I have successfully implemented OpenAPI endpoint support for the EPR MCP Server. This implementation provides a comprehensive API interface with automatic MCP tool generation, interactive documentation, and schema validation.
A complete OpenAPI 3.0 specification that defines:
- Schemas: Event, EventReceiver, EventReceiverGroup, SearchCriteria, Error
- Endpoints:
- Fetch operations:
GET /api/v1/{resource}/{id} - Create operations:
POST /api/v1/{resource} - Search operations:
POST /api/v1/{resource}/search - Health check:
GET /health
- Fetch operations:
- Request/Response types: Proper typing for all operations
- Validation rules: Required fields, data types, constraints
Enhanced the existing server with:
-
OpenAPI Spec Endpoints:
GET /openapi.yaml- YAML format specificationGET /openapi.json- JSON format specificationGET /docs- Swagger UI interactive documentation
-
Improved Error Handling: Better HTTP status codes and error messages
-
Structured Responses: All responses now use model objects and return JSON
-
Schema Integration: Full integration with existing Pydantic validation schemas
A demonstration of how to use FastMCP's native OpenAPI integration:
- FastMCPOpenAPI Class: Shows how to leverage FastMCP's built-in OpenAPI support
- Route Mappings: Configuration to map OpenAPI paths to MCP components
- Handler Classes: Structured approach for handling API operations
- Updated GraphQLQuery: Fixed to support dictionary variables
- Model Integration: Full integration between dataclass models and API operations
- Validation: Consistent ValidationError usage throughout the codebase
- Comprehensive Tests (
tests/test_openapi.py): Validates OpenAPI spec structure and schemas - Demo Script (
openapi_demo.py): Interactive demonstration of capabilities - Updated README: Complete documentation of OpenAPI features
- Updated Dependencies: Added PyYAML for OpenAPI spec handling
The OpenAPI specification can be used with FastMCP to automatically generate MCP tools, eliminating manual tool definition.
Swagger UI provides a user-friendly interface to explore and test the API endpoints directly in the browser.
- Pydantic schemas for request validation
- Dataclass models for response serialization
- OpenAPI schemas for API documentation
- Consistent error handling with ValidationError
- Works with existing manual MCP tool definitions
- Can be migrated to use FastMCP's OpenAPI integration
- Maintains backward compatibility
- Extensible for future enhancements
When the server is running on http://localhost:8000:
| Endpoint | Purpose | Format |
|---|---|---|
/openapi.yaml |
OpenAPI specification | YAML |
/openapi.json |
OpenAPI specification | JSON |
/docs |
Interactive API documentation | HTML (Swagger UI) |
/health |
Health check | Plain text |
From the OpenAPI specification, these MCP tools are available:
- fetchEvent - Retrieve a single event by ID
- fetchReceiver - Retrieve a single event receiver by ID
- fetchGroup - Retrieve a single event receiver group by ID
- createEvent - Create a new event
- createReceiver - Create a new event receiver
- createGroup - Create a new event receiver group
- searchEvents - Search for events with criteria
- searchReceivers - Search for event receivers with criteria
- searchGroups - Search for event receiver groups with criteria
- healthCheck - Health status check
- Clear API contract with OpenAPI specification
- Interactive testing with Swagger UI
- Automatic tool generation reduces boilerplate
- Type-safe operations with proper validation
- Consistent interface across all operations
- Self-documenting API with examples
- Better error messages and status codes
- Structured JSON responses
- Single source of truth for API definition
- Automatic validation ensures consistency
- Easy to extend with new operations
- Clear separation of concerns
- Install Dependencies:
pip install PyYAML fastmcp - Start Server: Run with your EPR configuration
- Explore API: Visit
http://localhost:8000/docs - Use MCP Tools: Integrate with MCP clients
- Extend: Add new operations to the OpenAPI spec
src/epr_mcp/
├── openapi.yaml # OpenAPI 3.0 specification
├── server.py # Enhanced MCP server with OpenAPI endpoints
├── openapi_server.py # Alternative FastMCP OpenAPI implementation
├── models.py # Data models (Event, EventReceiver, etc.)
├── schemas.py # Pydantic validation schemas
└── ...
tests/
├── test_openapi.py # OpenAPI specification tests
└── ...
openapi_demo.py # Interactive demonstration script
README.md # Updated documentation
This implementation provides a robust, well-documented, and extensible foundation for the EPR MCP Server with full OpenAPI support.