Title: Document best Practice for Handling Argument Errors in MCP Tool Rendering · Issue #356 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: Document best Practice for Handling Argument Errors in MCP Tool Rendering · Issue #356 · modelcontextprotocol/java-sdk
X Title: Document best Practice for Handling Argument Errors in MCP Tool Rendering · Issue #356 · modelcontextprotocol/java-sdk
Description: I'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments. Specifically: Should we throw an exception, or should we catch the error and return it as part of the McpS...
Open Graph Description: I'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments. Specifically: Should we throw an exception, or should we catch the...
X Description: I'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments. Specifically: Should we throw an exception, or should we catch...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/356
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Document best Practice for Handling Argument Errors in MCP Tool Rendering","articleBody":"\nI'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments.\n\nSpecifically:\nShould we **throw an exception**, or should we **catch the error and return it as part of the `McpSchema.CallToolResult`** so the LLM can understand what went wrong and possibly correct the request in a future interaction?\n\n#### Example Scenario:\n\nI have a tool that expects two parameters: `first_name` and `last_name`. It returns a simple greeting message.\nIf the request includes only `first_name` and `last_name` is null, how should the error be handled?\n\nOption 1 — **Throw an exception**:\n\n```java\ncatch (Exception e) {\n throw new McpError(e);\n}\n```\n\nOption 2 — **Catch and return the error message**:\n\n```java\ncatch (Exception e) {\n contents.add(\n new McpSchema.TextContent(\"Error: \" + e.getMessage())\n );\n}\n```\n\nWhich approach aligns better with MCP's error-handling philosophy and the intended LLM experience?\n","author":{"url":"https://github.com/Eraoui909","@type":"Person","name":"Eraoui909"},"datePublished":"2025-06-30T09:04:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/356/java-sdk/issues/356"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d760171c-162a-4899-6754-ac6149216136 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E44:20A434:7409A1:9FD18D:6A603C58 |
| html-safe-nonce | 53fe3994f5cba091b59a4754f421de1bdbb4107fcf82d869416e3cef50ecf78b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTQ0OjIwQTQzNDo3NDA5QTE6OUZEMThEOjZBNjAzQzU4IiwidmlzaXRvcl9pZCI6IjYxNjQwNjQ3NTkyMjk0NjM2NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3b245abf56346980b634b6452dd0b03bbf8dd2956139dbef958c98084dadb693 |
| hovercard-subject-tag | issue:3187716982 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/java-sdk/356/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b57d33cbc1461b841c1f63bccd7dcf24327a614f01af12f3babf88c848323f50/modelcontextprotocol/java-sdk/issues/356 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b57d33cbc1461b841c1f63bccd7dcf24327a614f01af12f3babf88c848323f50/modelcontextprotocol/java-sdk/issues/356 |
| og:image:alt | I'm uncertain about the recommended approach for handling errors in MCP, especially when it comes to missing or invalid arguments. Specifically: Should we throw an exception, or should we catch the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Eraoui909 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60da8c2a42fa2bbf5f7567474990ec467836a84444262a58e200fa91b7f3d2d0 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9824515e740d83d5eb82168a089b806ab0fe04a1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width