Skip to content

Add Runtime Type Validation for Tool Results - #82

Merged
ashwin-ant merged 4 commits into
modelcontextprotocol:mainfrom
jacksteamdev:fix-1
Nov 26, 2024
Merged

ashwin-ant merged 4 commits into
modelcontextprotocol:mainfrom
jacksteamdev:fix-1

Conversation

@jacksteamdev

Copy link
Copy Markdown
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

@dsp-ant dsp-ant left a comment

Copy link
Copy Markdown
Member

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

@ashwin-ant ashwin-ant left a comment

Copy link
Copy Markdown
Member

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

Comment thread client/src/components/ToolsTab.tsx Outdated
</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
Copy Markdown
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
Copy Markdown
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.

Comment thread client/src/components/ToolsTab.tsx Resolved
@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
@jacksteamdev
jacksteamdev deleted the fix-1 branch November 26, 2024 20:35
cliffhall added a commit that referenced this pull request Oct 20, 2026
CodeQL flagged the stamp's plain SHA-256 of the client secret as an
insufficient password hash (js/insufficient-password-hash, alert #82).
The digest sat in the same store as the secret, so it revealed nothing
that store does not, but the shape is still a fast unkeyed hash of a
secret. The stamp now carries an HMAC over the client_id keyed by the
credential: only a writer holding the value can produce it, it matches
only that value, and it also refuses a stamp whose client_id was
swapped.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: cliffhall <[email protected]>
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