[MCPServer] Optional ResourcesAsTools support ala FastMCP
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Look at the MCP server implementation in the python-sdk, particularly how resources and tools are registered and exposed. Examine FastMCP's ResourcesAsTools transform for reference. The work involves adding a new transform class, modifying tool generation logic, and ensuring compatibility with existing resource definitions. Start by understanding the server's resource and tool handling in the SDK's core modules.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
As per FastMCP's documentation:
Some MCP clients only support tools. They cannot list or read resources directly because they lack resource protocol support.
An example of this is Cursor.
A workaround for this is that FastMCP provides the ResourcesAsTools transform to bridge this gap by exposing list_resources and read_resource as tools.
It would be great if we support this feature here. Would love to open & scope a PR here if it's something we should support.
Additional Implementation Considerations
However, the above still requires tool-only clients (and the LLM using them) to:
- Call
list_resourcesto discover available resources/templates. - Identify the relevant URI or URI template.
- Construct the resource URI manually for templates.
- Call
read_resourcewith that URI.
This is particularly awkward for resource templates, where the parameters are already known by the resource definition but are not exposed as a tool input schema.
For example:
@mcp.resource("user://{user_id}/profile")
def user_profile(user_id: str) -> str:
...
A tool-only client currently has to discover the template and construct:
user://42/profile
before calling read_resource.
It would be great if ResourcesAsTools could optionally expose each resource and resource template as an individual tool.
For example:
@mcp.resource("config://app")
def app_config() -> str:
...
@mcp.resource("user://{user_id}/profile")
def user_profile(user_id: str) -> str:
...
mcp.add_transform(ResourcesAsTools(mcp, individual_tools=True))
could expose tools resembling:
app_config()
user_profile(user_id: str)
The generated tools would:
- Reuse the resource's name, description, MIME type, and other metadata where appropriate.
- Derive their input schema from the resource template parameters.
- Internally resolve/read the corresponding resource.
- Preserve the resource URI in the tool result where possible.
- Continue to respect the server's existing middleware, authorization, visibility, and other resource-level behavior.
This would make resources much more natural to consume from clients that only support tools/list / tools/call, while keeping the existing ResourcesAsTools behavior available for applications that prefer the generic list_resources / read_resource interface.
Example
Given:
@mcp.resource("data://{dataset}/{year}")
def dataset(dataset: str, year: int) -> str:
...
a generated tool could look conceptually like:
{
"name": "dataset",
"description": "...",
"inputSchema": {
"type": "object",
"properties": {
"dataset": {"type": "string"},
"year": {"type": "integer"}
},
"required": ["dataset", "year"]
}
}
The client could then simply call:
await client.call_tool(
"dataset",
{"dataset": "election_results", "year": 2022}
)
without needing to know how the underlying resource URI is constructed.
Alternatives considered
If maintainer's want to support this, the existing list_resources + read_resource approach works, but it exposes the resource protocol's URI-oriented abstraction directly to the model. Generating tools would instead let tool-only clients consume the same resources through the interface they already understand.
Proposed Scope
We should PR iteratively:
- Add FastMCP-stype
list_resourcesandread_resourcetools. - Optional Add
individual_tool=True. This allows for one tool per resource/template with anInputSchema.
Other
- Willing to submit PR
- AI Assistance (Cursor)
References
No response
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 11 Std.
- Gemergte PRs (30 T.)
- 30
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/python-sdk
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
modelcontextprotocol/python-sdk#3566 ·
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
modelcontextprotocol/python-sdk#3546 · 5 Kommentare ·
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
modelcontextprotocol/python-sdk#3545 · 1 Kommentar ·
-
v1 v2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
modelcontextprotocol/python-sdk#3508 · 2 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
modelcontextprotocol/python-sdk#3504 ·
Alle Issues in modelcontextprotocol/python-sdk
Ähnliche Issues
-
essnmx good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 95/100
-
[Feature] 奇物选择添加优先级 Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
syfoud/Simulated_Scepter#174 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Giskard-AI/giskard-oss#2840 · 1 Kommentar ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Offenarea: repo bug perceived difficulty: 2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
yeti-platform/yeti#1380 ·