This directory contains comprehensive examples demonstrating how to use @ivotoby/openapi-mcp-server as a library to create dedicated MCP servers for specific APIs.
The @ivotoby/openapi-mcp-server package can be used in two ways:
- CLI Tool: Use
npx @ivotoby/openapi-mcp-serverdirectly with command-line arguments - Library: Import and use the
OpenAPIServerclass in your own Node.js applications
These examples focus on the library usage, showing how to create dedicated, customized MCP servers for specific APIs.
Purpose: Demonstrates the simplest way to use the library with static authentication.
Key Features:
- Basic
OpenAPIServerconfiguration - Static header authentication
- Stdio transport for Claude Desktop integration
- Minimal setup for quick prototyping
When to use: When you have a simple API with static authentication and want to get started quickly.
Purpose: Showcases the AuthProvider interface for dynamic authentication scenarios.
Key Features:
- Multiple AuthProvider implementations (Refreshable, Manual, API Key)
- Token expiration handling
- Authentication error recovery
- Dynamic header generation
When to use: When your API requires token refresh, has expiring tokens, or needs complex authentication logic.
Purpose: Real-world implementation for the Beatport API demonstrating production-ready patterns.
Key Features:
- Custom AuthProvider for manual token management
- API endpoint filtering and optimization
- Comprehensive error handling with user guidance
- Production-ready packaging and distribution
When to use: As a template for creating production-ready MCP servers for specific APIs.
CLI Usage (what most users start with):
npx @ivotoby/openapi-mcp-server \
--api-base-url https://api.example.com \
--openapi-spec https://api.example.com/openapi.json \
--headers "Authorization:Bearer token"Library Usage (what these examples show):
import { OpenAPIServer } from "@ivotoby/openapi-mcp-server"
const server = new OpenAPIServer({
name: "my-api-server",
apiBaseUrl: "https://api.example.com",
openApiSpec: "https://api.example.com/openapi.json",
headers: { Authorization: "Bearer token" },
})The AuthProvider interface enables dynamic authentication:
interface AuthProvider {
getAuthHeaders(): Promise<Record<string, string>>
handleAuthError(error: AxiosError): Promise<boolean>
}Benefits:
- Fresh headers for each request
- Token expiration handling
- Authentication error recovery
- Runtime token updates
All examples demonstrate different configuration patterns:
- Transport Types: Stdio (Claude Desktop) vs HTTP (web clients)
- Tool Loading: All endpoints vs filtered subsets vs dynamic meta-tools
- Authentication: Static headers vs dynamic AuthProvider
- API Filtering: Include/exclude specific endpoints, operations, or tags
- Simple API with static auth → Start with Basic Library Usage
- API with token expiration → Use AuthProvider Example
- Production deployment → Follow Beatport Example patterns
Each example is a complete, standalone project:
- Copy the example directory
- Update
package.jsonwith your details - Modify the configuration for your API
- Implement custom authentication if needed
- Build and deploy
Examples show how to create distributable packages:
{
"name": "my-api-mcp-server",
"bin": {
"my-api-mcp-server": "dist/index.js"
}
}Users can then install and use your server:
npx my-api-mcp-serverconst config = {
// ... other config
headers: {
Authorization: "Bearer token",
"X-API-Key": "key",
},
}const authProvider = new MyAuthProvider()
const config = {
// ... other config
authProvider: authProvider,
}const config = {
// ... other config
includeOperations: ["get", "post"],
includeResources: ["users", "posts"],
includeTags: ["public"],
}class MyAuthProvider implements AuthProvider {
async handleAuthError(error: AxiosError): Promise<boolean> {
if (error.response?.status === 401) {
// Provide clear instructions
throw new Error("Token expired. Please...")
}
return false
}
}- Custom authentication logic
- API-specific optimizations
- Custom error handling
- Additional tools and features
- Package as standalone npm modules
- Version control and updates
- Easy installation for users
- Professional deployment
- Embed in larger applications
- Custom transport implementations
- Integration with existing auth systems
- Custom middleware and processing
- API-specific documentation
- Tailored user experience
- Focused feature set
- Better error messages
- Explore the Examples: Start with the basic example and work your way up
- Read the Documentation: Check the main README for all configuration options
- Implement Your API: Use the patterns to create your own dedicated server
- Share Your Work: Consider publishing your server for others to use
Found a useful pattern or want to add an example? Contributions are welcome!
- Add new examples for different authentication patterns
- Improve existing examples with better error handling
- Add examples for specific popular APIs
- Document advanced configuration patterns