Skip to content

[Feature Request] MCP (Model Context Protocol) Server Generation from OpenAPI Specifications #7334

Description

@gfortaine

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 28 Python Docker-ready, on PyPI
UnitOneAI/MCPBuilder 3 TypeScript Web UI approach
rmcp-openapi - Rust Crate for Rust ecosystem

OpenAPI Generator Activity

There is an active feature request (OpenAPITools/openapi-generator#22001) for MCP server generation, with a Quarkus MCP generator PR already submitted (#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

// 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

# 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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions