-
Notifications
You must be signed in to change notification settings - Fork 2.9k
MiniMCP - A minimal, stateless, and lightweight framework for building MCP servers #1761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Define external errors (MiniMCPError and subclasses) - Define internal errors (InternalMCPError and subclasses) - Define special tool errors (SpecialToolError hierarchy) - Define message handling types (Message, NoMessage, Send)
- Implement message builders for responses, notifications, and errors - Add utility functions for request ID extraction and validation - Add JSONRPCEnvelope helper for efficient message parsing - Add comprehensive unit test suite for the above
- Add MCPFunc class for validating and executing MCP handler functions - Support automatic schema generation from function signatures - Add argument validation and async/sync execution support - Add comprehensive unit test suite
- Implement ToolManager class for managing MCP tool handlers - Add tool registration via decorator (@mcp.tool()) or programmatically - Support tool listing, calling, and removal operations - Add automatic schema inference from function signatures - Add error handling with special tool exceptions - Add comprehensive unit test suite
- Implement ResourceManager class for managing MCP resource handlers - Add support for static resources and resource templates (parameterized URIs) - Add resource registration via decorator (@mcp.resource(uri)) or programmatically - Support resource listing, reading by URI/name, and removal operations - Add URI pattern matching and template parameter validation - Add comprehensive unit test suite
…ution - Implement PromptManager class for managing MCP prompt handlers - Add prompt registration via decorator (@mcp.prompt()) or programmatically - Support prompt listing, getting, and removal operations - Add automatic argument inference from function signatures - Add support for multiple content types and annotations - Add comprehensive unit test suite
- Implement Limiter class for enforcing concurrency and idle timeout limits - Add TimeLimiter for resettable idle timeout management - Support configurable max_concurrency and idle_timeout settings - Add comprehensive unit test suite
- Implement Responder class for sending notifications from handlers to clients - Add report_progress() method for progress updates during long-running operations - Add send_notification() method for general server notifications - Support automatic idle timeout reset when sending notifications - Add comprehensive unit test suite
- Implement ContextManager for tracking active handler contexts - Add Context dataclass for holding request metadata (message, time_limiter, scope, responder) - Support thread-safe and async-safe context isolation using contextvars - Add helper methods (get_scope, get_responder) for common access patterns - Add comprehensive unit test suite
- Implement MiniMCP class as main entry point for building MCP servers - Integrate ToolManager, PromptManager, ResourceManager, and ContextManager - Add message processing pipeline (parsing, validation, dispatch, error handling) - Add concurrency control with configurable idle timeout and max concurrency - Support protocol handshake with initialize request/response handling - Add comprehensive unit test suite - Added RESOURCE_NOT_FOUND in mcp.types
- Implement StdioTransport per MCP stdio specification - Add message reading from stdin and writing to stdout - Support newline-delimited JSON-RPC message protocol - Add message validation (no embedded newlines per spec) - Support concurrent message handling with task groups - Add comprehensive unit test suite
…ansport) - Implement BaseHTTPTransport as abstract base for HTTP transports - Add HTTPTransport for standard HTTP POST request/response - Add dispatch() method for handling HTTP requests to MiniMCP - Add protocol version validation via MCP-Protocol-Version header - Add request validation (method, headers, media type) - Add Starlette support - Add comprehensive unit test suites
…TP communication - Implement StreamableHTTPTransport extending BaseHTTPTransport - Add dispatch() method with streaming response handling - Add SSE (Server-Sent Events) support for server-to-client streaming - Add StreamManager for lifecycle management of memory object streams - Support bidirectional communication (POST requests + SSE responses) - Add graceful stream cleanup with configurable drain delay - Add Starlette support - Add comprehensive unit test suite
- Export MiniMCP, transports, and core types - Export orchestration classes and exceptions - Define __all__ for explicit public API
…transports - Add integration test suite for StdioTransport - Add integration test suite for HTTPTransport - Add integration test suite for StreamableHTTPTransport - Add test helpers (client session, HTTP utilities, process management) - Add math_mcp example server for integration testing - Add server fixtures and conftest configuration - Add psutil dependency for process management in tests
- Add math_mcp.py with tools, prompts, and resources - Add server implementations for all three transports - Demonstrate MiniMCP features with mathematical operations
- Add issue tracker MCP with scope-based auth - Add FastAPI integration example - Add Django WSGI integration example
- Add benchmarking framework and infrastructure - Add benchmarks for all three transports (stdio, HTTP, streamable HTTP) - Add analysis tools and comprehensive performance report - Include benchmark results for sync and async tool calls
- Add README.md with complete MiniMCP guide and API reference - Add TESTING.md with testing documentation - Document architecture, examples, and troubleshooting
a3900c2 to
36c3166
Compare
- Add tests for error scenarios across all managers and transports - Add edge case coverage for MiniMCP core orchestrator - Add validation and error handling tests - Clean up test imports
|
Checks are failing due to coverage issues. I’m working on it. |
|
Thanks for putting this together, clearly took quite a bit of work! Unfortunately we're going to close this PR as it's out of scope for the SDK. We currently already maintain two server layers/implementations, lowlevel and FastMCP. Adding a third would be a lot of maintenance burden. For these sorts of massive wide scale additions/changes we first would need this to be discussed, designed, and planned along with the maintainers of the Python SDK. We're soon going to be adding explicit wording around this to the CONTRIBUTING.md file. If you'd like to continue developing this, I'd recommend publishing this as a standalone package, similar to how FastMCP 2 split off to build their own package. |
|
Thank you for the review, @maxisbey. |
|
Linking issue #1371 for context. |
MiniMCP is a new high-performance framework for building MCP servers with a focus on simplicity, statelessness, and embeddability. This PR introduces a complete implementation with core orchestration, managers, transports, comprehensive tests, benchmarks, examples, and documentation. Despite the breadth of features, the core implementation remains compact - just over 1,800 lines of code, excluding docstrings.
Motivation and Context
While the existing FastMCP and low-level server implementations work well for many use cases, there's a need for a more lightweight, stateless approach that:
MiniMCP orchestration layer exposes a single asynchronous
handle()function that processes JSON-RPC 2.0 messages, making it transport-agnostic and easy to integrate anywhere.Benchmarks
How Has This Been Tested?
Unit Tests
Integration Tests
Manual Testing
Examples
Breaking Changes
None. This is a new addition to the SDK and does not affect existing FastMCP or low-level server implementations.
Types of changes
Checklist
Additional context
Architecture
MiniMCP consists of several key components:
MiniMCP) - Message lifecycle management, validation, dispatch, and error handlingKey Design Decisions
Documentation
Future Work
Potential additions (not in this PR):