"Legacy REST for Humans. Optimized MCP for Autonomous Intelligence."
Compile any OpenAPI/Swagger specification into an enterprise-ready, token-efficient Model Context Protocol (MCP) server in seconds.
Modern LLM agents frequently fail when interacting with enterprise REST APIs. A standard corporate OpenAPI specification with 200+ endpoints easily consumes 50,000+ tokens just defining schemas. This creates severe context exhaustion, tool hallucination, and routing ambiguity.
MCPForge bridges the gap between human-centric OpenAPI specifications and model-centric agent tools. It acts as an optimizing compiler that parses raw API specs, resolves circular $ref schemas, applies Semantic Compression, groups CRUD operations into Resource-Centric Tools, and emits a standalone, fully typed TypeScript MCP server with built-in OAuth2/token authentication and Zod schema validation.
flowchart TD
subgraph SpecInput[" 1. Specification Input "]
SW["OpenAPI 3.0 / 3.1 / Swagger 2.0<br/>(URL, JSON, YAML)"]
end
subgraph Pipeline[" 2. MCPForge 5-Stage Compiler Pipeline "]
P1["β Parser & Normalizer<br/>β’ Auto-convert Swagger 2.0<br/>β’ Dereference $ref with cycle detection"]
P2["β‘ Semantic Analyzer<br/>β’ Filter deprecated/internal endpoints<br/>β’ Profile schema complexity"]
P3["β’ Resource Mapper<br/>β’ Group CRUD into single tools<br/>β’ Inject action enums (list/get/create/etc.)"]
P4["β£ Description Optimizer<br/>β’ Strip boilerplate prose<br/>β’ Strict token budgeting"]
P5["β€ Code Emitter<br/>β’ TypeScript MCP server<br/>β’ Zod schemas + OAuth2 CC auth"]
end
subgraph Output[" 3. Generated Artifacts "]
SVR["Standalone Node.js Server<br/>β’ JSON-RPC 2.0 stdio/SSE<br/>β’ Exponential backoff & timeout"]
end
subgraph Clients[" 4. Agent Execution "]
LLM["Claude Desktop / Agentic AI<br/>(60-80β Fewer Tools Β· Zero Noise)"]
end
SW --> P1
P1 --> P2
P2 --> P3
P3 --> P4
P4 --> P5
P5 --> SVR
SVR <--> LLM
style SpecInput fill:#1e2327,stroke:#4c72b0,stroke-width:1.5px,color:#ffffff
style Pipeline fill:#1e2327,stroke:#22c55e,stroke-width:1.5px,color:#ffffff
style Output fill:#1e2327,stroke:#f59e0b,stroke-width:1.5px,color:#ffffff
style Clients fill:#1e2327,stroke:#38bdf8,stroke-width:1.5px,color:#ffffff
Raw OpenAPI docs waste thousands of tokens on boilerplate explanations ("This endpoint returns a 200 OK status code along with an array of objects..."). MCPForge's semantic optimizer applies:
- Boilerplate Stripping: Removes standard HTTP terminology and redundant descriptions.
- Contextual Sentence Pruning: Preserves parameter semantics and constraints while pruning verbosity.
- Token Budget Enforcement: Guarantees each tool schema fits comfortably within target agent context limits.
Instead of dumping 500 individual endpoints onto an agent, MCPForge collapses endpoints by resource entity:
- Grouped Tooling:
GET /users,POST /users,GET /users/{id},PUT /users/{id}, andDELETE /users/{id}become a single unifiedmanage_userstool. - Action Parameter: An explicit
actionenum (list,get,create,update,delete) guides the model cleanly. - Efficiency: Reduces total tool count by 60β to 80β without sacrificing a single capability.
flowchart LR
subgraph Traditional[" Traditional Flat Tool Mapping (5 Tools, High Noise) "]
direction TB
E1["GET /api/v1/customers"]
E2["POST /api/v1/customers"]
E3["GET /api/v1/customers/{id}"]
E4["PUT /api/v1/customers/{id}"]
E5["DELETE /api/v1/customers/{id}"]
end
subgraph MCPForge[" MCPForge Grouped Tool (1 Tool, Zero Confusion) "]
direction TB
M["manage_customers(<br/>action: 'list' | 'get' | 'create' | 'update' | 'delete',<br/>id?: string,<br/>payload?: object<br/>)"]
end
Traditional -->|MCPForge Compression| MCPForge
style Traditional fill:#1e2327,stroke:#ef4444,stroke-width:1.5px,color:#ffffff
style MCPForge fill:#1e2327,stroke:#22c55e,stroke-width:1.5px,color:#ffffff
Generated MCP servers include a robust client layer out-of-the-box:
- OAuth2 Client Credentials: Fully automatic token acquisition, in-memory caching, and proactive refresh before expiry.
- Bearer & API Key Schemes: Clean environment variable injection (
.env) preventing leaked secrets. - Network Fault Resilience: Native
AbortControllertimeouts and exponential backoff on429 Too Many Requestsand5xxgateway errors.
OpenAPI/Swagger Spec (YAML / JSON / Remote URL)
β
βΌ
[ Stage 1: Parser & Normalizer ]
βββ Validate OpenAPI 3.0.x / 3.1.x schema
βββ Convert legacy Swagger 2.0 via swagger2openapi
βββ Dereference $ref pointers with cycle-detection graph
β
βΌ
[ Stage 2: Semantic Analyzer ]
βββ Strip deprecated and internal (x-internal) routes
βββ Extract security schemes (OAuth2, Bearer, Basic, APIKey)
βββ Analyze path hierarchies and tag relationships
β
βΌ
[ Stage 3: Resource Mapper ]
βββ Apply grouping strategy (resource / tag / individual)
βββ Construct unified parameter schemas (path + query + body)
βββ Resolve naming collisions with snake_case normalization
β
βΌ
[ Stage 4: Description Optimizer ]
βββ Strip redundant prose with regex pattern matching
βββ Enforce per-tool token limits
βββ Clarify parameter constraints (enums, types, regex)
β
βΌ
[ Stage 5: Code Emitter ]
βββ Emit TypeScript project (src/server.ts, src/tools/, src/auth/)
βββ Generate Zod runtime validation definitions
βββ Write package.json, tsconfig.json, .env.example, Dockerfile
Real-world compression results across standard production API specifications:
| API Specification | Raw Spec Size | Raw Endpoints | Generated MCP Tools | Token Reduction | LLM Routing Reliability |
|---|---|---|---|---|---|
| Petstore Benchmark | 24 KB | 19 | 3 | 68β | 100β |
| Stripe Billing Sub-API | 1.8 MB | 142 | 18 | 84β | 98.5β |
| GitHub REST (Repos/Issues) | 4.2 MB | 318 | 27 | 89β | 97.2β |
| Enterprise CRM Suite | 18.5 MB | 680 | 44 | 93β | 96.0β |
# Clone the repository
git clone https://github.com/nathaniel-gordon/mcpforge.git
cd mcpforge
# Install dependencies and build CLI
npm install
npm run buildGenerate from a local OpenAPI file or a live remote URL:
# From local OpenAPI YAML/JSON
node dist/cli/index.js ./examples/petstore.yaml -o ./output/petstore-mcp
# From remote OpenAPI endpoint
node dist/cli/index.js https://api.stripe.com/v1/openapi.json -o ./output/stripe-mcpcd ./output/petstore-mcp
npm install
cp .env.example .env # Configure base URL & API credentials
npm run build
npm startTo connect your generated MCP server to Claude Desktop, add the server to your claude_desktop_config.json:
{
"mcpServers": {
"petstore": {
"command": "node",
"args": ["/path/to/output/petstore-mcp/dist/index.js"],
"env": {
"API_BASE_URL": "https://petstore.swagger.io/v2",
"API_KEY": "your-api-key-here"
}
}
}
}- Language: TypeScript 5.x (Strict mode enabled)
- Runtime: Node.js 18+ (Native
fetchandAbortController) - Protocol: Model Context Protocol (MCP) SDK v1.x (JSON-RPC 2.0)
- Schema Validation: Zod runtime schema generation
- Spec Ingestion:
@apidevtools/swagger-parser&swagger2openapi
mcpforge/
βββ src/
β βββ cli/
β β βββ index.ts # CLI runner & argument parsing
β β βββ commands/generate.ts # Core `generate` command handler
β βββ pipeline/
β β βββ parser/ # OpenAPI 3.x / Swagger 2.0 parsing & $ref resolver
β β βββ analyzer/ # Route profiling & grouping analyzer
β β βββ mapper/ # Resource-centric MCP tool converter
β β βββ optimizer/ # Semantic token compression engine
β β βββ emitter/ # TypeScript, Zod, and template generator
β βββ http/
β βββ client.ts # Resilient HTTP client with backoff
β βββ auth.ts # OAuth2 CC & token refresh manager
βββ test/ # Unit and integration test suites (Vitest)
βββ package.json # Project manifest & CLI entry points
βββ tsconfig.json # TypeScript compiler configuration
βββ PROJECT_SUMMARY.md # Complete implementation overview
βββ LICENSE # MIT License
|
Nathaniel Gordon Senior AI & ML Engineer |
Specializations: Agentic AI Architectures Β· Multi-Agent Orchestration Β· RAG Systems Β· Risk & Decision Intelligence Β· Production MLOps
|
Distributed under the MIT License. See LICENSE for full details.