Skip to content

Conversation

@jacksteamdev
Copy link
Contributor

Fixes #80

Problem

The inspector crashes when tool handlers return malformed responses. Specifically, when following the weather example from the docs, the inspector throws TypeError: f.content.map is not a function because the response structure doesn't match expectations.

Solution

  • Replace type assertions with Zod schema validation to catch malformed responses
  • Add error UI to display validation failures and help debug incorrect tool responses
  • Update imports to use CallToolResultSchema for runtime type checking

Changes

  • Uses safeParse() to validate without throwing
  • Shows both invalid data and validation errors in the UI
  • Maintains dark mode compatibility

Testing

  • Follow weather example from docs to verify fix
  • Test various malformed response scenarios
  • Check error display formatting
  • Verify dark mode styles

dsp-ant
dsp-ant previously approved these changes Nov 26, 2024
Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the improvement! This is quite sensible.

ashwin-ant
ashwin-ant previously approved these changes Nov 26, 2024
Copy link
Member

@ashwin-ant ashwin-ant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Left one small comment

</pre>
<h4 className="font-semibold mb-2">Errors:</h4>
{parsedResult.error.errors.map((error) => (
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this might need a key prop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashwin-ant Perfect! I've applied your suggestion.

@jacksteamdev jacksteamdev dismissed stale reviews from ashwin-ant and dsp-ant via 6057831 November 26, 2024 20:30
@ashwin-ant ashwin-ant merged commit 722df4d into modelcontextprotocol:main Nov 26, 2024
2 checks passed
@jacksteamdev jacksteamdev deleted the fix-1 branch November 26, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inspector UI Crash when CallToolResult content is not an array

3 participants