[Feature] De-couple Starlette from FastMCP to make it easier to implement MCP endpoints in other frameworks
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Xem xét tích hợp cấp thấp của MCPServer, các tool/resource/prompt managers, decorators và các phương thức handler được mô tả trong issue. So sánh các thiết lập dành riêng cho Starlette, transport và routing với ranh giới FastMCPBase được đề xuất, bao gồm tham chiếu FastMCP của Context; được xem là hoàn thành khi mã độc lập với framework vẫn giữ được các khả năng này, trong khi FastMCP giữ lại các mối quan tâm của Starlette.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
If someone wanted to implement an MCP server in another framework such as Django or some other ASGI implementation, one would have to use the mcp.server.lowlevel.Server class and implement handlers for the low-level server. This means we have to sacrifice a ton of functionality from FastMCP that really has nothing to do with the python server backend. For example tool/resource/prompt managers, decorators, etc would have to be re-impemented.
It seems that these features of FastMCP could be decoupled in to a base class or mixin that handles all the tool/resource/prompt management & decorators, as well as the integration with the low-level Server. You could then extend that class to implement your own server with all the routing and request/response logic.
The proposed base class would have minimal dependencies on these framework-specific concerns:
Base Class Dependencies:
- MCPServer from mcp.server.lowlevel.server
- Tool/Resource/Prompt managers
- Basic handler methods (list_tools, call_tool, etc.)
- The decorators (@tool, @resource, @prompt)
Server-specific Responsibilities:
- Settings handling (Settings class with HTTP config)
- Transport logic (stdio vs SSE)
- Routing (custom_route, Starlette routing)
class FastMCPBase:
"""Base class or mixin with tool/resource/prompt management and core handlers"""
def __init__(self, name: str, instructions: str = None):
self._mcp_server = MCPServer(name=name, instructions=instructions)
self._tool_manager = ToolManager()
self._resource_manager = ResourceManager()
self._prompt_manager = PromptManager()
self._setup_handlers()
# All the @tool, @resource, @prompt decorators
# All the list_tools, call_tool, etc. handler methods
# Context management
class FastMCP(FastMCPBase):
"""Starlette-specific implementation"""
def __init__(self, name: str, **settings):
super().__init__(name)
self.settings = Settings(**settings)
self._custom_starlette_routes = []
# Only Starlette-specific methods like sse_app, routing, etc.
The implementation in the other library could look like this:
class DjangoMCP(FastMCPBase):
"""Django-specific implementation"""
# Django-specific routing & transport logic
One slight complication could be the Context class as it has a reference to the FastMCP instance (self._fastmcp. However the only function that's used is read_resource which would already be on the base class. So possible just need to change the type hint to use the base class.
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 19 phút
- Pull request đã merge (30 ngày)
- 29
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
Streamable HTTP client logs a WARNING for valid 202 Accepted on session termination (DELETE) Đang mởv1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3546 · 5 bình luận ·
-
v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/python-sdk#3545 · 1 bình luận ·
-
v1 v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3508 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/python-sdk#3492 · 1 bình luận ·
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
from:qa priority:P2 reliability tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
spec-kitty/spec-kitty#4874 ·
-
fix: inaccuracy ⚠️
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
uabrc/uabrc.github.io#1255 · 1 bình luận ·
-
kind:bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ethereum-optimism/factory#64 ·