From 9d80b75c0d0edbe610d274bbf8c7b79283660781 Mon Sep 17 00:00:00 2001 From: Ishaan Gupta Date: Fri, 3 Jul 2026 21:08:47 +0530 Subject: [PATCH] fix(mcp): return graph view message from fetch-graph-data --- apps/mcp/src/server/tools/fetch-graph-data.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/mcp/src/server/tools/fetch-graph-data.ts b/apps/mcp/src/server/tools/fetch-graph-data.ts index e2d2b083..770a0996 100644 --- a/apps/mcp/src/server/tools/fetch-graph-data.ts +++ b/apps/mcp/src/server/tools/fetch-graph-data.ts @@ -1,6 +1,6 @@ import { registerAppTool } from "@modelcontextprotocol/ext-apps/server" import { z } from "zod" -import { SUPERMEMORY_RESOURCE_URI } from "../../shared/types" +import { SUPERMEMORY_RESOURCE_URI, type ViewMessage } from "../../shared/types" import type { ToolDeps } from "./types" export function register(deps: ToolDeps) { @@ -44,9 +44,23 @@ export function register(deps: ToolDeps) { args.limit, ) + // structuredContent must be a ViewMessage - the widget dispatches on + // `view` and renders anything else as an "unrecognized response" error. + const sc: ViewMessage = { + view: "graph", + containerTag: effectiveTag, + documents: data.documents, + totalCount: data.pagination.totalItems, + } + return { - content: [{ type: "text" as const, text: JSON.stringify(data) }], - structuredContent: data, + content: [ + { + type: "text" as const, + text: `Fetched ${data.documents.length} documents (page ${data.pagination.currentPage} of ${data.pagination.totalPages}, ${data.pagination.totalItems} total)${effectiveTag ? `. Workspace: ${effectiveTag}` : ""}`, + }, + ], + structuredContent: sc, } } catch (error) { return deps.errorResult(error)