modelcontextprotocol / modelcontextprotocol/python-sdk

Prompt validation errors are logged with an unnecessary traceback

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

还没有人认领这个 Issue。

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

描述

Initial Checks
Release line

2.x (current stable)

Description

Description

When a prompt is called without a required argument, the request is correctly rejected, but the Python SDK logs the validation error with a full traceback.

To Reproduce

Steps to reproduce the behavior:

  1. Create a prompt with a required argument:

    @mcp.prompt()
    def diagnose_cluster(problem: str) -> str:
        return f"Diagnose: {problem}"
    
  2. Call prompts/list and confirm that problem is marked as required.

  3. Call prompts/get without providing the required argument:

    {
      "method": "prompts/get",
      "params": {
        "name": "diagnose_cluster"
      }
    }
    
  4. The request is rejected, but the server logs a full traceback:

    Error getting prompt diagnose_cluster
    Traceback (most recent call last):
      ...
      File ".../mcp/server/mcpserver/server.py", line 1285, in get_prompt
        rendered = await prompt.render(arguments, context)
      File ".../mcp/server/mcpserver/prompts/base.py", line 160, in render
        raise ValueError(f"Missing required arguments: {missing}")
    ValueError: Missing required arguments: {'problem'}
    
    handler for 'prompts/get' raised
    
Example Code

Python & MCP Python SDK
## Environment

- MCP Python SDK: v2
- Python: 3.x
- Server: `MCPServer`
- Prompt transport: Streamable HTTP

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 mcp/server/mcpserver/server.py 中的 get_prompt 开始,跟踪它对 mcp/server/mcpserver/prompts/base.py 中 render 的调用。在缺少必需的 problem 参数的情况下,复现针对 diagnose_cluster 的 prompts/get,然后检查验证错误是如何记录日志的。请求仍然被拒绝,且预期的验证错误在没有完整 traceback 的情况下被记录日志,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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