Skip to content

Inspector UI Crash when CallToolResult content is not an array #80

Closed

Description

@jacksteamdev

I've followed the weather example from the docs, and the inspector crashes when the get_forecast handler returns with this error in the browser:

Uncaught TypeError: f.content.map is not a function
    at u (index-jOz_Q5JL.js:185:28299)
    at qE (index-jOz_Q5JL.js:185:30526)
    at $u (index-jOz_Q5JL.js:38:16998)
    at bc (index-jOz_Q5JL.js:40:3139)
    at Th (index-jOz_Q5JL.js:40:44737)
    at Eh (index-jOz_Q5JL.js:40:39727)
    at Lx (index-jOz_Q5JL.js:40:39655)
    at ra (index-jOz_Q5JL.js:40:39508)
    at Dc (index-jOz_Q5JL.js:40:35875)
    at _h (index-jOz_Q5JL.js:40:34826)

Perhaps the fastest way to explain is a quick Loom.

Minimal repro: https://github.com/jacksteamdev/weather-server/tree/main

Activity

  1. jacksteamdev commented on Nov 26, 2024

    @jacksteamdev
    ContributorAuthor

    A little bit more digging shows that the docs have the wrong return value for the handler; it should be an array.

    console.error(`Forecast for ${city}:`, forecasts);
    await setTimeout(5000);
    return {
      content: {
        mimeType: "application/json",
        text: JSON.stringify(forecasts, null, 2)
      } // content should be an array
    };

    The related code for this repo:

    if ("content" in toolResult) {
    const structuredResult = toolResult as CallToolResult;
    const isError = structuredResult.isError ?? false;
    return (
    <>
    <h4 className="font-semibold mb-2">
    Tool Result: {isError ? "Error" : "Success"}
    </h4>
    {structuredResult.content.map((item, index) => (

    In the wild, structuredResult.content could be anything.

  2. changed the title [-]Inspector UI Crash on tool use[/-] [+]Inspector UI Crash when handler returns invalid data[/+] on Nov 26, 2024
  3. changed the title [-]Inspector UI Crash when handler returns invalid data[/-] [+]Inspector UI Crash when CallToolResult content is not an array[/+] on Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions