[Feature Request] MCP (Model Context Protocol) Server Generation from OpenAPI Specifications
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
## Summary
Add support for generating **MCP (Model Context Protocol) servers** from OpenAPI specifications, enabling any API with an OpenAPI definition to be automatically exposed as AI-consumable tools for Claude, ChatGPT, VS Code Copilot, and other AI assistants.
## Background & Motivation
### The Problem
AI assistants (Claude, ChatGPT, GitHub Copilot, etc.) increasingly need to interact with external APIs. The **Model Context Protocol (MCP)** has emerged as the standard for connecting AI assistants to external data sources and tools. However, creating MCP servers today requires:
1. **Manual implementation** of tool definitions, schemas, and handlers
2. **Duplication of effort** - API definitions already exist in OpenAPI specs but must be re-implemented for MCP
3. **Maintenance burden** - keeping MCP servers in sync with API changes
### The Opportunity
Kiota already excels at:
- ✅ Parsing and understanding OpenAPI specifications
- ✅ Generating type-safe code across multiple languages (C#, Java, TypeScript, Python, Go, PHP, Ruby, Dart)
- ✅ Handling authentication, serialization, and error handling
- ✅ Enterprise-grade stability and Microsoft ecosystem integration
**Extending Kiota to generate MCP servers would provide a "universal API-to-AI bridge"** - any API with an OpenAPI spec could instantly become AI-accessible.
## Competitive Landscape & Prior Art
### Existing Solutions (Community)
| Project | Stars | Language | Notes |
|---------|-------|----------|-------|
| [abutbul/openapi-mcp-generator](https://github.com/abutbul/openapi-mcp-generator) | 28 | Python | Docker-ready, on PyPI |
| [UnitOneAI/MCPBuilder](https://github.com/UnitOneAI/MCPBuilder) | 3 | TypeScript | Web UI approach |
| [rmcp-openapi](https://crates.io/crates/rmcp-openapi) | - | Rust | Crate for Rust ecosystem |
### OpenAPI Generator Activity
There is an **active feature request** ([OpenAPITools/openapi-generator#22001](https://github.com/OpenAPITools/openapi-generator/issues/22001)) for MCP server generation, with a **Quarkus MCP generator PR already submitted** ([#22197](https://github.com/OpenAPITools/openapi-generator/pull/22197)).
### Why Kiota is Better Positioned
Having evaluated OpenAPI Generator, we found it:
- **Fragmented** - Too many competing implementations, inconsistent across languages
- **Not homogeneous** - Different language generators have different capabilities
- **Less mature** for enterprise use
**Kiota advantages:**
1. **Consistent architecture** - Single `LanguageWriter` pattern ensures uniform behavior
2. **Enterprise-ready** - Production-tested, backed by Microsoft
3. **Better TypeScript/C# support** - Critical for MCP (most MCP servers are TypeScript)
4. **Existing OpenAPI parsing** - Mature, well-tested OpenAPI handling
## Proposed Solution
### Architecture
Extend Kiota's `LanguageWriter` system with new MCP-specific writers:
```
src/Kiota.Builder/Writers/
├── CSharp/
├── TypeScript/
├── Python/
├── ...
└── MCP/ # NEW
├── TypeScript/ # MCP server in TypeScript
├── Python/ # MCP server in Python
└── CSharp/ # MCP server in C#
```
### Generated Output Example
**Input:** OpenAPI spec for a Pet Store API
**Output:** A fully functional MCP server
```typescript
// Generated by Kiota MCP Writer
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server({
name: "petstore-mcp",
version: "1.0.0",
}, {
capabilities: { tools: {} }
});
// Tool: listPets - Generated from GET /pets
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: "listPets",
description: "List all pets in the store",
inputSchema: {
type: "object",
properties: {
limit: { type: "integer", description: "Maximum number of pets to return" }
}
}
}, {
name: "createPet",
description: "Create a new pet",
inputSchema: {
type: "object",
properties: {
name: { type: "string", description: "Pet name" },
tag: { type: "string", description: "Pet tag" }
},
required: ["name"]
}
}]
}));
// Tool handlers - call the actual API
server.setRequestHandler(CallToolRequestSchema, async (request) => {
switch (request.params.name) {
case "listPets":
const response = await fetch(`${baseUrl}/pets?limit=${request.params.arguments.limit}`);
return { content: [{ type: "text", text: JSON.stringify(await response.json()) }] };
// ... other tools
}
});
```
### CLI Usage
```bash
# Generate MCP server from OpenAPI spec
kiota generate --language mcp-typescript \
--openapi https://api.example.com/openapi.json \
--output ./mcp-server
# Options
--transport stdio|sse|http # MCP transport type
--auth bearer|apikey|oauth2 # Authentication method
```
## Mapping OpenAPI → MCP
| OpenAPI Concept | MCP Concept |
|-----------------|-------------|
| `operationId` | Tool `name` |
| `summary` / `description` | Tool `description` |
| Request body schema | Tool `inputSchema` |
| Response schema | Tool response content |
| Security schemes | Server authentication |
| Servers array | Base URL configuration |
## Implementation Phases
### Phase 1: TypeScript MCP Server (MVP)
- Generate TypeScript MCP server with stdio transport
- Support basic CRUD operations
- Handle JSON request/response bodies
- Generate tool definitions from operations
### Phase 2: Multi-Language Support
- Add Python MCP writer (using `mcp` Python SDK)
- Add C# MCP writer (using .NET MCP SDK when available)
- Ensure consistent behavior across languages
### Phase 3: Advanced Features
- SSE and HTTP transports
- OAuth2 and complex auth flows
- Streaming responses
- Resource endpoints (not just tools)
- Prompt templates from API descriptions
## Success Criteria
- [ ] `kiota generate --language mcp-typescript` produces working MCP server
- [ ] Generated server passes MCP protocol validation
- [ ] Works with Claude Desktop, VS Code MCP extension, and other clients
- [ ] Supports at least 3 transport types (stdio, SSE, HTTP)
- [ ] Handles common auth patterns (API key, Bearer token, OAuth2)
## Use Cases
1. **Enterprise API Exposure** - Companies can instantly make internal APIs available to AI assistants
2. **Developer Tools** - API documentation becomes interactive through AI
3. **Rapid Prototyping** - Test API integrations with AI before building full clients
4. **Accessibility** - Non-developers can interact with APIs through natural language
## Related Work
- [Model Context Protocol Specification](https://modelcontextprotocol.io/)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
- [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)
- [OpenAPI Generator MCP Discussion](https://github.com/OpenAPITools/openapi-generator/issues/22001)
## Questions for Maintainers
1. Would this fit as a new `GenerationLanguage` enum value, or should it be a separate concept (e.g., `GenerationTarget.MCP`)?
2. Should MCP generation reuse existing language writers for model generation, or be fully standalone?
3. Is there interest in Microsoft contributing to or endorsing this feature given Azure API Management scenarios?
---
**Labels:** `enhancement`, `feature-request`, `good-first-issue` (for initial exploration)
I'm happy to contribute to the implementation if there's interest from the maintainers.
Contributor guide
Research direction
Start by reviewing the existing LanguageWriter implementations under src/Kiota.Builder/Writers/ and the GenerationLanguage and CLI generation paths mentioned in the proposal. Clarify the MVP scope with maintainers, then define completion against the stated TypeScript stdio generation and MCP protocol validation criteria before considering additional languages or transports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100