Calling an unknown tool logs a server-side Error "threw an unhandled exception"
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start in src/ModelContextProtocol.Core/Server/McpServerImpl.cs, tracing the unknown-tool handler and the BuildInitialAlternateToolFilter and LogToolCallLifecycles paths that call ToolCallError. Compare this path with the existing Logs_Tool_Error_When_Tool_Throws_McpProtocolException test. Done means an unknown tool still returns JSON-RPC -32602 without an Error log, while an exception thrown by a tool remains logged at Error.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When a client calls a tool that does not exist, the server answers correctly with JSON-RPC -32602 (Unknown tool: '…'), but it also writes a server-side Error with a stack trace:
fail: "no_such_tool" threw an unhandled exception.
ModelContextProtocol.McpProtocolException: Unknown tool: 'no_such_tool'
The cause is input from the client, not a fault of the server, yet it looks like a crash in logs, APM and alerting. Any client (or a model that hallucinates a tool name) can produce these Errors at will.
Where (2.4.0, unchanged on main)
src/ModelContextProtocol.Core/Server/McpServerImpl.cs
- The default handler throws
new McpProtocolException($"Unknown tool: '{name}'", McpErrorCode.InvalidParams)(line ~1603). BuildInitialAlternateToolFilter(line ~1737) andLogToolCallLifecycles(line ~1787) callToolCallError(LogLevel.Error, "threw an unhandled exception.") for every exception except cancellation andInputRequiredException, including thisMcpProtocolException, and then rethrow it as the protocol error.
Reproduction
Server with any tool, client calls tools/call with the name no_such_tool. Expected: -32602 to the client, no Error on the server. Actual: -32602 and the Error above.
Context
Logs_Tool_Error_When_Tool_Throws_McpProtocolException asserts that an McpProtocolException thrown by a tool is logged at Error, so I understand that is intended. The unknown-tool case is different: no tool ran, and the exception comes from the SDK's own validation of the request.
Proposal
Do not log ToolCallError when no tool was matched for the request (the SDK's own unknown-tool path), or log it at Debug/Information like ToolCallCompleted. The protocol error to the client stays as it is.
Workaround we use today: an incoming message filter (WithMessageFilters(f => f.AddIncomingFilter(...))) that answers tools/call for unknown names with -32602 before the tool pipeline runs. Happy to send a PR if the direction is acceptable.
- Ngôn ngữ chính
- C#
- Star
- 4.6k
- Fork
- 849
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/csharp-sdk
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
modelcontextprotocol/csharp-sdk#2031 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Static resources whose URIs differ only in the fragment or user info collapse into oneCó thể đã có người làm @halter73 đã nhận 9 ngày trước. Đang mởP2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
modelcontextprotocol/csharp-sdk#1970 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
POST /mcp with a missing or unparseable Content-Type returns HTTP 500 instead of a 4xxCó thể đã có người làm @halter73 đã nhận 9 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
modelcontextprotocol/csharp-sdk#1966 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Reserved URI-template expansion throws for supplementary Unicode charactersCó thể đã có người làm @tarekgh đã nhận 2 ngày trước. Đang mởP3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
modelcontextprotocol/csharp-sdk#1913 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ClaimsPrincipal parameter injection sample requestCó thể đã có người làm @utsavjain2809 đã nhận 48 ngày trước. Đang mởhelp wanted P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
modelcontextprotocol/csharp-sdk#1899 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/csharp-sdk
Issue tương tự
-
account bug effort:S P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nightscout/nocturne#3745 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
grate-devs/grate#969 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
jsboige/CoursIA#27768 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
martin-stromberg/FinanceManager#562 ·
Maintainer thường phản hồi trong vòng 1 ngày