The Model Context Protocol (MCP) server enables reliable integration between Clay and AI assistants. It provides type-safe, validated tool calls that eliminate parameter hallucination and errors.
The MCP server provides 14 tools:
clay_generate - Generate code from modelsclay_clean - Clean up generated filesclay_test_path - Test JSONPath expressionsclay_init - Initialize projects or generatorsclay_list_generators - List all generatorsclay_get_model_structure - Inspect model structure
clay_list_helpers - List Handlebars helpers with
examples
clay_explain_concepts - Get comprehensive documentation
These tools let the AI query and modify your model data directly.
They are include-aware: they query the expanded model
(with includes resolved) to find targets, then trace back to the
correct source file to apply the edit. If data lives in an included
file, the mutation is written there — the main model's
include reference is preserved.
clay_model_query - Query model data with JSONPath
(searches the expanded model)
clay_model_add - Add items to arrays or properties to
objects
clay_model_update - Update fields on matched items
clay_model_delete - Remove matched items (deleting an
included entity removes the include reference from the main model)
clay_model_rename - Rename a property key on matched
items
clay_model_set_schema - Set or update
$schema reference on a model
The MCP server includes 2 comprehensive prompts that teach AI assistants about Clay:
clay-getting-started - Complete guide to Clay
architecture, project structure, and using basic tools (clean,
generate)
clay-workflow - Step-by-step workflow from project
setup to code generation with real-world examples
These prompts provide instant, comprehensive knowledge to AI assistants, ensuring consistent and accurate guidance when working with Clay projects.
AI assistants can accidentally edit files that are generated by Clay. Clay provides built-in commands to prevent this.
Claude Code supports hooks that intercept tool calls.
Clay can install a PreToolUse hook that blocks Edit/Write operations
on any file listed in the .clay manifest:
clay init-claude
This creates .claude/settings.json with a hook that
calls clay check-generated before any Edit/Write
operation. No scripts are generated — Clay handles the check
entirely via the clay binary.
When Claude tries to edit a generated file, the hook blocks the operation and shows a helpful message explaining how to use Clay MCP tools instead.
Commit the .claude/ directory to git so hooks travel
with the repo — every team member gets protection automatically.
Use clay init-mcp to add the Clay MCP server to your
AI platform's configuration:
clay init-mcp
This interactively asks which platforms you use (VS Code / Copilot, Claude Code, Claude Desktop, Cursor) and writes the correct config for each. It auto-detects platforms already present in your project and pre-selects them.
For AI assistants without hook support (Cursor, Windsurf, etc.),
add instructions to your project's AI configuration file (e.g.
.cursorrules) telling the assistant not to edit
generated files. Check file headers for "This file is generated
using Clay" comments.
npm install -g clay-generator
Edit your Claude config file:
~/Library/Application
Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
Add this configuration:
{
"mcpServers": {
"clay": {
"command": "clay-mcp",
"args": []
}
}
}
The MCP server will start automatically when Claude launches.
npm install -g clay-generator
Create .vscode/mcp.json in your project:
{
"servers": {
"clay": {
"type": "stdio",
"command": "clay-mcp",
"args": []
}
}
}
Or use the Command Palette:
MCP: Open Workspace Folder Configuration
VS Code will prompt you to trust the server when it starts. You can also manage servers via:
MCP: List Servers - View all configured serversMCP: Start Server - Manually start the Clay server
Reference Clay tools in Copilot Chat:
# List available helpers
#clay_list_helpers
# Generate code
#clay_generate
# Test a JSONPath
#clay_test_path
User: "Regenerate all my Clay models"
AI calls: clay_generate({})
User: "Generate code for the users model"
AI calls:
clay_generate({ model_path: "./clay/users-model.json", output_path:
"./src" })
User: "Show me all array-type parameters"
AI calls:
clay_test_path({ model_path: "./clay/model.json", json_path:
"$.model.types[*].commands[*].parameters[?(@.type=='array')]"
})
User: "What Handlebars helpers can I use?"
AI calls:
clay_list_helpers({ include_examples: true })
User: "Show me string manipulation helpers"
AI calls:
clay_list_helpers({ category: "string", include_examples: true
})
User: "How do I use the pluralize helper?"
AI: The AI calls
clay_list_helpers({ include_examples: true }) and shows:
{{pluralize "category"}} → categories
{{pluralize "user"}} → users
{{pluralize "child"}} → children
Common helper categories available:
User: "Show me the User entity"
AI calls:
clay_model_query({ model_path: "./clay/model.json", json_path:
"$.model.entities[?(@.name=='User')]" })
User: "Add an email field to the User entity"
AI calls:
clay_model_add({ model_path: "./clay/model.json", json_path:
"$.model.entities[?(@.name=='User')].fields", value: { name:
"email", type: "string" } })
If User lives in an included file (e.g.
entities/user.json), the field is added there
automatically. The response includes
source_file showing which file was modified.
User: "Add a description to the User entity"
AI calls:
clay_model_update({ model_path: "./clay/model.json", json_path:
"$.model.entities[?(@.name=='User')]", fields: { description: "A
registered user" } })
User: "Remove the legacy_id field from User"
AI calls:
clay_model_delete({ model_path: "./clay/model.json", json_path:
"$.model.entities[?(@.name=='User')].fields[?(@.name=='legacy_id')]"
})
User: "Rename 'fields' to 'columns' on all entities"
AI calls:
clay_model_rename({ model_path: "./clay/model.json", json_path:
"$.model.entities[*]", old_name: "fields", new_name: "columns"
})
User: "How do I create a generator?"
AI calls:
clay_explain_concepts({ topic: "generators", include_examples: true
})
User: "What are clay_key and clay_parent?"
AI calls:
clay_explain_concepts({ topic: "context-variables" })
You: "Help me create a REST API generator for my user model"
AI: *Calls clay_get_model_structure to inspect your model*
*Calls clay_list_helpers to see available helpers*
*Creates generator.json with appropriate steps*
*Creates templates using discovered helpers*
*Calls clay_generate to test the generator*
You: "Add a 'role' field to the User entity"
AI: *Calls clay_model_query to find the User entity*
*Calls clay_model_add to add the field*
*Response shows source_file: "entities/user.json"*
*The included file was edited, main model unchanged*
You: "Why isn't my generator selecting the right fields?"
AI: *Calls clay_test_path with your current selector*
*Analyzes the results*
*Suggests corrected JSONPath expression*
*Calls clay_test_path again to verify*
You: "I need a template that converts field names to PascalCase"
AI: *Calls clay_list_helpers with category: "string"*
*Shows you the pascalCase helper*
*Creates example template using {{pascalCase name}}*
You: "Create a template that generates TypeScript types with proper casing"
AI: *Calls clay_list_helpers to review case conversion helpers*
*Suggests using pascalCase for type names*
*Suggests using camelCase for property names*
Template created:
export type {{pascalCase name}} = {
{{#each fields}}
{{camelCase name}}: {{type}};
{{/each}}
};
You: "How do I conditionally render based on field types?"
AI: *Calls clay_list_helpers with category: "type-check"*
*Shows isArray, isString, isNumber, etc.*
Template example:
{{#each fields}}
{{#if (isArray type)}}
// {{name}} is an array type
{{else if (isString type)}}
// {{name}} is a string type
{{/if}}
{{/each}}
The clay watch command is intentionally not included in
the MCP server because it's a long-running background process that
doesn't fit the MCP request-response model.
Instead:
clay watch directly in a terminalVerify Clay is installed globally:
which clay-mcp
# Should show: /usr/local/bin/clay-mcp or similar
Check the server status in your AI assistant:
MCP: List Servers
The MCP server requires a .clay file for parameterless
commands. Initialize if needed:
clay init
clay_explain_concepts tool to get detailed documentation
on any Clay topic directly in your AI chat!
The MCP server uses your current working directory. To work with a different project:
cd /path/to/your/project
# Then use AI assistant normally
Each project can have its own .clay file. The server uses
the one in your current directory.
The MCP server is designed for interactive use. For CI/CD, use the CLI directly:
clay generate
clay test-path ./clay/model.json "$.model.types[*]"