Calling an unknown tool logs a server-side Error "threw an unhandled exception"
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 75/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 4.6k
- Fork
- 849
- Merge medio
- 1g 16h
- PR unite (30g)
- 24
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di modelcontextprotocol/csharp-sdk
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
modelcontextprotocol/csharp-sdk#2031 ·
I maintainer di solito rispondono entro 1 giorno
-
Static resources whose URIs differ only in the fragment or user info collapse into oneForse già presa @halter73 l’ha presa 9 giorni fa. ApertaP2
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
modelcontextprotocol/csharp-sdk#1970 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
POST /mcp with a missing or unparseable Content-Type returns HTTP 500 instead of a 4xxForse già presa @halter73 l’ha presa 9 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
modelcontextprotocol/csharp-sdk#1966 · 5 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Reserved URI-template expansion throws for supplementary Unicode charactersForse già presa @tarekgh l’ha presa 2 giorni fa. ApertaP3
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
modelcontextprotocol/csharp-sdk#1913 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
ClaimsPrincipal parameter injection sample requestForse già presa @utsavjain2809 l’ha presa 48 giorni fa. Apertahelp wanted P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
modelcontextprotocol/csharp-sdk#1899 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di modelcontextprotocol/csharp-sdk
Issue simili
-
account bug effort:S P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nightscout/nocturne#3745 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
grate-devs/grate#969 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
jsboige/CoursIA#27768 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
martin-stromberg/FinanceManager#562 ·
I maintainer di solito rispondono entro 1 giorno