Support explicit elicitation capabilities and safe per-request narrowing

未關閉
#3,956 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
45/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

Read the capability construction and modern request stamping in src/mcp/client/session.py, identified in the issue references, and compare them with the reproduction in the issue body. First inspect how sampling_capabilities is configured and how concurrent requests carry client capabilities. Done means supported elicitation modes can be declared explicitly and modern requests can safely narrow capabilities without widening them or changing shared state; the issue leaves the API design open.

由索引模型根據 Issue 內容生成。

描述

Problem

Clients should advertise only the elicitation modes they can actually fulfill. While developing a stdio-to-Streamable-HTTP MCP bridge, we found two limitations in the Python SDK:

  1. Installing an elicitation callback advertises both form and url, even if the implementation supports forms only.
  2. On 2026-07-28 connections, the SDK replaces request-local clientCapabilities with the configured client capabilities. A caller cannot narrow them for an individual request.

We left elicitation relay disabled rather than advertise unsupported interaction modes.

This also affects potential use cases beyond transport bridges: terminal and embedded clients that implement forms but not URL interactions; proxies and gateways serving hosts with different capabilities or interaction policies; and agents that need to disable user interaction for unattended requests. The common requirement is accurate capability declaration, not a bridge-specific API.

Reproduction

The original SDK 2.2.0 findings have now been reproduced on v2.3.0 and main at 77001c96.

Environment: CPython 3.13.18; isolated environments with mcp/mcp-types 2.3.0 (HTTPX2 2.17.0), and local builds from the cited main commit. The modern results agree across real loopback Streamable HTTP and in-process tests. Legacy behavior was also tested.

This minimal example was run verbatim on both versions:

import anyio
from mcp import types
from mcp.client import Client
from mcp.server.lowlevel import Server
from mcp_types import CLIENT_CAPABILITIES_META_KEY


async def elicit(ctx, params):
    return types.ElicitResult(action="decline")


async def list_tools(ctx, params):
    return types.ListToolsResult(tools=[
        types.Tool(name="inspect", input_schema={"type": "object"})
    ])


async def inspect(ctx, params):
    caps = ctx.session.client_capabilities
    return types.CallToolResult(
        content=[], structured_content=caps.model_dump(exclude_none=True)
    )


async def main():
    server = Server("fixture", on_list_tools=list_tools, on_call_tool=inspect)
    async with Client(server, mode="auto", elicitation_callback=elicit) as client:
        result = await client.call_tool(
            "inspect", {}, meta={CLIENT_CAPABILITIES_META_KEY: {"elicitation": {"form": {}}}}
        )
        print(result.structured_content["elicitation"])


anyio.run(main)

Actual output: {'form': {}, 'url': {}}.

Additional runtime cases on both versions:

Scenario Observed elicitation capability Desired capability
No callback (control) Absent Absent
Form-only implementation with callback Form + URL Form only
Modern request narrowed to form Form + URL Form only
Modern request narrowed to no interaction Form + URL Absent
Concurrent modern requests A (form only) and B (none) Both Form + URL A: Form only; B: Absent

Server-side control: hand-built 2026-07-28 requests to the same server preserve form-only, form+URL and absent elicitation declarations. The observed limitation is in the SDK client, not the server's handling of these request capabilities. Legacy per-connection capability behavior is expected and is not a defect.

Alternative: separate client instances can distinguish no interaction (no callback) from full elicitation (callback), but still cannot express form-only support. Separate instances also require routing and additional connection/discovery setup.

Possible API direction (open to maintainer preference)
  • An optional elicitation_capabilities parameter, analogous to sampling_capabilities, to express supported modes explicitly. Preserve existing defaults.
  • For modern requests, a supported way to narrow configured capabilities per request. It should never permit widening beyond what the client can fulfill, must not mutate shared client state, and should isolate concurrent requests. Leave legacy negotiation unchanged.

The two limitations are reproduced; the proposed API changes are design requests, not a prescribed implementation. I would be interested in helping with a focused fix if this direction is appropriate.

References

AI disclosure: AI coding assistants helped investigate, run the reproductions, compare SDK source, and prepare this issue. No implementation PR has been opened.

主要語言
Python
星號
25k
分支
4.2k
平均合併
10 分鐘
30 天內合併 PR
1

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。