AI & MCP Setup
Connect RouteCraft to Claude Desktop, Cursor, or other MCP clients.
Overview
RouteCraft integrates with AI agents through the Model Context Protocol (MCP). You define tools as routes, then expose them to AI clients like Claude Desktop or Cursor.
Security model:
- AI can only call the tools you explicitly define
- Each tool has a typed schema (validated with Zod)
- No filesystem access, no shell commands
- You control all business logic
1. Install the AI package
npm install @routecraft/ai zod
2. Create tools
Define tools as routes using tool() from @routecraft/ai:
import { craft, tool, noop } from '@routecraft/routecraft'
import { z } from 'zod'
export default craft()
.id('my-tool')
.from(tool('my-tool', {
description: 'What this tool does',
schema: z.object({
param: z.string()
}),
keywords: ['search', 'terms']
}))
.process((body) => {
// Your business logic
return { result: body.param }
})
.to(noop())
3. Configure MCP client
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"my-business-tools": {
"command": "npx",
"args": [
"@routecraft/cli",
"run",
"./routes/tools.mjs"
]
}
}
}
Cursor
Open Cursor Settings → Features → Model Context Protocol, then add:
{
"my-business-tools": {
"command": "npx",
"args": [
"@routecraft/cli",
"run",
"./routes/tools.mjs"
]
}
}
4. Restart and verify
- Completely quit and restart Claude/Cursor
- Look for the hammer icon (🔨) in the input area
- Your tools should appear in the tool picker
Production deployment
For production MCP servers, use absolute paths:
{
"mcpServers": {
"production-tools": {
"command": "/usr/local/bin/node",
"args": [
"/path/to/project/node_modules/@routecraft/cli/dist/index.js",
"run",
"/path/to/project/routes/tools.mjs"
]
}
}
}
Security best practices
- Validate all inputs - Use Zod schemas on every tool
- Principle of least privilege - Only expose tools AI needs
- Audit logs - Use
.tap(log())to track tool usage - Rate limiting - Add throttling for sensitive operations
- Environment variables - Never hardcode API keys