modelcontextprotocol / modelcontextprotocol/python-sdk
Prompt validation errors are logged with an unnecessary traceback
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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:
-
Create a prompt with a required argument:
@mcp.prompt() def diagnose_cluster(problem: str) -> str: return f"Diagnose: {problem}" -
Call
prompts/listand confirm thatproblemis marked as required. -
Call
prompts/getwithout providing the required argument:{ "method": "prompts/get", "params": { "name": "diagnose_cluster" } } -
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 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