MCP Server Generator
Generate MCP servers from any codebase without needing an OpenAPI specification.
MCP Server Generator
The MCP Server Generator is an enterprise feature that scans your source code for API endpoints and produces a complete, production-ready MCP server. It works directly with your codebase, so you do not need an OpenAPI specification or any other API documentation.
This feature is available in CodeSpar Enterprise (the
codespar-enterpriserepo). Contact enterprise@codespar.dev for access.
What It Does
The generator performs three steps:
- Scans source code for API endpoint definitions (route handlers, decorators, middleware)
- Generates MCP tool definitions with parameter schemas, descriptions, and auth requirements
- Outputs a complete MCP server that speaks JSON-RPC 2.0 over stdio, ready to connect to any MCP client
Supported Frameworks
| Framework | Detection Method |
|---|---|
| Express | app.get(), app.post(), router.use(), middleware chains |
| Fastify | fastify.route(), fastify.get(), schema definitions |
| Next.js (App Router) | route.ts exports (GET, POST, PUT, DELETE, PATCH) |
| Next.js (Pages Router) | pages/api/*.ts default exports with req.method checks |
What It Detects
For each endpoint, the generator extracts:
- Route definitions: HTTP method, path pattern, middleware stack
- Path parameters:
/users/:idbecomes a requiredidparameter in the MCP tool schema - Body fields: TypeScript interfaces, Zod schemas, or inline type annotations used in request body parsing
- JSDoc descriptions:
@description,@param, and@returnstags are mapped to MCP tool descriptions - Auth requirements: middleware like
requireAuth,isAdmin, or custom auth guards are noted in the tool metadata
How to Use
From any messaging channel where your CodeSpar agent is active:
The agent scans the linked repository, generates the MCP server, and creates a PR with the output.
The Generated MCP Server
The output is a self-contained TypeScript package that includes:
- JSON-RPC 2.0 over stdio: compatible with any MCP client (Claude Desktop, Cursor, custom clients)
- Tool definitions: one tool per API endpoint, with typed parameters and descriptions
- Auth header forwarding: configurable auth headers passed through to the target API
- Fetch-based handlers: each tool calls the original API endpoint using
fetch, so no code duplication
Generated Structure
Example
Given this Express application:
The generator produces these MCP tools:
Each tool handler calls the original API using fetch with configurable base URL and auth headers:
Why This Matters
90% of enterprise codebases do not have current OpenAPI specs. API documentation drifts out of sync within weeks of being written. The MCP Server Generator reads the source code directly, which means:
- No manual spec maintenance
- Always up to date with the actual implementation
- Detects undocumented endpoints and parameters
- Works with legacy codebases that never had documentation
Enterprise Only
The MCP Server Generator is available in CodeSpar Enterprise (the codespar-enterprise repo, commercial license). It builds on the Repository Index for codebase analysis and uses the same MCP infrastructure as the Integration Connectors.
Contact enterprise@codespar.dev for access and pricing.