Exception handling improvment #584
-
When an exception happens during tool calls, if it's not MCPException, the error message is $"An error occurred invoking '{request.Params?.Name}'."; The message doesn't contain too much info, why can't we print exception type and message as well? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
It's not about "printing". It's about what the server sends down to the client. Having arbitrary server-side exceptions, possibly containing arbitrary user and environmental data, be automically sent to the client, would be a significant security issue. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I understand it would a security issue if sending down to the client, actually my usage scenario is enterprise, the mcp server is only accessible with a small group of people inside company, returning detailed exception type & message(can promise no PII) would be great for people to report issue. so the best way is to catch exception inside my tool? |
Beta Was this translation helpful? Give feedback.
-
Yes. If you want it sent down to the client as an error, you can return a CallToolResult out of your tool, with its IsError set to true. Or you can catch your exception and wrap it in an McpException, which as you noted will then be special-cased to allow the message through. |
Beta Was this translation helpful? Give feedback.
Yes. If you want it sent down to the client as an error, you can return a CallToolResult out of your tool, with its IsError set to true.
Or you can catch your exception and wrap it in an McpException, which as you noted will then be special-cased to allow the message through.