`ClientSessionGroup` attempts to use capabilities that were not advertised
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 76/100
Rechercherichtung
Beginne bei mcp.client.session_group.ClientSessionGroup.connect_with_session und untersuche, wie die Methode die initialize_result-Fähigkeiten der Sitzung verwendet. Führe die mitgelieferte tools-only-Server-Reproduktion aus und bestätige, dass nicht angekündigte Prompts und Ressourcen nicht abgefragt werden, während angekündigte Tools ohne „Method not found“-Warnungen verfügbar bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
ClientSessionGroup calls session.list_tools, session.list_prompts(), and session.list_resources() unconditionally on every connect. It never consults the ServerCapabilities returned by initialize.
For a server that doesn't implement tools, prompts, or resources, the corresponding calls return a JSON-RPC Method not found error. The MCPError is squashed and a WARNING is emitted, e.g.,
WARNING:root:Could not fetch prompts: Method not found
This seems to contradict the MCP lifecycle spec (2025-11-25, Capability Negotiation / Operation):
Both parties MUST: ... Only use capabilities that were successfully negotiated.
ClientSessionGroup should inspect session.initialize_result.capabilities and only interrogate capabilities that the server advertised, e.g.,
caps = session.initialize_result.capabilities if session.initialize_result else None
if caps and caps.prompts is not None:
prompts = (await session.list_prompts()).prompts
...
if caps and caps.resources is not None:
resources = (await session.list_resources()).resources
...
if caps and caps.tools is not None:
tools = (await session.list_tools()).tools
...
Example Code
"""Repro: tools-only server + ClientSessionGroup emits WARNINGs."""
from __future__ import annotations
import anyio
from mcp import Client, types
from mcp.client.session_group import ClientSessionGroup
from mcp.server import Server, ServerRequestContext
async def handle_list_tools(
ctx: ServerRequestContext, params: types.PaginatedRequestParams | None
) -> types.ListToolsResult:
return types.ListToolsResult(
tools=[
types.Tool(
name="ping",
description="Ping",
input_schema={"type": "object", "properties": {}},
)
]
)
async def handle_call_tool(
ctx: ServerRequestContext, params: types.CallToolRequestParams
) -> types.CallToolResult:
return types.CallToolResult(content=[types.TextContent(type="text", text="pong")])
async def main() -> None:
server = Server(
"tools-only-server",
on_list_tools=handle_list_tools,
on_call_tool=handle_call_tool,
)
async with Client(server) as client:
# Server omits prompts/resources capabilities:
assert client.initialize_result.capabilities.prompts is None
assert client.initialize_result.capabilities.resources is None
group = ClientSessionGroup()
await group.connect_with_session(client.initialize_result.server_info, client.session)
if __name__ == "__main__":
anyio.run(main)
Python & MCP Python SDK
Python: 3.14.4
MCP Python SDK: main @ da4c118 (also reproducible on v1.27.1)
OS: Linux 6.6.87.2-microsoft-standard-WSL2 x86_64
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 19 Min.
- Gemergte PRs (30 T.)
- 29
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
-
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 ·
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
modelcontextprotocol/python-sdk#3492 · 1 Kommentar ·
Alle Issues in modelcontextprotocol/python-sdk
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
use-agent-os/agent-os#3314 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
BasedHardware/omi#15662 · 1 Kommentar ·
-
documentation help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
AiursoftWeb/AnduinOS-2#19 ·