MCP OpenAPI Connector
Enables Claude Desktop and other MCP clients to interact with any OAuth2-authenticated OpenAPI-based API through automatic tool generation from OpenAPI specifications, with built-in token management and authentication handling.
README
MCP OpenAPI Connector
A unified Model Context Protocol (MCP) server for connecting OpenAPI-based APIs with built-in authentication management. This project enables Claude Desktop, Cursor, and other MCP-compatible clients to interact with authenticated OpenAPI-based APIs without requiring separate proxy servers.
Features
- Single Process Architecture: No separate proxy server needed
- Built-in OAuth2 Authentication: Automatic token management and refresh
- OpenAPI Integration: Automatically generate MCP tools from OpenAPI/Swagger specifications
- Extensible Tool System: Easy to add custom tools and resources
- Error Handling: Automatic retry and authentication error recovery
- Simple Configuration: Single configuration file for all settings
- Multiple API Support: Easily adapt to any OAuth2-based API
Installation
Via npm (Recommended)
npm install -g @ssossan/mcp-openapi-connector
Or use directly with npx:
npx @ssossan/mcp-openapi-connector
From Source
git clone https://github.com/ssossan/mcp-openapi-connector.git
cd mcp-openapi-connector
npm install
Quick Setup (Recommended)
Run the interactive setup wizard:
npm run setup
This will:
- Collect your API configuration through interactive prompts
- Generate
generated/.envfile with your settings - Create
generated/claude-desktop-config.jsonfor easy Claude Desktop integration - Provide step-by-step instructions for Claude Desktop configuration
Manual Configuration
Alternatively, you can set up manually:
- Copy
.env.exampleto.env:
cp .env.example .env
- Edit
.envwith your API credentials:
CLIENT_ID=your-client-id
CLIENT_SECRET=your-client-secret
API_BASE_URL=https://api.example.com
AUTH_PATH=/oauth/token
OPENAPI_SPEC_PATH=./config/openapi.json
Usage
Development Mode
For development with automatic recompilation:
npm run dev
Production Mode
Build and run the compiled version:
npm run build
npm start
Claude Desktop Configuration
Add to your Claude Desktop config file:
Using npm package (Recommended):
{
"mcpServers": {
"openapi-connector": {
"command": "npx",
"args": ["@ssossan/mcp-openapi-connector"],
"env": {
"CLIENT_ID": "your-client-id",
"CLIENT_SECRET": "your-client-secret",
"API_BASE_URL": "https://api.example.com",
"AUTH_PATH": "/oauth/token",
"OPENAPI_SPEC_PATH": "/path/to/openapi.json"
}
}
}
}
Using global installation:
{
"mcpServers": {
"openapi-connector": {
"command": "mcp-openapi-connector",
"env": {
"CLIENT_ID": "your-client-id",
"CLIENT_SECRET": "your-client-secret",
"API_BASE_URL": "https://api.example.com",
"AUTH_PATH": "/oauth/token",
"OPENAPI_SPEC_PATH": "/path/to/openapi.json"
}
}
}
}
Using from source:
{
"mcpServers": {
"openapi-connector": {
"command": "node",
"args": ["/path/to/mcp-openapi-connector/dist/mcp-openapi-connector.js"],
"cwd": "/path/to/mcp-openapi-connector",
"env": {
"CLIENT_ID": "your-client-id",
"CLIENT_SECRET": "your-client-secret",
"API_BASE_URL": "https://api.example.com",
"AUTH_PATH": "/oauth/token",
"OPENAPI_SPEC_PATH": "/path/to/openapi.json"
}
}
}
}
OpenAPI Integration
The server automatically generates tools from an OpenAPI specification. An OpenAPI specification is required for the server to function.
- Place your OpenAPI spec file (JSON format) in the project
- Set the path in your environment:
OPENAPI_SPEC_PATH=./config/openapi.json
OPENAPI_TOOL_PREFIX=api_ # Optional: prefix for generated tool names
OPENAPI_INCLUDE_ONLY=listItems,createItem # Optional: only include specific operations
OPENAPI_EXCLUDE=deleteItem # Optional: exclude specific operations
The server will automatically generate MCP tools from all operations in your OpenAPI spec. Without an OpenAPI specification, the server will only provide test/debug tools.
Custom Tools
Create custom tools by adding a JavaScript file:
export default {
register(server) {
server.registerCustomTool('my_tool', {
name: 'my_tool',
description: 'My custom tool',
inputSchema: {
type: 'object',
properties: {
param: { type: 'string', required: true }
}
},
apiEndpoint: '/my-endpoint',
method: 'POST'
});
}
};
Then set CUSTOM_TOOLS_PATH in your environment:
CUSTOM_TOOLS_PATH=./src/tools/my-custom-tools.ts
Publishing to npm
For maintainers:
npm run build
npm test
npm publish --access public
Development
Available Scripts
npm run dev # Development mode with tsx
npm run build # Compile TypeScript to JavaScript
npm start # Build and run production version
npm run test # Build and run test server
npm run test:dev # Run test server in development mode
npm run typecheck # Type check without compilation
npm run clean # Remove build output
TypeScript Development
This project is built with TypeScript for better type safety and development experience:
- Source code:
src/directory - Build output:
dist/directory - Type definitions: Automatically generated
.d.tsfiles
Architecture
Claude Desktop ↔ MCP Server (stdio) → OpenAPI-based API
↓
TokenManager
(OAuth2 handling)
Key Components
- src/mcp-openapi-connector.ts - Main server entry point
- src/lib/token-manager.ts - OAuth2 token management with caching
- src/lib/saas-client.ts - HTTP client with automatic authentication
- src/lib/mcp-handler.ts - MCP protocol handling and tool registration
- src/lib/openapi-loader.ts - OpenAPI specification parser and tool generator
- src/types/ - TypeScript type definitions
Migration from v1.x
If you're using the previous gateway-based version:
- Remove the proxy server configuration
- Update your Claude Desktop config to point directly to this server
- Use the same environment variables (no changes needed)
Example: Using with a Generic OpenAPI-based API
See the config/openapi-example.json file for a sample OpenAPI specification that demonstrates how to structure your API for MCP integration.
Troubleshooting
Authentication Errors
- Verify CLIENT_ID and CLIENT_SECRET are correct
- Check AUTH_URL points to the correct OAuth2 endpoint
- Ensure your credentials have the necessary scopes
Connection Issues
- Check API_BASE_URL is correct
- Verify network connectivity
- Check server logs for detailed error messages
Debug Mode
Set NODE_ENV=development for verbose logging:
NODE_ENV=development npm run dev
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Acknowledgments
Built using the Model Context Protocol SDK by Anthropic.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。