Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
fix(mcp): expose downstream project tool results (#43)
antinrml6ddd6a500f1a
diff --git a/lib/host/project-mcp-result.test.ts b/lib/host/project-mcp-result.test.tsindex 24974003..f5434725 100644--- a/lib/host/project-mcp-result.test.ts+++ b/lib/host/project-mcp-result.test.ts@@ -1,5 +1,5 @@import { expect, it } from "vitest";-import { projectMcpResult } from "./project-mcp-result";+import { projectMcpResult, projectMcpStructuredProjection } from "./project-mcp-result";it("preserves rich results and downstream errors without granting a canvas origin", () => {const content = [{ type: "image", mimeType: "image/png", data: "aGVsbG8=" }, { type: "audio", mimeType: "audio/wav", data: "aGVsbG8=" }, { type: "resource_link", uri: "https://example.com/file", name: "file" }];const result = projectMcpResult({ content, isError: true, structuredContent: { id: 1 }, _meta: { ui: { resourceUri: "ui://untrusted" } } });@@ -7,3 +7,26 @@ it("preserves rich results and downstream errors without granting a canvas origiexpect(result.meta).toEqual({ "mso/downstream": { ui: { resourceUri: "ui://untrusted" } } });expect(() => projectMcpResult({ content: [{ type: "image" }] })).toThrow("malformed");});++it("projects downstream text and metadata into structured output without duplicating binary payloads", () => {+ const raw = projectMcpResult({ content: [+ { type: "text", text: "{\"ok\":true}" },+ { type: "image", mimeType: "image/png", data: "base64-secret-binary" },+ { type: "resource_link", uri: "https://example.com/file", name: "file" },+ { type: "resource", resource: { uri: "mcp://text", text: "hello", mimeType: "text/plain" } },+ { type: "resource", resource: { uri: "mcp://blob", blob: "base64-resource-binary", mimeType: "application/octet-stream" } },+ ], structuredContent: { id: 1 } });+ const projected = projectMcpStructuredProjection(raw);+ expect(projected).toMatchObject({+ content: [+ { type: "text", text: "{\"ok\":true}" },+ { type: "image", mimeType: "image/png", binaryOmitted: true },+ { type: "resource_link", uri: "https://example.com/file", name: "file" },+ { type: "resource", resource: { uri: "mcp://text", text: "hello", mimeType: "text/plain" } },+ { type: "resource", resource: { uri: "mcp://blob", binaryOmitted: true, mimeType: "application/octet-stream" } },+ ],+ structuredContent: { id: 1 },+ });+ expect(JSON.stringify(projected)).not.toContain("base64-secret-binary");+ expect(JSON.stringify(projected)).not.toContain("base64-resource-binary");+});diff --git a/lib/host/project-mcp-result.ts b/lib/host/project-mcp-result.tsindex ab9e0a4b..2cdf0aeb 100644--- a/lib/host/project-mcp-result.ts+++ b/lib/host/project-mcp-result.ts@@ -1,5 +1,7 @@import type { McpContent } from "@/lib/contracts/mcp-content";+const object = (v: unknown): v is Record<string, unknown> => Boolean(v && typeof v === "object" && !Array.isArray(v));+export function projectMcpResult(raw: unknown) {if (!object(raw) || !Array.isArray(raw.content)) throw new Error("downstream MCP returned an invalid CallToolResult");const content = raw.content.map((block): McpContent => {@@ -11,7 +13,35 @@ export function projectMcpResult(raw: unknown) {(typeof block.resource.text === "string" || typeof block.resource.blob === "string")) return block as McpContent;throw new Error("unsupported or malformed downstream MCP content");});- return { content, isError: raw.isError === true, structuredContent: object(raw.structuredContent) ? raw.structuredContent : undefined,+ return {+ content,+ isError: raw.isError === true,+ structuredContent: object(raw.structuredContent) ? raw.structuredContent : undefined,// Downstream UI origins cannot grant themselves access to MSO's trusted canvas.- meta: object(raw._meta) ? { "mso/downstream": raw._meta } : undefined };+ meta: object(raw._meta) ? { "mso/downstream": raw._meta } : undefined,+ };+}++export function projectMcpStructuredProjection(result: ReturnType<typeof projectMcpResult>) {+ const content = result.content.map((block) => {+ if (block.type === "text") return { type: "text", text: block.text };+ if (block.type === "resource_link") return { type: "resource_link", uri: block.uri, name: block.name };+ if (block.type === "resource") {+ const resource = block.resource;+ return {+ type: "resource",+ resource: {+ uri: resource.uri,+ ...(typeof resource.text === "string" ? { text: resource.text } : { binaryOmitted: true }),+ ...(typeof resource.mimeType === "string" ? { mimeType: resource.mimeType } : {}),+ },+ };+ }+ return { type: block.type, mimeType: block.mimeType, binaryOmitted: true };+ });+ return {+ content,+ ...(result.isError ? { isError: true } : {}),+ ...(result.structuredContent ? { structuredContent: result.structuredContent } : {}),+ };}diff --git a/lib/mcp/tools-project-mcp.ts b/lib/mcp/tools-project-mcp.tsindex cc284800..54db95f3 100644--- a/lib/mcp/tools-project-mcp.ts+++ b/lib/mcp/tools-project-mcp.ts@@ -1,5 +1,5 @@import { callManagedScProvider } from "./managed-sc-call";-import { projectMcpResult } from "@/lib/host/project-mcp-result";+import { projectMcpResult, projectMcpStructuredProjection } from "@/lib/host/project-mcp-result";import { callProjectMcpTool, listProjectMcpToolPage, publicProjectMcpServers, readProjectMcpServers, resolveProjectHint } from "@/lib/host/projects-api";import { type McpTool, S, str, mcpDirect } from "./tool-kit";@@ -48,7 +48,7 @@ export const PROJECT_MCP_TOOLS: McpTool[] = [const project = await resolveProjectHint(str(a, "project")); if (!project) throw new Error(`project not found: ${String(a.project)}`);const managed = await callManagedScProvider(project.path, str(a, "server"), str(a, "tool"), a.arguments ?? {});const out = projectMcpResult(managed.handled ? managed.result : await callProjectMcpTool(project.path, str(a, "server"), str(a, "tool"), a.arguments ?? {}));- return mcpDirect(out.content, out.isError, { result: { project: project.id, server: str(a, "server"), tool: str(a, "tool"), ...(out.structuredContent ? { structuredContent: out.structuredContent } : {}) } }, out.meta);+ return mcpDirect(out.content, out.isError, { result: { project: project.id, server: str(a, "server"), tool: str(a, "tool"), output: projectMcpStructuredProjection(out) } }, out.meta);},},];