OpenAPI to MCP Server

by tyktechnologies

Not rated
GitHub

About

A tool to create MCP servers from OpenAPI/Swagger specifications, allowing AI assistants to interact with your APIs.

Details

Author
tyktechnologies
Categories
Developer Tools, API

Setup

Install OpenAPI to MCP Server in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/tyktechnologies/api-to-mcp

Follow the installation instructions in the repository README, then restart your MCP client.

A tool that creates MCP (Model Context Protocol) servers from OpenAPI/Swagger specifications, enabling AI assistants to interact with your APIs.Create your ownbranded and customized MCPsfor specific APIs or services.

This project creates a dynamic MCP server that transforms OpenAPI specifications into MCP tools. It enables seamless integration of REST APIs with AI assistants via the Model Context Protocol, turning any API into an AI-accessible tool.

- Dynamic loading of OpenAPI specs from file or HTTP/HTTPS URLs
- Support for
OpenAPI Overlaysloaded from files or HTTP/HTTPS URLs
- Customizable mapping of OpenAPI operations to MCP tools
- Advanced filtering of operations using glob patterns for both operationId and URL paths
- Comprehensive parameter handling with format preservation and location metadata
- API authentication handling
- OpenAPI metadata (title, version, description) used to configure the MCP server
- Hierarchical description fallbacks (operation description → operation summary → path summary)
- Custom HTTP headers support via environment variables and CLI
- X-MCP header for API request tracking and identification
- Support for customx-mcpextensions at the path level to override tool names and descriptions

This tool creates an MCP server that allows AI assistants to interact with APIs defined by OpenAPI specifications. The primary way to use it is by configuring your AI assistant to run it directly as an MCP tool.
-

Ensure you haveNode.jsinstalled on your computer

Open Claude Desktop and navigate to Settings > Developer

