Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

feat(connections): surface built-in orchestration MCP + tools modal

Yuting Zhong3030782f8c71
diff --git a/src/app/(app)/[project]/connections/page.tsx b/src/app/(app)/[project]/connections/page.tsx
index 9a300a53..d780355e 100644
--- a/src/app/(app)/[project]/connections/page.tsx
+++ b/src/app/(app)/[project]/connections/page.tsx
@@ -3,7 +3,9 @@ import { Card, CardContent } from "@/components/ui/card";
import { getProject } from "@/server/db/projects";
import { MCP_CATALOG, storedMcpKey } from "@/server/mcp-catalog";
import { getMcpStatus } from "@/server/mcp-state";
+import { summarizeBuiltinTools } from "@/server/mcp-server/tool-summaries";
import { McpCard } from "@/components/mcp-card";
+import { BuiltinMcpCard } from "@/components/builtin-mcp-card";
import { McpFlashBanner } from "@/components/mcp-flash-banner";
type Search = { mcp_connected?: string; mcp_error?: string };
@@ -26,33 +28,45 @@ export default async function ConnectionsPage({
MCP_CATALOG.map((s) => getMcpStatus(storedMcpKey(project.slug, s.key))),
);
+ // Built-in MCP: notfair-orchestration ships with the platform and serves
+ // every agent without OAuth or setup. We hand its tool summary straight
+ // to the card so the tools dialog opens with zero RPC delay.
+ const builtinTools = summarizeBuiltinTools();
+
return (
<div className="mx-auto max-w-3xl space-y-6">
<header>
- <h1 className="text-2xl font-semibold tracking-tight">Connections</h1>
+ <h1 className="text-2xl font-semibold tracking-tight">
+ MCP Connections
+ </h1>
<p className="text-sm text-muted-foreground">
- Project <span className="font-mono">{project.slug}</span> · MCP servers
- configured here are shared by every agent in this project. Each project
- gets its own OpenClaw key (and its own bearer token), so connecting
- here doesn&rsquo;t touch other projects&rsquo; setups.
+ MCPs are the tool servers your agents call into. Connect external
+ ones (Google Ads, etc.) with one click, or browse the orchestration
+ tools that ship built-in.
</p>
</header>
<McpFlashBanner connected={mcp_connected} error={mcp_error} />
- {MCP_CATALOG.length === 0 ? (
- <Card>
- <CardContent className="py-12 text-center text-sm text-muted-foreground">
- No MCP servers in the catalog yet.
- </CardContent>
- </Card>
- ) : (
- <div className="space-y-3">
- {MCP_CATALOG.map((spec, i) => (
+ <div className="space-y-3">
+ <BuiltinMcpCard
+ name="Orchestration"
+ description="Built-in tools your agents use to coordinate: assign tasks, request approvals, write PROJECT.md, comment, and report status."
+ tools={builtinTools}
+ />
+
+ {MCP_CATALOG.length === 0 ? (
+ <Card>
+ <CardContent className="py-12 text-center text-sm text-muted-foreground">
+ No external MCP servers in the catalog yet.
+ </CardContent>
+ </Card>
+ ) : (
+ MCP_CATALOG.map((spec, i) => (
<McpCard key={spec.key} spec={spec} status={statuses[i]} />
- ))}
- </div>
- )}
+ ))
+ )}
+ </div>
</div>
);
}
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx
index 3fe98afe..f40df3e7 100644
--- a/src/components/app-sidebar.tsx
+++ b/src/components/app-sidebar.tsx
@@ -49,7 +49,7 @@ const NAV: NavItem[] = [
{ href: "/tasks", label: "Tasks", icon: ListChecks },
{ href: "/crons", label: "Crons", icon: Clock },
{ href: "/activity", label: "Activity", icon: Activity },
- { href: "/connections", label: "Connections", icon: Plug },
+ { href: "/connections", label: "MCP Connections", icon: Plug },
{ href: "/settings", label: "Settings", icon: Settings },
];
diff --git a/src/components/builtin-mcp-card.tsx b/src/components/builtin-mcp-card.tsx
new file mode 100644
index 00000000..ca4c40e3
--- /dev/null
+++ b/src/components/builtin-mcp-card.tsx
@@ -0,0 +1,87 @@
+"use client";
+
+import { useState } from "react";
+import { Workflow, BookOpenText } from "lucide-react";
+
+import { Card, CardContent } from "@/components/ui/card";
+import { Button } from "@/components/ui/button";
+import { Badge } from "@/components/ui/badge";
+import { McpToolsDialog } from "@/components/mcp-tools-dialog";
+import type { ToolSummary } from "@/server/mcp-server/tool-summaries";
+
+/**
+ * Card for an MCP that ships with notfair-cmo itself — no OAuth, no
+ * connect/disconnect, always available to every agent. We distinguish
+ * it visually from external OAuth MCPs through:
+ *
+ * - icon: `Workflow` (orchestration) instead of `Plug` (external wire)
+ * - badge: "Built-in" emerald chip in place of a connection-state badge
+ * - right-side action: "View tools" only (no Connect button)
+ * - footer line states the tool count + "Self-hosted" instead of a
+ * connection-state detail line
+ *
+ * Tool list is supplied directly from the server-side describeTool walk
+ * so the dialog opens instantly — no RPC roundtrip.
+ */
+type Props = {
+ name: string;
+ description: string;
+ tools: ToolSummary[];
+};
+
+export function BuiltinMcpCard({ name, description, tools }: Props) {
+ const [open, setOpen] = useState(false);
+
+ return (
+ <>
+ <Card>
+ <CardContent className="space-y-4 p-5">
+ <div className="flex items-start justify-between gap-3">
+ <div className="flex min-w-0 items-start gap-3">
+ <div className="flex size-9 shrink-0 items-center justify-center rounded-md bg-emerald-500/10 ring-1 ring-inset ring-emerald-500/20">
+ <Workflow className="size-4 text-emerald-700 dark:text-emerald-400" />
+ </div>
+ <div className="min-w-0">
+ <div className="flex items-center gap-2">
+ <h3 className="text-sm font-medium">{name}</h3>
+ <Badge
+ variant="secondary"
+ className="h-4 gap-1 border-emerald-500/20 bg-emerald-500/10 px-1.5 text-[10px] font-medium tracking-wide text-emerald-700 uppercase dark:text-emerald-400"
+ >
+ Built-in
+ </Badge>
+ </div>
+ <p className="mt-0.5 text-xs text-muted-foreground">
+ {description}
+ </p>
+ <p className="mt-1 font-mono text-[11px] text-muted-foreground">
+ {tools.length} tool{tools.length === 1 ? "" : "s"} · self-hosted ·
+ no setup
+ </p>
+ </div>
+ </div>
+ <div className="shrink-0">
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ onClick={() => setOpen(true)}
+ >
+ <BookOpenText className="size-3.5" />
+ View tools
+ </Button>
+ </div>
+ </div>
+ </CardContent>
+ </Card>
+
+ <McpToolsDialog
+ open={open}
+ onOpenChange={setOpen}
+ mcpName={name}
+ mcpDescription={description}
+ tools={tools}
+ />
+ </>
+ );
+}
diff --git a/src/components/mcp-card.tsx b/src/components/mcp-card.tsx
index ba4a2161..49602f08 100644
--- a/src/components/mcp-card.tsx
+++ b/src/components/mcp-card.tsx
@@ -2,14 +2,27 @@
import { useState, useTransition } from "react";
import { useRouter } from "next/navigation";
-import { Plug, CheckCircle2, AlertTriangle, Loader2, Unplug, XCircle } from "lucide-react";
+import {
+ Plug,
+ CheckCircle2,
+ AlertTriangle,
+ Loader2,
+ Unplug,
+ XCircle,
+ BookOpenText,
+} from "lucide-react";
import { Card, CardContent } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { toast } from "sonner";
-import { startMcpConnect, disconnectMcpAction } from "@/server/actions/mcp";
+import {
+ startMcpConnect,
+ disconnectMcpAction,
+ listMcpToolsAction,
+} from "@/server/actions/mcp";
import type { McpSpec } from "@/server/mcp-catalog";
import type { McpRuntimeStatus } from "@/server/mcp-state";
+import { McpToolsDialog } from "@/components/mcp-tools-dialog";
type Props = {
spec: McpSpec;
@@ -19,6 +32,7 @@ type Props = {
export function McpCard({ spec, status }: Props) {
const [pending, startTransition] = useTransition();
const [busy, setBusy] = useState<"connect" | "disconnect" | null>(null);
+ const [toolsOpen, setToolsOpen] = useState(false);
const router = useRouter();
async function onConnect() {
@@ -57,60 +71,85 @@ export function McpCard({ spec, status }: Props) {
}
const isBusy = busy !== null || pending;
+ const canViewTools = status.state === "connected";
return (
- <Card>
- <CardContent className="space-y-4 p-5">
- <div className="flex items-start justify-between gap-3">
- <div className="flex items-start gap-3 min-w-0">
- <div className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted">
- <Plug className="size-4" />
- </div>
- <div className="min-w-0">
- <div className="flex items-center gap-2">
- <h3 className="text-sm font-medium">{spec.display_name}</h3>
- <StatusBadge status={status} />
+ <>
+ <Card>
+ <CardContent className="space-y-4 p-5">
+ <div className="flex items-start justify-between gap-3">
+ <div className="flex items-start gap-3 min-w-0">
+ <div className="flex size-9 shrink-0 items-center justify-center rounded-md bg-muted">
+ <Plug className="size-4" />
+ </div>
+ <div className="min-w-0">
+ <div className="flex items-center gap-2">
+ <h3 className="text-sm font-medium">{spec.display_name}</h3>
+ <StatusBadge status={status} />
+ </div>
+ <p className="mt-0.5 text-xs text-muted-foreground">
+ {spec.description}
+ </p>
+ <p className="mt-1 truncate font-mono text-[11px] text-muted-foreground">
+ {spec.resource_url}
+ </p>
</div>
- <p className="mt-0.5 text-xs text-muted-foreground">
- {spec.description}
- </p>
- <p className="mt-1 truncate font-mono text-[11px] text-muted-foreground">
- {spec.resource_url}
- </p>
+ </div>
+ <div className="shrink-0">
+ {status.state === "connected" ? (
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ disabled={isBusy}
+ onClick={onDisconnect}
+ >
+ {busy === "disconnect" ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : (
+ <Unplug className="size-3.5" />
+ )}
+ Disconnect
+ </Button>
+ ) : (
+ <Button type="button" size="sm" disabled={isBusy} onClick={onConnect}>
+ {busy === "connect" ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : (
+ <Plug className="size-3.5" />
+ )}
+ {status.state === "stale_token" ? "Reconnect" : "Connect"}
+ </Button>
+ )}
</div>
</div>
- <div className="shrink-0">
- {status.state === "connected" ? (
+
+ <div className="flex items-center justify-between gap-3">
+ <StatusDetail status={status} />
+ {canViewTools && (
<Button
type="button"
- variant="outline"
+ variant="ghost"
size="sm"
- disabled={isBusy}
- onClick={onDisconnect}
+ className="h-7 shrink-0 px-2 text-xs text-muted-foreground hover:text-foreground"
+ onClick={() => setToolsOpen(true)}
>
- {busy === "disconnect" ? (
- <Loader2 className="size-3.5 animate-spin" />
- ) : (
- <Unplug className="size-3.5" />
- )}
- Disconnect
- </Button>
- ) : (
- <Button type="button" size="sm" disabled={isBusy} onClick={onConnect}>
- {busy === "connect" ? (
- <Loader2 className="size-3.5 animate-spin" />
- ) : (
- <Plug className="size-3.5" />
- )}
- {status.state === "stale_token" ? "Reconnect" : "Connect"}
+ <BookOpenText className="size-3.5" />
+ View tools
</Button>
)}
</div>
- </div>
+ </CardContent>
+ </Card>
- <StatusDetail status={status} />
- </CardContent>
- </Card>
+ <McpToolsDialog
+ open={toolsOpen}
+ onOpenChange={setToolsOpen}
+ mcpName={spec.display_name}
+ mcpDescription={spec.description}
+ loadTools={() => listMcpToolsAction({ mcp_key: spec.key })}
+ />
+ </>
);
}
diff --git a/src/components/mcp-tools-dialog.tsx b/src/components/mcp-tools-dialog.tsx
new file mode 100644
index 00000000..2332d4ab
--- /dev/null
+++ b/src/components/mcp-tools-dialog.tsx
@@ -0,0 +1,236 @@
+"use client";
+
+import { useEffect, useMemo, useState } from "react";
+import { Loader2, Search } from "lucide-react";
+
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import { Badge } from "@/components/ui/badge";
+import { cn } from "@/lib/utils";
+import type { ToolSummary } from "@/server/mcp-server/tool-summaries";
+
+/**
+ * Tools modal for an MCP card.
+ *
+ * Two source modes:
+ * - `tools` prop is supplied (built-in / self-hosted MCP — server-rendered
+ * summary handed in directly, no network needed)
+ * - `loadTools` is supplied (external MCP — async server action invoked
+ * on first open, result cached)
+ *
+ * Layout is closer to an API-reference than a JSON dump: each tool gets
+ * a monospace name, a one-line description, and a small grid of args
+ * showing name (mono) · type · required-marker · arg description.
+ * Search filters across tool name + arg names + description text.
+ */
+type Props = {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ mcpName: string;
+ /** Optional one-liner shown under the title — what the MCP does. */
+ mcpDescription?: string;
+ /** Eagerly-supplied tools (built-in MCP). Mutually exclusive with loadTools. */
+ tools?: ToolSummary[];
+ /** Lazy loader (external MCP). Called once on first open. */
+ loadTools?: () => Promise<
+ { ok: true; tools: ToolSummary[] } | { ok: false; error: string }
+ >;
+};
+
+export function McpToolsDialog({
+ open,
+ onOpenChange,
+ mcpName,
+ mcpDescription,
+ tools: eagerTools,
+ loadTools,
+}: Props) {
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const [lazyTools, setLazyTools] = useState<ToolSummary[] | null>(null);
+ const [q, setQ] = useState("");
+
+ // Lazy-load once on first open. Cache forever after — connecting +
+ // disconnecting wouldn't change a tool list inside one session of the
+ // modal being mounted, and the dialog unmounts on close anyway.
+ useEffect(() => {
+ if (!open) return;
+ if (eagerTools) return;
+ if (!loadTools) return;
+ if (lazyTools !== null) return;
+ let cancelled = false;
+ setLoading(true);
+ setError(null);
+ void loadTools()
+ .then((r) => {
+ if (cancelled) return;
+ if (r.ok) setLazyTools(r.tools);
+ else setError(r.error);
+ })
+ .catch((err) => {
+ if (cancelled) return;
+ setError(err instanceof Error ? err.message : String(err));
+ })
+ .finally(() => {
+ if (!cancelled) setLoading(false);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [open, eagerTools, loadTools, lazyTools]);
+
+ const tools = eagerTools ?? lazyTools ?? [];
+
+ const filtered = useMemo(() => {
+ const needle = q.trim().toLowerCase();
+ if (!needle) return tools;
+ return tools.filter((t) => {
+ if (t.name.toLowerCase().includes(needle)) return true;
+ if (t.description.toLowerCase().includes(needle)) return true;
+ return t.args.some(
+ (a) =>
+ a.name.toLowerCase().includes(needle) ||
+ a.description.toLowerCase().includes(needle),
+ );
+ });
+ }, [tools, q]);
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent
+ showCloseButton
+ className="flex max-h-[85vh] flex-col gap-0 overflow-hidden p-0 sm:max-w-2xl"
+ >
+ <DialogHeader className="border-b px-6 pt-5 pb-4">
+ <DialogTitle className="flex items-baseline gap-2">
+ <span>{mcpName}</span>
+ <span className="text-xs font-normal text-muted-foreground">
+ {tools.length} {tools.length === 1 ? "tool" : "tools"}
+ </span>
+ </DialogTitle>
+ {mcpDescription && (
+ <DialogDescription className="text-xs">
+ {mcpDescription}
+ </DialogDescription>
+ )}
+ </DialogHeader>
+
+ {/* Sticky search row — sits between header and scroll area. */}
+ <div className="border-b bg-card px-6 py-2.5">
+ <div className="relative">
+ <Search
+ aria-hidden
+ className="absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground"
+ />
+ <Input
+ autoFocus
+ value={q}
+ onChange={(e) => setQ(e.target.value)}
+ placeholder={`Search ${tools.length} tools…`}
+ className="h-8 pl-8 text-xs"
+ disabled={loading}
+ aria-label="Search tools"
+ />
+ </div>
+ </div>
+
+ {/* Scroll area */}
+ <div className="min-h-0 flex-1 overflow-y-auto">
+ {loading && (
+ <div className="flex items-center justify-center gap-2 py-12 text-xs text-muted-foreground">
+ <Loader2 className="size-3.5 animate-spin" />
+ Fetching tool list…
+ </div>
+ )}
+ {!loading && error && (
+ <div className="px-6 py-12 text-center text-sm text-destructive">
+ {error}
+ </div>
+ )}
+ {!loading && !error && tools.length === 0 && (
+ <div className="px-6 py-12 text-center text-sm text-muted-foreground">
+ This MCP exposes no tools.
+ </div>
+ )}
+ {!loading && !error && tools.length > 0 && filtered.length === 0 && (
+ <div className="px-6 py-12 text-center text-sm text-muted-foreground">
+ No tools match{" "}
+ <span className="font-mono text-foreground">{q}</span>.
+ </div>
+ )}
+ {!loading && !error && filtered.length > 0 && (
+ <ul className="divide-y">
+ {filtered.map((t) => (
+ <ToolRow key={t.name} tool={t} />
+ ))}
+ </ul>
+ )}
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+}
+
+function ToolRow({ tool }: { tool: ToolSummary }) {
+ const requiredCount = tool.args.filter((a) => a.required).length;
+ return (
+ <li className="px-6 py-4">
+ <div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">
+ <code className="rounded bg-muted px-1.5 py-0.5 font-mono text-[12px] text-foreground">
+ {tool.name}
+ </code>
+ {tool.args.length > 0 && (
+ <span className="text-[10px] text-muted-foreground">
+ {requiredCount}/{tool.args.length} required
+ </span>
+ )}
+ </div>
+ {tool.description && (
+ <p className="mt-1.5 text-xs leading-relaxed text-muted-foreground">
+ {tool.description}
+ </p>
+ )}
+ {tool.args.length > 0 && (
+ <ul className="mt-3 space-y-1.5">
+ {tool.args.map((a) => (
+ <li
+ key={a.name}
+ className="grid grid-cols-[minmax(0,8rem)_minmax(0,7rem)_minmax(0,1fr)] items-baseline gap-x-3 text-[11px]"
+ >
+ <span className="truncate font-mono text-foreground">
+ {a.name}
+ {a.required && (
+ <span aria-label="required" className="ml-0.5 text-destructive">
+ *
+ </span>
+ )}
+ </span>
+ <Badge
+ variant="outline"
+ className={cn(
+ "h-4 truncate px-1 font-mono text-[9px] font-normal",
+ // enums get a quieter slate-toned outline; primitives stay default
+ a.type.startsWith("enum:") && "border-dashed",
+ )}
+ title={a.type}
+ >
+ {a.type}
+ </Badge>
+ <span className="truncate text-muted-foreground" title={a.description}>
+ {a.description || (
+ <span className="italic opacity-60">no description</span>
+ )}
+ </span>
+ </li>
+ ))}
+ </ul>
+ )}
+ </li>
+ );
+}
diff --git a/src/server/actions/mcp.ts b/src/server/actions/mcp.ts
index 3f209f65..a9e2b250 100644
--- a/src/server/actions/mcp.ts
+++ b/src/server/actions/mcp.ts
@@ -106,6 +106,74 @@ export async function disconnectMcpAction(input: {
return { ok: true };
}
+/**
+ * Fetch the tool list for an external (OAuth-connected) MCP. Driven by the
+ * tools modal on the Connections page — lazy on dialog-open so we don't
+ * pay the RPC roundtrip when the user is just glancing at the page.
+ *
+ * Probes the MCP's tools/list endpoint with the stored bearer, then
+ * normalizes each entry into the same ToolSummary shape we ship for
+ * built-in tools — the modal renders both identically.
+ */
+export async function listMcpToolsAction(input: {
+ mcp_key: string;
+}): Promise<
+ | { ok: true; tools: import("@/server/mcp-server/tool-summaries").ToolSummary[] }
+ | { ok: false; error: string }
+> {
+ const project = await getActiveProject();
+ if (!project) {
+ return { ok: false, error: "No active project." };
+ }
+ const stored_key = storedMcpKey(project.slug, input.mcp_key);
+ const { getMcpConfig, mcpRpc } = await import("@/server/mcp/rpc");
+ const cfg = await getMcpConfig(stored_key);
+ if (!cfg) {
+ return { ok: false, error: "MCP is not configured for this project." };
+ }
+ const r = await mcpRpc<{ tools?: Array<{ name?: unknown; description?: unknown; inputSchema?: unknown }> }>(
+ cfg.url,
+ cfg.token,
+ "tools/list",
+ {},
+ { timeoutMs: 5_000 },
+ );
+ if (!r.ok) {
+ const message =
+ r.kind === "http_error"
+ ? `HTTP ${r.status}`
+ : r.kind === "rpc_error"
+ ? `RPC ${r.code}: ${r.message}`
+ : r.kind === "timeout"
+ ? "MCP call timed out"
+ : r.kind === "aborted"
+ ? "MCP call aborted"
+ : r.kind === "malformed_response"
+ ? r.message
+ : r.message;
+ return { ok: false, error: message };
+ }
+ const { argsFromJsonSchema } = await import("@/server/mcp-server/tool-summaries");
+ const tools = Array.isArray(r.result?.tools)
+ ? r.result.tools
+ .filter(
+ (
+ t,
+ ): t is { name: string; description?: string; inputSchema?: Record<string, unknown> } =>
+ typeof t?.name === "string",
+ )
+ .map((t) => ({
+ name: t.name,
+ description: typeof t.description === "string" ? t.description : "",
+ args:
+ t.inputSchema && typeof t.inputSchema === "object"
+ ? argsFromJsonSchema(t.inputSchema)
+ : [],
+ }))
+ : [];
+ return { ok: true, tools };
+}
+
// ─── helpers ────────────────────────────────────────────────────────
type ResolvedAuthServer = {
diff --git a/src/server/mcp-server/tool-summaries.ts b/src/server/mcp-server/tool-summaries.ts
new file mode 100644
index 00000000..b563893a
--- /dev/null
+++ b/src/server/mcp-server/tool-summaries.ts
@@ -0,0 +1,91 @@
+import { TOOLS, describeTool } from "./tools";
+
+/**
+ * Client-safe summary of an MCP tool, suitable for rendering in the
+ * tools modal. We deliberately don't pass zod schemas (or full JSON
+ * Schema trees) across the server/client boundary — the modal cares
+ * about name + description + arg list, not validation.
+ *
+ * Same shape for built-in (notfair-orchestration) tools we own + for
+ * external (Google Ads etc.) tools we learn about via tools/list. The
+ * modal renders both identically.
+ */
+export type ToolArgSummary = {
+ name: string;
+ /**
+ * One-token type hint: "string", "number", "boolean", `enum: a|b|c`,
+ * "array<string>", "object". Picked for human readability rather
+ * than schema fidelity.
+ */
+ type: string;
+ description: string;
+ required: boolean;
+};
+
+export type ToolSummary = {
+ name: string;
+ description: string;
+ args: ToolArgSummary[];
+};
+
+/**
+ * Walk TOOLS (server-side; the registry holds zod schemas + handlers)
+ * and produce a JSON-safe summary array for the connections-page
+ * built-in MCP card. We piggyback on describeTool() which already runs
+ * the zod → JSON Schema conversion this app needs for the MCP protocol
+ * surface, so the modal stays in lockstep with what agents actually see.
+ */
+export function summarizeBuiltinTools(): ToolSummary[] {
+ return TOOLS.map((tool) => {
+ const desc = describeTool(tool);
+ return {
+ name: desc.name,
+ description: desc.description,
+ args: argsFromJsonSchema(desc.inputSchema),
+ };
+ });
+}
+
+type JsonSchemaProp = {
+ type?: string | string[];
+ description?: string;
+ enum?: unknown[];
+ items?: { type?: string };
+};
+
+type JsonSchemaObject = {
+ type?: string;
+ properties?: Record<string, JsonSchemaProp>;
+ required?: string[];
+};
+
+/**
+ * Map a JSON-Schema object (the shape describeTool produces) into the
+ * flat arg-summary list the UI renders. Unknown shapes degrade to
+ * "unknown" type without crashing — better to show a tool with a fuzzy
+ * arg row than to drop it.
+ */
+export function argsFromJsonSchema(
+ schema: Record<string, unknown>,
+): ToolArgSummary[] {
+ const obj = schema as JsonSchemaObject;
+ if (!obj.properties) return [];
+ const required = new Set(obj.required ?? []);
+ return Object.entries(obj.properties).map(([name, prop]) => ({
+ name,
+ type: typeHint(prop),
+ description: prop.description ?? "",
+ required: required.has(name),
+ }));
+}
+
+function typeHint(prop: JsonSchemaProp): string {
+ if (Array.isArray(prop.enum) && prop.enum.length > 0) {
+ return `enum: ${prop.enum.map(String).join(" | ")}`;
+ }
+ if (prop.type === "array") {
+ return `array<${prop.items?.type ?? "any"}>`;
+ }
+ if (Array.isArray(prop.type)) return prop.type.join(" | ");
+ return prop.type ?? "unknown";
+}