modelcontextprotocol / modelcontextprotocol/python-sdk

[Bug] check_capability does not validate elicitation sub-capabilities (form/url)

未关闭 适合新手
#2,965 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug needs confirmation P2 v2
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
31

描述

Summary

Connection.check_capability() returns True when a client has URL-mode elicitation but the caller checks for form-mode elicitation — the sub-capability (ElicitationCapability.form / .url) is never inspected.

Root cause

In src/mcp/server/connection.py:340-341:

if capability.elicitation is not None and have.elicitation is None:
    return False

This only returns False when the client has no elicitation at all. It does not check individual sub-capabilities (form / url). Compare with sampling, which correctly checks sub-capabilities:

if capability.sampling is not None:
    if have.sampling is None:
        return False
    if capability.sampling.context is not None and have.sampling.context is None:
        return False
    if capability.sampling.tools is not None and have.sampling.tools is None:
        return False

Reproduction

# Client supports URL elicitation only
have = ClientCapabilities(elicitation=ElicitationCapability(url=UrlElicitationCapability()))

# Check for form elicitation — should be False (client does not have form)
want = ClientCapabilities(elicitation=ElicitationCapability(form=FormElicitationCapability()))

Connection.from_envelope("2025-11-25", client_info, have).check_capability(want)  # Returns True (BUG)

Impact

  • check_capability is public API (via ServerSession.check_client_capability)
  • Currently no production callers use elicitation sub-capability checks — low immediate impact
  • But once someone relies on it (e.g., checking if the client supports form elicitation before calling elicit_form), it will return wrong results

Additional gaps (lower priority)

  • extensionsClientCapabilities.extensions is not checked at all
  • tasksClientCapabilities.tasks and sub-capabilities entirely unhandled

Proposed fix

Add form / url sub-capability checks, matching the sampling pattern:

if capability.elicitation is not None:
    if have.elicitation is None:
        return False
    if capability.elicitation.form is not None and have.elicitation.form is None:
        return False
    if capability.elicitation.url is not None and have.elicitation.url is None:
        return False

AI assistance: Bug discovered and analyzed with AI assistance (opencode).

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 src/mcp/server/connection.py 的第340-341行附近开始,将 elicitation 处理与现有的 sampling 检查进行比较。复现 issue 中 URL-only 与 form-only capabilities 的情况,然后验证匹配和不匹配的 form/url capabilities 是否在相关测试套件中返回预期结果。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
冷清
描述清晰度
描述清楚
新手友好度
82/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。