MCP Generator
Automatically generate MCP server code from your existing API endpoints using CodeSpar's scanner and generator.
The MCP Generator scans your existing API source code, discovers endpoints, and generates a fully functional MCP server with tool definitions — turning any REST API into tools your AI agent can call.
The MCP Generator is part of CodeSpar Enterprise and runs in the dashboard: open Generate at codespar.dev/dashboard/generate, or search for it in the ⌘K palette.
Dashboard wizard (Generate)
The fastest path — no install, no code. Open Generate in the dashboard and run a four-step pipeline that ends with a server which is routable, governed, and isolated to your project — not just generated code on disk.
Source
Point at your API one of three ways:
- Paste source — drop Express / Fastify / Next.js route handlers for an instant scan.
- OpenAPI 3.x — paste the raw spec (JSON or YAML); no source access needed.
- GitHub repo — give
owner/repo(plus a token for private repos); the picker fetches the files most likely to hold endpoints and scans them.
Endpoints
Toggle which discovered endpoints to expose as tools.
Generate
Review the generated server.ts and tool definitions; rename the server or regenerate.
Onboard & activate
Onboard saves the server to your project. Activate (with your API's upstream base URL + auth) seeds it into the router as a project-scoped rail — so every agent call to it runs through the same policy engine, credential vault, and audit chain as Pix, NF-e, and the rest. Then connect credentials to go live.
The dashboard wizard is the only way to run the generator today, and the path that makes a generated server routable. The generator is not published as a library or as a CLI command.
How it works
Scan
The API Scanner parses your TypeScript/JavaScript source files and discovers API endpoints. It supports Express, Fastify, and Next.js API routes.
Generate tools
The Generator converts discovered endpoints into MCP tool definitions with JSON Schema inputs, descriptions, and semantic names.
Generate server
The generator produces a complete MCP server configuration with runnable code.
Example
Given this Express API:
/**
* Create a new order
*/
app.post("/api/orders", async (req, res) => {
const { customer_id, items, shipping_address } = req.body;
// ...
});
/**
* Get order by ID
*/
app.get("/api/orders/:id", async (req, res) => {
// ...
});
/**
* List orders with filters
*/
app.get("/api/orders", async (req, res) => {
const { status, from, to, limit } = req.query;
// ...
});The generator produces:
[
{
"name": "CreateOrder",
"description": "Create a new order",
"input_schema": {
"type": "object",
"properties": {
"customer_id": { "type": "string" },
"items": { "type": "array" },
"shipping_address": { "type": "object" }
},
"required": ["customer_id", "items"]
}
},
{
"name": "GetOrder",
"description": "Get order by ID",
"input_schema": {
"type": "object",
"properties": {
"id": { "type": "string", "description": "Order ID" }
},
"required": ["id"]
}
},
{
"name": "ListOrders",
"description": "List orders with filters",
"input_schema": {
"type": "object",
"properties": {
"status": { "type": "string" },
"from": { "type": "string" },
"to": { "type": "string" },
"limit": { "type": "number" }
}
}
}
]Supported frameworks
| Framework | Scanner support |
|---|---|
| Express | Routes, Router, middleware |
| Fastify | Route handlers, schemas |
| Next.js | App Router (route.ts), Pages API (pages/api) |
Naming conventions
The generator creates semantic tool names from HTTP method + path:
| Method | Path | Generated name |
|---|---|---|
GET | /api/users | ListUsers |
GET | /api/users/:id | GetUser |
POST | /api/users | CreateUser |
PUT | /api/users/:id | UpdateUser |
DELETE | /api/users/:id | DeleteUser |
POST | /api/orders/:id/refund | RefundOrder |
Output types
interface DiscoveredEndpoint {
method: string; // HTTP method
path: string; // Route path
handler: string; // Handler function name
params: string[]; // Path parameters
queryParams: string[]; // Query parameters
bodyFields: string[]; // Request body fields
description?: string; // JSDoc description
}
interface MCPToolDefinition {
name: string;
description: string;
input_schema: Record<string, unknown>;
}
interface MCPServerConfig {
name: string;
description: string;
tools: MCPToolDefinition[];
endpoints: DiscoveredEndpoint[];
code: string; // Generated TypeScript
}Next steps
codespar_manage_connections
List, inspect or connect the accounts and identity the agent needs. Dashboard connect deep-links for API-key and OAuth providers, a one-time login for login-walled stores, and the buyer's vaulted checkout identity for guest-checkout stores.
Developer resources
Set up your environment, pick a client, and learn the platform pieces you build against.