A powerful Node.js server that dynamically converts any OpenAPI/Swagger specification into Model Context Protocol (MCP) tools, making APIs instantly accessible to AI assistants like Claude.
๐ What This Does
Transform any REST API into AI-friendly tools in seconds:
- Point to any OpenAPI spec (local file or URL)
- Get instant MCP tools for schema analysis AND API execution
- Use with Claude or any MCP-compatible AI assistant
โจ Key Features
- Universal Compatibility: Works with any OpenAPI 2.x or 3.x specification
- Dual Tool Types: Schema analysis tools + Dynamic HTTP execution tools
- Multiple Transports: HTTP server + STDIO for Claude integration
- Auto-Discovery: Automatically generates CRUD tools from your API paths
- Zero Configuration: Just point to a schema and go
- Production Ready: Full error handling, logging, and monitoring
๐ฆ Quick Start
# Install git clone https://github.com/your-username/openapi-mcp-server.git cd openapi-mcp-server npm install # Configure (pick one) export OPENAPI_URL="https://petstore.swagger.io/v2/swagger.json" export OPENAPI_URL="./samples/petstore.yaml" export OPENAPI_URL="https://your-api.com/swagger.json" # Start the server npm start
That's it! Your API is now available as MCP tools.
๐ ๏ธ What You Get
Schema Analysis Tools (Always Available)
- list-endpoints - See all API paths and methods
- get-endpoint - Detailed endpoint information
- get-request-body - Request schemas and validation
- get-response-schema - Response formats
- list-components - Schema components and models
- search-schema - Full-text search across the spec
- list-security-schemes - Authentication methods
Dynamic HTTP Execution Tools (Auto-Generated)
For each API endpoint, get semantic tools like:
- search-users -
GET /users - create-user -
POST /users - read-user -
GET /users/{id} - update-user -
PUT /users/{id} - delete-user -
DELETE /users/{id} - execute-request - Generic HTTP execution tool
๐ฏ Real-World Examples
Petstore API
export OPENAPI_URL="https://petstore.swagger.io/v2/swagger.json" npm start
Result: 15+ tools including search-pet, create-pet, update-pet, etc.
Your Company API
export OPENAPI_URL="https://your-company.com/api/swagger.json" export API_BASE_URL="https://your-company.com/api" export API_TOKEN="your-bearer-token" npm start
Result: Full API access through semantic tools + Claude integration
Local Development
export OPENAPI_URL="./openapi.yaml" export API_BASE_URL="http://localhost:3000" npm start
Result: Local API testing through MCP tools
๐ง Configuration
| Variable | Description | Example |
|---|---|---|
OPENAPI_URL |
Path or URL to OpenAPI spec | ./spec.yaml or https://api.com/swagger.json |
API_BASE_URL |
Base URL for API execution | https://api.example.com |
API_TOKEN |
Bearer token for authentication | eyJhbGciOiJIUzI1NiIs... |
PORT |
Server port | 8000 (default) |
๐ค Claude Integration
For Desktop Claude
- Start the MCP client:
npm run client - Add to your Claude config:
{
"mcpServers": {
"openapi": {
"command": "node",
"args": ["/path/to/openapi-mcp-server/src/client.js"],
"env": {
"OPENAPI_URL": "https://your-api.com/swagger.json"
}
}
}
}For Web/API Usage
Use the HTTP endpoints directly:
curl -X POST http://localhost:8000/tools/call \ -H "Content-Type: application/json" \ -d '{"name": "list-endpoints", "arguments": {}}'
๐ก Available Transports
HTTP Server (Web APIs)
POST /tools/list- List available toolsPOST /tools/call- Execute toolsGET /sse- Server-Sent Events for real-timeGET /health- Health monitoring
STDIO (Claude Integration)
npm run client- Direct MCP protocol communication- Perfect for Claude Desktop integration
- Full streaming support
๐งช Testing
# Test with included Petstore sample cp .env.example .env # Edit .env: OPENAPI_URL=./samples/petstore.yaml npm start # Run comprehensive tests npm test # HTTP endpoints npm run test:mcp # MCP protocol npm run test:client # Full STDIO client npm run test:all # Everything
๐ Project Structure
โโโ src/
โ โโโ server.js # HTTP server entry point
โ โโโ client.js # STDIO client entry point
โ โโโ tools/
โ โ โโโ registerTools.js # Schema analysis tools
โ โ โโโ registerActions.js # HTTP execution tools
โ โโโ utils/
โ โ โโโ schemaLoader.js # OpenAPI schema loading
โ โ โโโ toolUtils.js # Tool management
โ โโโ routes/ # HTTP route handlers
โโโ test/ # Comprehensive test suite
โโโ samples/ # Example OpenAPI specs
๐ How It Works
- Schema Loading: Loads OpenAPI spec from file or URL
- Tool Generation: Creates MCP tools for both analysis and execution
- Dynamic Mapping: Maps HTTP operations to semantic tool names
- Parameter Handling: Automatically handles path/query/body parameters
- Authentication: Supports Bearer tokens and API keys
- Transport Agnostic: Works over HTTP or STDIO
๐จ Advanced Usage
Custom Tool Filtering
// Only generate tools for specific paths const filteredPaths = ['/users', '/orders'];
Authentication Strategies
# Bearer token export API_TOKEN="your-bearer-token" # API key in header export API_KEY="your-api-key"
Multiple APIs
Run multiple instances with different configs:
# API 1 PORT=8001 OPENAPI_URL="api1.yaml" npm start & # API 2 PORT=8002 OPENAPI_URL="api2.yaml" npm start &
๐ฆ Supported APIs
- โ OpenAPI 3.x (native support)
- โ Swagger 2.x (full compatibility)
- โ REST APIs with standard HTTP methods
- โ Authentication: Bearer, API Key, OAuth2
- โ Parameter Types: Path, Query, Header, Body
- โ Content Types: JSON, Form data, URL encoded
๐ Monitoring & Logging
- Built-in health checks at
/health - Structured logging with multiple levels
- Request/response tracking
- Error handling and reporting
- Performance metrics
๐ Security
- Request validation using Zod schemas
- Bearer token support
- CORS configuration
- Rate limiting (configurable)
- Error sanitization in production
๐ค Contributing
- Fork the repository
- Add support for your OpenAPI spec
- Run the test suite:
npm run test:all - Submit a pull request
๐ License
MIT License - use this to make any API accessible to AI assistants!
๐ Attribution
Originally inspired by openapi-introspect by Hannes Junnila. This project expands the concept with dynamic tool generation, HTTP execution, and full MCP protocol support.
Transform any API into AI-accessible tools in minutes, not hours.