Edit the configuration file (or it will be created if it doesn't exist):

- macOS:~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:%APPDATA%\Claude\claude_desktop_config.json

Add this configuration (customize as needed):

{ "mcpServers": { "api-tools": { "command": "npx", "args": [ "-y", "@tyk-technologies/api-to-mcp@latest", "--spec", "https://petstore3.swagger.io/api/v3/openapi.json" ], "enabled": true } } }

- Restart Claude Desktop
- You should now see a hammer icon in the chat input box. Click it to access your API tools.

You can adjust theargsarray to customize your MCP server with various options:

{ "mcpServers": { "my-api": { "command": "npx", "args": [ "-y", "@tyk-technologies/api-to-mcp@latest", "--spec", "./path/to/your/openapi.json", "--overlays", "./path/to/overlay.json,https://example.com/api/overlay.json", "--whitelist", "getPet,POST:/users/", "--targetUrl", "https://api.example.com" ], "enabled": true } } }

-

Create a configuration file in one of these locations:

- Project-specific:.cursor/mcp.jsonin your project directory
- Global:~/.cursor/mcp.jsonin your home directory

Add this configuration (adjust as needed for your API):

{ "servers": [ { "command": "npx", "args": [ "-y", "@tyk-technologies/api-to-mcp@latest", "--spec", "./path/to/your/openapi.json" ], "name": "My API Tools" } ] }

You can also use this MCP server directly in your JavaScript/TypeScript applications using the Vercel AI SDK's MCP client:

import { experimental_createMCPClient } from 'ai'; import { Experimental_StdioMCPTransport } from 'ai/mcp-stdio'; import { generateText } from 'ai'; import { createGoogleGenerativeAI } from '@ai-sdk/google'; // Initialize the Google Generative AI provider const google = createGoogleGenerativeAI({ apiKey: process.env.GOOGLE_API_KEY, // Set your API key in environment variables }); const model = google('gemini-2.0-flash'); // Create an MCP client with stdio transport const mcpClient = await experimental_createMCPClient({ transport: { type: 'stdio', command: 'npx', // Command to run the MCP server args: ['-y', '@tyk-technologies/api-to-mcp', '--spec', 'https://petstore3.swagger.io/api/v3/openapi.json'], // OpenAPI spec env: { // You can set environment variables here // API_KEY: process.env.YOUR_API_KEY, }, }, }); async function main() { try { // Retrieve tools from the MCP server const tools = await mcpClient.tools(); // Generate text using the AI SDK with MCP tools const { text } = await generateText({ model, prompt: 'List all available pets in the pet store using the API.', tools, // Pass the MCP tools to the model }); console.log('Generated text:', text); } catch (error) { console.error('Error:', error); } finally { // Always close the MCP client to release resources await mcpClient.close(); } } main();

Configuration is managed via environment variables, command-line options, or a JSON configuration file:

# Start with specific OpenAPI spec file @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json # Apply overlays to the spec @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json --overlays=./path/to/overlay.json,https://example.com/api/overlay.json # Include only specific operations (supports glob patterns) @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json --whitelist="getPet,POST:/users/" # Specify target API URL @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json --targetUrl=https://api.example.com # Add custom headers to all API requests @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json --headers='{"X-Api-Version":"1.0.0"}' # Disable the X-MCP header @tyk-technologies/api-to-mcp --spec=./path/to/openapi.json --disableXMcp

You can set these in a.envfile or directly in your environment:

- OPENAPI_SPEC_PATH: Path to OpenAPI spec file
- OPENAPI_OVERLAY_PATHS: Comma-separated paths to overlay JSON files
- TARGET_API_BASE_URL: Base URL for API calls (overrides OpenAPI servers)
- MCP_WHITELIST_OPERATIONS: Comma-separated list of operation IDs or URL paths to include (supports glob patterns likegetPetorGET:/pets/)
- MCP_BLACKLIST_OPERATIONS: Comma-separated list of operation IDs or URL paths to exclude (supports glob patterns, ignored if whitelist used)
- API_KEY: API Key for the target API (if required)
- SECURITY_SCHEME_NAME: Name of the security scheme requiring the API Key
- SECURITY_CREDENTIALS: JSON string containing security credentials for multiple schemes
- CUSTOM_HEADERS: JSON string containing custom headers to include in all API requests
- HEADER_: Any environment variable starting withHEADER_will be added as a custom header (e.g.,HEADER_X_API_Version=1.0.0adds the headerX-API-Version: 1.0.0)
- DISABLE_X_MCP: Set totrueto disable adding theX-MCP: 1header to all API requests
- CONFIG_FILE: Path to a JSON configuration file

You can also use a JSON configuration file instead of environment variables or command-line options. The MCP server will look for configuration files in the following order:
- Path specified by--configcommand-line option
- Path specified byCONFIG_FILEenvironment variable
- config.jsonin the current directory
- openapi-mcp.jsonin the current directory
- .openapi-mcp.jsonin the current directory

{ "spec": "./path/to/openapi-spec.json", "overlays": "./path/to/overlay1.json,https://example.com/api/overlay.json", "targetUrl": "https://api.example.com", "whitelist": "getPets,createPet,/pets/", "blacklist": "deletePet,/admin/", "apiKey": "your-api-key", "securitySchemeName": "ApiKeyAuth", "securityCredentials": { "ApiKeyAuth": "your-api-key", "OAuth2": "your-oauth-token" }, "headers": { "X-Custom-Header": "custom-value", "User-Agent": "OpenAPI-MCP-Client/1.0" }, "disableXMcp": false }

A full example configuration file with explanatory comments is available atconfig.example.jsonin the root directory.

Configuration settings are applied in the following order of precedence (highest to lowest):
- Command-line options
- Environment variables
- JSON configuration file

# Clone the repository git clone <repository-url> cd openapi-to-mcp-generator # Install dependencies npm install # Build the project npm run build
# Start the MCP server npm start # Development mode with auto-reload npm run dev

Customizing and Publishing Your Own Version

You can use this repository as a base for creating your own customized OpenAPI to MCP server. This section explains how to fork the repository, customize it for your specific APIs, and publish it as a package.
-

Fork the Repository: Fork this repository on GitHub to create your own copy that you can customize.

# Create a specs directory if it doesn't exist mkdir -p specs # Add your OpenAPI specifications cp path/to/your/openapi-spec.json specs/ # Add any overlay files cp path/to/your/overlay.json specs/

Configure Default Settings: Create a custom config file that will be bundled with your package:

# Copy the example config cp config.example.json config.json # Edit the config to point to your bundled specs # and set any default settings
{ "name": "your-custom-mcp-server", "version": "1.0.0", "description": "Your customized MCP server for specific APIs", "files": [ "dist//", "config.json", "specs//*", "README.md" ] }

Ensure Specs are Bundled: Thefilesfield in package.json (shown above) ensures your specs and config file will be included in the published package.

The repository includes a GitHub Actions workflow for automatic publishing to npm. To customize it for your forked repo:
-

Update the Workflow Name: Edit.github/workflows/publish-npm.yamlto update the name if desired:

Set Package Scope (if needed): If you want to publish under an npm organization scope, uncomment and modify the scope line in the workflow file:

- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "18" registry-url: "https://registry.npmjs.org/" # Uncomment and update with your organization scope: scope: "@your-org"

Set Up npm Token: Add your npm token as a GitHub secret namedNPM_TOKENin your forked repository's settings.

Once you've customized the repository:

# Update version in package.json (optional, the workflow will update it based on the tag) npm version 1.0.0 # Push the tag git push --tags

- Automatically build the package
- Update version in package.json to match the tag
- Publish to npm with your bundled specs and config

Users of your customized package can install and use it with npm:

# Install your customized package npm install your-custom-mcp-server -g # Run it your-custom-mcp-server

They can override your default settings via environment variables or command line options as described in the Configuration section.

This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.

A server that dynamically creates MCP endpoints from any OpenAPI specification URL.

Turn any OpenAPI 3.0 spec into an MCP server with zero code — deploy to Cloudflare Workers, Node.js, Docker, or run locally via npx, with a built-in OAuth 2.1 server for MCP clients that require custom connector authentication.

An MCP server for any web application with an OpenAPI specification, connecting AI models to external tools and data services.

A zero-configuration tool to automatically expose FastAPI endpoints as MCP tools.

An MCP server that enables Large Language Models to make HTTP requests and interact with web APIs. It supports automatic tool generation from OpenAPI/Swagger specifications.

CLI tool that generates MCP servers from OpenAPI/Postman specs — pip install mcpgen-cli

A secure MCP-to-OpenAPI proxy server that converts MCP tools into OpenAPI compatible HTTP servers, with support for multiple server types and automatic API documentation.

Turn any OpenAPI/Swagger spec into Claude tools. Zero config, zero code.

Connect to any OpenAPI-based API with built-in OAuth2 authentication management.

Converts OpenAPI/Swagger specifications to Model Context Protocol (MCP) format, providing a modern Web UI and a backend service.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.