MCP Server Framework - v1.1.2
    Preparing search index...
    • Create a spec-compliant structured response for tools that declare an output schema.

      Per MCP 2025-06-18 ("Structured Content"), tools that return structuredContent SHOULD also serialize the same payload into a TextContent block for backwards compatibility with clients that do not yet read outputSchema / structuredContent. Modern clients prefer structuredContent for typed access while the TextContent block stays available for display-oriented rendering and legacy consumers.

      By default the helper serializes data as pretty-printed JSON into the TextContent block — a safe, schema-faithful fallback. Pass StructuredResponseOptions.text | options.text to override the TextContent with a human-readable rendering (Markdown, ASCII table, etc.). The structuredContent payload remains the single source of truth in either case.

      For tools without an output schema (state-change confirmations, free-form messages), use text instead.

      Parameters

      • data: unknown

        The structured payload (must conform to the tool's output schema)

      • Optionaloptions: StructuredResponseOptions

        Optional text override, indent (default 2), annotations, and metadata

      Returns {
          _meta?: {
              "io.modelcontextprotocol/related-task"?: { taskId: string };
              progressToken?: string | number;
              [key: string]: unknown;
          };
          content: (
              | {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  text: string;
                  type: "text";
              }
              | {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  data: string;
                  mimeType: string;
                  type: "image";
              }
              | {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  data: string;
                  mimeType: string;
                  type: "audio";
              }
              | {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  description?: string;
                  icons?: {
                      mimeType?: string;
                      sizes?: string[];
                      src: string;
                      theme?: "light"
                      | "dark";
                  }[];
                  mimeType?: string;
                  name: string;
                  size?: number;
                  title?: string;
                  type: "resource_link";
                  uri: string;
              }
              | {
                  _meta?: { [key: string]: unknown };
                  annotations?: {
                      audience?: ("user" | "assistant")[];
                      lastModified?: string;
                      priority?: number;
                  };
                  resource: | {
                      _meta?: { [key: string]: unknown };
                      mimeType?: string;
                      text: string;
                      uri: string;
                  }
                  | {
                      _meta?: { [key: string]: unknown };
                      blob: string;
                      mimeType?: string;
                      uri: string;
                  };
                  type: "resource";
              }
          )[];
          isError?: boolean;
          structuredContent?: { [key: string]: unknown };
          [key: string]: unknown;
      }

      A CallToolResult with both structuredContent and a TextContent block

      defineTool({
      name: 'my_tool',
      output: mySchema,
      handler: async () => {
      const result = { ok: true, count: 42 };
      return structured(result);
      },
      });
      defineTool({
      name: 'list_items',
      output: listSchema,
      handler: async () => {
      const payload = { items: [...] };
      return structured(payload, {
      text: `### Items (${payload.items.length})\n\n${renderTable(payload.items)}`,
      });
      },
      });