Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ai): Mcp (#3260)

Eric Hayes55c7cd946505
diff --git a/.env-local.enc b/.env-local.enc
index faefc3b9b5..453a73696b 100644
--- a/.env-local.enc
+++ b/.env-local.enc
@@ -133,6 +133,8 @@ LIVEKIT_TRANSCRIPTION_AGENT_NAME=ENC[AES256_GCM,data:RgXJ+WNruFiyg1Pjjzo++SDOLg=
INTERNAL_CALL_SECRET=ENC[AES256_GCM,data:66UR3BO7Ddg5bQ0xmLNeY5EGb65L4tiXcsDNpTE=,iv:ovuMlw/k257Oh1CkosXjOXDWycQ4AoA9s+hhfHpeOvs=,tag:qXXYEFhSaM0Q4ffRdGtMRg==,type:str]
URL_SIGNING_HMAC=ENC[AES256_GCM,data:2PtDBCM6BARI7Fl5MSCVbOzGsXvgR8eFghJPfTvUFP31YRnFHpF5CBIsSlOhGUJihSoq6Ydfr9L4+LKv1EXT9g8S,iv:7ZmNUdsYr3ujUZiPVStz5ymrtYBfhsmDeyISzGX+1h0=,tag:snvxFxHfT7NyXpKF4Onu6A==,type:str]
NOTIFICATION_INGRESS_QUEUE=ENC[AES256_GCM,data:ZNMcAeqCNUOP9P763YB5kJgPRTKjIYLoamXheZKgeTtvHIfrtwYXIGjrd9PY/uWOR+RkrfevyRKTAlOEGeu95g==,iv:4Ag6GDV9B/g0feL1ayLau6fyA2j9udJt1AAIejy5Otw=,tag:3MgDj0sUU6kOv7H4NU1dmw==,type:str]
+MCP_CREDENTIALS_KEY_SECRET_NAME=ENC[AES256_GCM,data:xObDlP22th9DzVIFrIh7wQ==,iv:WsOMkvUgq2pUb14I4cdB8gJkTHC6GzFaTtv6lEa38LI=,tag:ILWcwyMF86J3gbciNsaTIg==,type:str]
+ tiYALFuCjFMiAkjOagyLnbOTY7AE=ENC[AES256_GCM,data:eA==,iv:cn7A0iY1f6PTAVGYg0D4EHH0XCUGvOp4F9sSBSqBEeU=,tag:7rJqoWRh2uBKvUuMsf9cEg==,type:str]
sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHBpdi1wMjU2IEUzMVUyZyBBM1lmcDc3\nUENpRVorSGVGa3R2NFlrdkx1Mm43aEcyR1ZtbEswL2RnWHlqMwpVMnY4ck5makNC\nZzVZc3JrZ3NKV2x3RTY0TFovRXJtVzEyeFZOZWRheHBNCi0tLSBobjhCbHpJa25s\nZDhyQjhCaEYrOWNiWHZkRWpnRlkwTnNEbjMwYzdxcTUwCqxxxmXy3mFUAbAy29y8\n2DFYDATdVvmplHpDTvgrNyY+lAL/3Jp9vtIs5DGXW/r73Nv3AhISmuCid18qhpAY\nUqE=\n-----END AGE ENCRYPTED FILE-----\n
sops_age__list_0__map_recipient=age1yubikey1qw64ag5lzvn9ekrflu5ruj4a6ucycscl6ctk39fjzf76jptsay39z442pxv
sops_kms__list_0__map_arn=arn:aws:kms:us-east-1:569036502058:key/mrk-cab29bf948044eb79005a81f48d40e93
@@ -143,7 +145,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480
sops_kms__list_1__map_aws_profile=
sops_kms__list_1__map_created_at=2026-03-03T19:32:07Z
sops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wFUqf7u/HEfCUGv7j69Mb6YAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMpcJQR1XeIAFFE7ebAgEQgDvYRYIWelwN8TuwA+6fZVaB34yKo9EQ5xPLr/3BU+ro1Mn2eBPCg3q8ie2LuE/3voim1X35P/cdtDqTZg==
-sops_lastmodified=2026-05-01T18:35:36Z
-sops_mac=ENC[AES256_GCM,data:pu7baim+ir8XHU52exmUSy6w0OAOs/lk2NiSz85b4koiliAywXbR6TyOUMUPPSo2N7/ahPM6P/5Frn71aUCXMXPNPbxvZr8J7cYb5zVYVgxolK6uBnYf6uITjjdS2lHp0HUTgfxRicoiZgCSNCn58aY6zpoyLPq7TuGY+EVOZV4=,iv:ShVorWC3nYBNe7Jlx7rxhPCj0Fc+KuNJZp7ON8z5BrA=,tag:zHO41aukfcdayiIJRgQCkg==,type:str]
+sops_lastmodified=2026-05-14T16:13:37Z
+sops_mac=ENC[AES256_GCM,data:INRPXmbrhoykBbSuf3X5Ukgxe1RGZ5ybGIXdvuOqsA2CWaYR/riWCLVVwkXOxJCUKzx1DKMoGEfsVmXJ5Jvf8fAAG67whQq6XKPN2MEd3QtQ10Ooxtjo4ITbnHApipStur3xi2fjPT3Ct9O2Trwr0ZvqSJnuO05OMEevUJDAZB4=,iv:uVUYmhlwLKt7UfUOL811GAA6KQmR+S6PF9Os4N7mYpM=,tag:cv3HSvm/zFfxHI4+dcv5lw==,type:str]
sops_unencrypted_suffix=_unencrypted
sops_version=3.12.2
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.ts
index df57441c83..8fd85edf9b 100644
--- a/infra/stacks/document-cognition-service/index.ts
+++ b/infra/stacks/document-cognition-service/index.ts
@@ -11,7 +11,10 @@ import {
stack,
} from '../../packages/shared';
import { get_coparse_api_vpc } from '../../packages/vpc';
-import { DocumentCognitionService } from './document-cognition-service';
+import {
+ DocumentCognitionService,
+ SERVICE_DOMAIN_NAME,
+} from './document-cognition-service';
const tags = {
environment: stack,
@@ -298,6 +301,10 @@ const documentCognitionService = new DocumentCognitionService(
name: 'DD_ENV',
value: stack,
},
+ {
+ name: 'DOCUMENT_COGNITION_SERVICE_URL',
+ value: `https://${SERVICE_DOMAIN_NAME}`,
+ },
],
isPrivate: false,
tags,
diff --git a/js/app/packages/app/component/settings/Agent.tsx b/js/app/packages/app/component/settings/Agent.tsx
new file mode 100644
index 0000000000..a8c1a5a88d
--- /dev/null
+++ b/js/app/packages/app/component/settings/Agent.tsx
@@ -0,0 +1,433 @@
+import { createSignal, For, Show, Suspense } from 'solid-js';
+import { Tabs } from '@core/component/Tabs';
+import { Button, Layer, Panel } from '@ui';
+import { McpSetupCards } from '@core/component/AI/component/McpSetupCards';
+import { toast } from '@core/component/Toast/Toast';
+import type { ServerResponse } from '@service-cognition/generated/schemas';
+import { ScopedPortal } from '@core/component/ScopedPortal';
+import {
+ useMcpServersQuery,
+ useAddMcpServerMutation,
+ useUpdateMcpServerMutation,
+ useDeleteMcpServerMutation,
+ useStartMcpAuthMutation,
+} from '@queries/mcp-servers';
+import {
+ agentSettingsSubTab,
+ setAgentSettingsSubTab,
+ type AgentSettingsSubTab,
+} from '@core/constant/SettingsState';
+import {
+ QUICK_CONNECT_SERVERS,
+ QUICK_CONNECT_ICON_MAP,
+ type SvgIcon,
+} from '@core/component/AI/constant/mcpServers';
+
+type McpTab = AgentSettingsSubTab;
+
+function AddServerForm(props: {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ existingUrls: Set<string>;
+}) {
+ const [name, setName] = createSignal('');
+ const [url, setUrl] = createSignal('');
+ const addMutation = useAddMcpServerMutation();
+ const authMutation = useStartMcpAuthMutation();
+
+ const reset = () => {
+ setName('');
+ setUrl('');
+ };
+
+ const startAuth = (serverName: string, serverUrl: string) => {
+ authMutation.mutate(
+ { server_name: serverName, server_url: serverUrl },
+ {
+ onSuccess: (result) => {
+ window.open(result.authorization_url, '_blank');
+ },
+ onError: () => {
+ toast.failure('Server added but failed to start authorization');
+ },
+ }
+ );
+ };
+
+ const handleSubmit = () => {
+ const n = name().trim();
+ const u = url().trim();
+ if (!n || !u) return;
+
+ addMutation.mutate(
+ { server_name: n, url: u },
+ {
+ onSuccess: () => {
+ startAuth(n, u);
+ reset();
+ props.onOpenChange(false);
+ },
+ onError: () => {
+ toast.failure('Failed to add server');
+ },
+ }
+ );
+ };
+
+ const handleQuickConnect = (server: { server_name: string; url: string }) => {
+ addMutation.mutate(
+ { server_name: server.server_name, url: server.url },
+ {
+ onSuccess: () => {
+ startAuth(server.server_name, server.url);
+ props.onOpenChange(false);
+ },
+ onError: () => {
+ toast.failure(`Failed to add ${server.server_name}`);
+ },
+ }
+ );
+ };
+
+ return (
+ <ScopedPortal scope="local" show={props.open}>
+ <Layer depth={3}>
+ <div class="absolute inset-0 z-10 flex items-center justify-center bg-overlay">
+ <div class="w-100 max-w-[calc(100%-2rem)]">
+ <Panel active depth={3} class="shadow-md">
+ <Panel.Header class="px-6">
+ <span class="text-ink text-sm font-semibold">Add MCP Server</span>
+ </Panel.Header>
+ <Panel.Body class="p-6 flex flex-col gap-5">
+ <div class="flex flex-col gap-2">
+ <span class="text-xs text-ink-muted">Quick Connect</span>
+ <div class="grid grid-cols-2 gap-2">
+ <For each={QUICK_CONNECT_SERVERS}>
+ {(server) => {
+ const added = () => props.existingUrls.has(server.url);
+ return (
+ <button
+ class="flex items-center justify-between px-3 py-2 rounded-sm border border-edge-muted text-sm transition-colors"
+ classList={{
+ 'bg-panel text-ink hover:bg-hover cursor-pointer': !added(),
+ 'bg-panel text-ink-muted cursor-default': added(),
+ }}
+ disabled={added() || addMutation.isPending}
+ onClick={() => handleQuickConnect(server)}
+ >
+ <span class="flex items-center gap-2 text-accent">
+ <server.icon class="size-4" />
+ <span class="text-ink">{server.server_name}</span>
+ </span>
+ <Show when={added()}>
+ <span class="text-xs text-ink-muted">Added</span>
+ </Show>
+ </button>
+ );
+ }}
+ </For>
+ </div>
+ </div>
+
+ <div class="flex flex-col gap-4">
+ <span class="text-xs text-ink-muted">Custom Server</span>
+ <label class="flex flex-col gap-1.5">
+ <span class="text-xs text-ink-muted">Name</span>
+ <input
+ type="text"
+ class="h-8 px-2.5 rounded-sm border border-edge-muted bg-input text-sm text-ink outline-none placeholder:text-ink-muted focus:border-edge"
+ placeholder="My MCP Server"
+ value={name()}
+ onInput={(e) => setName(e.currentTarget.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') handleSubmit();
+ if (e.key === 'Escape') { reset(); props.onOpenChange(false); }
+ }}
+ />
+ </label>
+ <label class="flex flex-col gap-1.5">
+ <span class="text-xs text-ink-muted">URL</span>
+ <input
+ type="url"
+ class="h-8 px-2.5 rounded-sm border border-edge-muted bg-input text-sm text-ink outline-none placeholder:text-ink-muted focus:border-edge"
+ placeholder="https://example.com/mcp"
+ value={url()}
+ onInput={(e) => setUrl(e.currentTarget.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') handleSubmit();
+ if (e.key === 'Escape') { reset(); props.onOpenChange(false); }
+ }}
+ />
+ </label>
+ </div>
+
+ <div class="flex justify-end gap-2 pt-1">
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ onClick={() => {
+ reset();
+ props.onOpenChange(false);
+ }}
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="active"
+ size="sm"
+ depth={3}
+ disabled={!name().trim() || !url().trim() || addMutation.isPending}
+ onClick={handleSubmit}
+ >
+ {addMutation.isPending ? 'Adding...' : 'Add'}
+ </Button>
+ </div>
+ </Panel.Body>
+ </Panel>
+ </div>
+ </div>
+ </Layer>
+ </ScopedPortal>
+ );
+}
+
+function ServerRow(props: { server: ServerResponse }) {
+ const updateMutation = useUpdateMcpServerMutation();
+ const deleteMutation = useDeleteMcpServerMutation();
+ const authMutation = useStartMcpAuthMutation();
+ const [confirmDelete, setConfirmDelete] = createSignal(false);
+
+ const handleToggleEnabled = () => {
+ updateMutation.mutate(
+ { url: props.server.url, enabled: !props.server.enabled },
+ {
+ onError: () => {
+ toast.failure('Failed to update server');
+ },
+ }
+ );
+ };
+
+ const handleDelete = () => {
+ deleteMutation.mutate(
+ { url: props.server.url },
+ {
+ onSuccess: () => {
+ toast.success('Server removed');
+ setConfirmDelete(false);
+ },
+ onError: () => {
+ toast.failure('Failed to remove server');
+ setConfirmDelete(false);
+ },
+ }
+ );
+ };
+
+ const handleAuth = () => {
+ authMutation.mutate(
+ {
+ server_url: props.server.url,
+ server_name: props.server.server_name,
+ },
+ {
+ onSuccess: (result) => {
+ window.open(result.authorization_url, '_blank');
+ },
+ onError: () => {
+ toast.failure('Failed to start authorization');
+ },
+ }
+ );
+ };
+
+ const Icon = () => QUICK_CONNECT_ICON_MAP.get(props.server.url);
+
+ return (
+ <div class="bg-panel flex items-center gap-4 px-6 py-3">
+ <Show when={Icon()}>
+ {(IconComp) => {
+ const C = IconComp() as SvgIcon;
+ return <C class="size-5 shrink-0 text-accent" />;
+ }}
+ </Show>
+ <div class="flex-1 min-w-0">
+ <div class="text-sm font-medium text-ink truncate">
+ {props.server.server_name}
+ </div>
+ <div class="text-xs text-muted truncate">{props.server.url}</div>
+ </div>
+
+ <div class="flex items-center gap-2 shrink-0">
+ <Show when={!props.server.authenticated}>
+ <Button
+ variant="active"
+ size="sm"
+ depth={3}
+ disabled={authMutation.isPending}
+ onClick={handleAuth}
+ >
+ {authMutation.isPending ? 'Connecting...' : 'Connect'}
+ </Button>
+ </Show>
+
+ <Show when={props.server.authenticated}>
+ <span class="text-xs text-green-500">Connected</span>
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ disabled={updateMutation.isPending}
+ onClick={handleToggleEnabled}
+ >
+ {props.server.enabled ? 'Disable' : 'Enable'}
+ </Button>
+ </Show>
+
+ <Show
+ when={!confirmDelete()}
+ fallback={
+ <div class="flex items-center gap-1">
+ <Button
+ variant="danger"
+ size="sm"
+ depth={3}
+ disabled={deleteMutation.isPending}
+ onClick={handleDelete}
+ >
+ {deleteMutation.isPending ? 'Removing...' : 'Confirm'}
+ </Button>
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ onClick={() => setConfirmDelete(false)}
+ >
+ Cancel
+ </Button>
+ </div>
+ }
+ >
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ onClick={() => setConfirmDelete(true)}
+ >
+ Remove
+ </Button>
+ </Show>
+ </div>
+ </div>
+ );
+}
+
+function Connectors() {
+ const serversQuery = useMcpServersQuery();
+ const [showAddDialog, setShowAddDialog] = createSignal(false);
+
+ return (
+ <div class="px-6 py-4 flex flex-col gap-4">
+ <div class="flex items-center justify-between">
+ <div class="text-sm">
+ Connect the Macro agent to external MCP servers
+ </div>
+ <Button
+ variant="active"
+ size="sm"
+ onClick={() => { setShowAddDialog(true) }}
+ >
+ Add Server
+ </Button>
+ </div>
+
+ <Show when={serversQuery.isLoading}>
+ <div class="text-sm text-ink-muted py-8 text-center">Loading...</div>
+ </Show>
+
+ <Show when={serversQuery.isError}>
+ <div class="text-sm text-red-500 py-8 text-center">
+ Failed to load servers.
+ <Button
+ variant="base"
+ size="sm"
+ depth={3}
+ onClick={() => serversQuery.refetch()}
+ class="ml-2"
+ >
+ Retry
+ </Button>
+ </div>
+ </Show>
+
+ <Show when={serversQuery.data}>
+ {(servers) => (
+ <Show
+ when={servers().length > 0}
+ fallback={
+ <div class="text-sm text-ink-muted py-8 text-center">
+ No MCP servers configured yet.
+ </div>
+ }
+ >
+ <div class="grid gap-px bg-edge-muted rounded-sm overflow-hidden border border-edge-muted">
+ <For each={servers()}>
+ {(server) => <ServerRow server={server} />}
+ </For>
+ </div>
+ </Show>
+ )}
+ </Show>
+
+ <AddServerForm
+ open={showAddDialog()}
+ onOpenChange={setShowAddDialog}
+ existingUrls={new Set(serversQuery.data?.map((s) => s.url) ?? [])}
+ />
+ </div>
+ );
+}
+
+function McpServer() {
+ return (
+ <div class="px-6">
+ <div class="text-sm py-4"> Connect agents to Macro </div>
+ <McpSetupCards class="max-w-none" />
+ </div>
+ );
+}
+
+export function Agent() {
+ const tabList = [
+ { value: 'connectors', label: 'Connectors' },
+ { value: 'mcp_server', label: 'MCP Server' },
+ ];
+
+ return (
+ <div class="h-full overflow-hidden flex justify-center p-2">
+ <div class="max-w-200 size-full">
+ <Panel depth={2} class="relative portal-scope">
+ <Panel.Header>
+ <Tabs
+ list={tabList}
+ value={agentSettingsSubTab()}
+ defaultValue="connectors"
+ onChange={(v) => setAgentSettingsSubTab(v as McpTab)}
+ />
+ </Panel.Header>
+ <Panel.Body scroll>
+ <Show when={agentSettingsSubTab() === 'connectors'}>
+ <Suspense fallback={<div class="text-sm text-ink-muted py-8 text-center">Loading...</div>}>
+ <Connectors />
+ </Suspense>
+ </Show>
+ <Show when={agentSettingsSubTab() === 'mcp_server'}>
+ <McpServer />
+ </Show>
+ </Panel.Body>
+ </Panel>
+ </div>
+ </div>
+ );
+}
diff --git a/js/app/packages/app/component/settings/Mcp.tsx b/js/app/packages/app/component/settings/Mcp.tsx
deleted file mode 100644
index 083e5038e8..0000000000
--- a/js/app/packages/app/component/settings/Mcp.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import { Panel } from '@ui';
-import { McpSetupCards } from '@core/component/AI/component/McpSetupCards';
-
-export function Mcp() {
- return (
- <div class="h-full overflow-hidden flex justify-center p-2">
- <div class="max-w-200 size-full">
- <Panel depth={2} class="h-full overflow-hidden text-ink">
- <Panel.Header class="px-6">
- <div class="text-sm font-semibold">MCP Setup</div>
- </Panel.Header>
-
- <Panel.Body scroll>
- <div class="px-6 py-4">
- <McpSetupCards class="max-w-none" />
- </div>
- </Panel.Body>
- </Panel>
- </div>
- </div>
- );
-}
diff --git a/js/app/packages/app/component/settings/Settings.tsx b/js/app/packages/app/component/settings/Settings.tsx
index 0038409958..6b47ff4350 100644
--- a/js/app/packages/app/component/settings/Settings.tsx
+++ b/js/app/packages/app/component/settings/Settings.tsx
@@ -5,7 +5,7 @@ import { isMobile } from '@core/mobile/isMobile';
import { DEV_MODE_ENV, ENABLE_APP_STORE_QR_CODE, ENABLE_TEAMS_OVERRIDE } from '@core/constant/featureFlags';
import { useFeatureFlag } from '@app/lib/analytics/posthog';
import { MobileApp } from './MobileApp';
-import { Mcp } from './Mcp';
+import { Agent } from './Agent';
import { Appearance } from './Appearance';
import { Tabs } from '@core/component/Tabs';
import { Account } from './Account';
@@ -63,7 +63,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
if (teamsFlag().enabled) { tabs.push({ value: 'Team', label: 'Team' }) }
tabs.push({ value: 'Shortcuts', label: 'Shortcuts' });
if (ENABLE_APP_STORE_QR_CODE && !isNativeMobilePlatform()) { tabs.push({ value: 'Mobile App', label: 'App' }) }
- if (!isNativeMobilePlatform()) { tabs.push({ value: 'MCP', label: 'MCP' }) }
+ if (!isNativeMobilePlatform()) { tabs.push({ value: 'Agent', label: 'Agent' }) }
if (isNativeMobilePlatform() && DEV_MODE_ENV) { tabs.push({ value: 'Mobile', label: 'Mobile Dev Tools' }) }
return tabs;
}
@@ -230,8 +230,8 @@ export function SettingsPanel(props: SettingsPanelProps) {
<Show when={activeTabId() === 'Mobile App' && ENABLE_APP_STORE_QR_CODE && !isNativeMobilePlatform()}>
<MobileApp />
</Show>
- <Show when={activeTabId() === 'MCP' && !isNativeMobilePlatform()}>
- <Mcp />
+ <Show when={activeTabId() === 'Agent' && !isNativeMobilePlatform()}>
+ <Agent />
</Show>
</div>
diff --git a/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx b/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
index cbebf992ac..f373c93e05 100644
--- a/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
+++ b/js/app/packages/core/component/AI/component/message/AssistantMessage.tsx
@@ -1,6 +1,7 @@
import { useSplitLayout } from '@app/component/split-layout/layout';
import { ChatMessageMarkdown } from '@core/component/AI/component/message/ChatMessageMarkdown';
import { RenderTool } from '@core/component/AI/component/tool/handler';
+import { McpToolCall } from '@core/component/AI/component/tool/McpToolCall';
import { useChatContext } from '@core/component/AI/context';
import { replaceCitations } from '@core/component/LexicalMarkdown/citationsUtils';
import { ENABLE_TTFT } from '@core/constant/featureFlags';
@@ -342,6 +343,28 @@ function AssistantMessageParts(props: {
);
})()}
</Match>
+ <Match when={type() === 'mcpToolCall'}>
+ {(() => {
+ const mcpCall = () =>
+ currentPart() as Extract<
+ AssistantMessagePart,
+ { type: 'mcpToolCall' }
+ >;
+ return (
+ <McpToolCall
+ name={mcpCall().name}
+ service={mcpCall().service}
+ display_name={mcpCall().display_name ?? undefined}
+ isComplete={isCompleteSelector(mcpCall().id)}
+ renderContext={{
+ renderContext: {
+ isStreaming: props.isStreaming,
+ },
+ }}
+ />
+ );
+ })()}
+ </Match>
<Match when={type() === 'text'}>
{(() => {
const text = () => {
diff --git a/js/app/packages/core/component/AI/component/message/EmptyChatState.tsx b/js/app/packages/core/component/AI/component/message/EmptyChatState.tsx
index 9977d5479b..1c0e9fb3fc 100644
--- a/js/app/packages/core/component/AI/component/message/EmptyChatState.tsx
+++ b/js/app/packages/core/component/AI/component/message/EmptyChatState.tsx
@@ -1,10 +1,79 @@
+import {
+ type SettingsTab,
+ setAgentSettingsSubTab,
+ useSettingsState,
+} from '@core/constant/SettingsState';
+import ArrowRightIcon from '@phosphor-icons/core/assets/bold/arrow-right-bold.svg?component-solid';
+import AtIcon from '@phosphor-icons/core/assets/bold/at-bold.svg?component-solid';
+import PlugsConnectedIcon from '@phosphor-icons/core/assets/bold/plugs-connected-bold.svg?component-solid';
+import PuzzlePieceIcon from '@phosphor-icons/core/assets/bold/puzzle-piece-bold.svg?component-solid';
+import type { JSXElement } from 'solid-js';
+
+function EmptyStateCard(props: {
+ icon: JSXElement;
+ title: string;
+ description: string;
+ action?: { label: string; onClick: () => void };
+}) {
+ return (
+ <div class="flex gap-3 rounded-md border border-edge-muted bg-input/50 px-4 py-3">
+ <div class="mt-0.5 text-accent shrink-0">{props.icon}</div>
+ <div class="flex flex-col gap-1 min-w-0">
+ <span class="text-sm font-medium text-ink">{props.title}</span>
+ <span class="text-xs text-ink-muted leading-relaxed">
+ {props.description}
+ </span>
+ {props.action && (
+ <button
+ class="mt-1 flex items-center gap-1 text-xs text-accent hover:text-accent/80 transition-colors cursor-pointer w-fit"
+ onClick={props.action.onClick}
+ >
+ {props.action.label}
+ <ArrowRightIcon class="size-3" />
+ </button>
+ )}
+ </div>
+ </div>
+ );
+}
+
export function EmptyChatState(props: { minHeight: number }) {
+ const { openSettings } = useSettingsState();
+
+ const openConnectors = () => {
+ setAgentSettingsSubTab('connectors');
+ openSettings('Agent' as SettingsTab);
+ };
+
+ const openMcpServer = () => {
+ setAgentSettingsSubTab('mcp_server');
+ openSettings('Agent' as SettingsTab);
+ };
+
return (
<div
- class="w-full"
- style={{
- 'min-height': `${props.minHeight}px`,
- }}
- />
+ class="w-full flex items-center justify-center"
+ style={{ 'min-height': `${props.minHeight}px` }}
+ >
+ <div class="flex flex-col gap-3 w-full max-w-md px-4">
+ <EmptyStateCard
+ icon={<AtIcon class="size-4" />}
+ title="@mention anything"
+ description="Type @ in the chat input to attach files, documents, emails, and more as context for the AI."
+ />
+ <EmptyStateCard
+ icon={<PlugsConnectedIcon class="size-4" />}
+ title="Connect MCP servers"
+ description="Give the agent access to external tools like Linear, PostHog, Datadog, and more."
+ action={{ label: 'Add connectors', onClick: openConnectors }}
+ />
+ <EmptyStateCard
+ icon={<PuzzlePieceIcon class="size-4" />}
+ title="Connect your own agents"
+ description="Use Macro as a tool from Claude Code, Cursor, or any MCP-compatible client."
+ action={{ label: 'Set up MCP server', onClick: openMcpServer }}
+ />
+ </div>
+ </div>
);
}
diff --git a/js/app/packages/core/component/AI/component/tool/McpToolCall.tsx b/js/app/packages/core/component/AI/component/tool/McpToolCall.tsx
new file mode 100644
index 0000000000..68e9adaff7
--- /dev/null
+++ b/js/app/packages/core/component/AI/component/tool/McpToolCall.tsx
@@ -0,0 +1,29 @@
+import Plug from '@phosphor-icons/core/regular/plug.svg';
+import { getMcpServerIcon, type SvgIcon } from '../../constant/mcpServers';
+import { BaseTool } from './BaseTool';
+import type { RenderContext } from './ToolRenderer';
+
+export function McpToolCall(props: {
+ name: string;
+ service: string;
+ display_name?: string;
+ isComplete: boolean;
+ renderContext: RenderContext;
+}) {
+ const Icon = (): SvgIcon =>
+ getMcpServerIcon(props.service) ?? (Plug as SvgIcon);
+
+ return (
+ <BaseTool
+ icon={Icon()}
+ renderContext={props.renderContext.renderContext}
+ type="call"
+ >
+ <div class="flex min-w-0 flex-1 items-center gap-2">
+ <span class="text-ink-muted">{props.service}</span>
+ <span class="text-ink-extra-muted">/</span>
+ <span>{props.display_name ?? props.name}</span>
+ </div>
+ </BaseTool>
+ );
+}
diff --git a/js/app/packages/core/component/AI/constant/mcpServers.ts b/js/app/packages/core/component/AI/constant/mcpServers.ts
new file mode 100644
index 0000000000..d097bda8d6
--- /dev/null
+++ b/js/app/packages/core/component/AI/constant/mcpServers.ts
@@ -0,0 +1,42 @@
+import IconDatadog from '@macro-icons/mcp-datadog.svg';
+import IconGrafana from '@macro-icons/mcp-grafana.svg';
+import IconLinear from '@macro-icons/mcp-linear.svg';
+import IconPostHog from '@macro-icons/mcp-posthog.svg';
+import type { Component, JSX } from 'solid-js';
+
+export type SvgIcon = Component<JSX.SvgSVGAttributes<SVGSVGElement>>;
+
+export const QUICK_CONNECT_SERVERS = [
+ {
+ server_name: 'Linear',
+ url: 'https://mcp.linear.app/mcp',
+ icon: IconLinear as SvgIcon,
+ },
+ {
+ server_name: 'PostHog',
+ url: 'https://mcp.posthog.com/mcp',
+ icon: IconPostHog as SvgIcon,
+ },
+ {
+ server_name: 'Datadog',
+ url: 'https://mcp.datadoghq.com/mcp',
+ icon: IconDatadog as SvgIcon,
+ },
+ {
+ server_name: 'Grafana',
+ url: 'https://mcp.grafana.com/mcp',
+ icon: IconGrafana as SvgIcon,
+ },
+] as const;
+
+export const QUICK_CONNECT_ICON_MAP: Map<string, SvgIcon> = new Map(
+ QUICK_CONNECT_SERVERS.map((s) => [s.url, s.icon])
+);
+
+const SERVER_NAME_ICON_MAP: Map<string, SvgIcon> = new Map(
+ QUICK_CONNECT_SERVERS.map((s) => [s.server_name.toLowerCase(), s.icon])
+);
+
+export function getMcpServerIcon(serverName: string): SvgIcon | undefined {
+ return SERVER_NAME_ICON_MAP.get(serverName.toLowerCase());
+}
diff --git a/js/app/packages/core/constant/SettingsState.tsx b/js/app/packages/core/constant/SettingsState.tsx
index e9b7b21b83..6ba95c74de 100644
--- a/js/app/packages/core/constant/SettingsState.tsx
+++ b/js/app/packages/core/constant/SettingsState.tsx
@@ -12,12 +12,16 @@ export type SettingsTab =
| 'Inbox'
| 'Shortcuts'
| 'Mobile App'
- | 'MCP'
+ | 'Agent'
| 'Team';
export const [activeTabId, setActiveTabId] =
createSignal<SettingsTab>('Appearance');
+export type AgentSettingsSubTab = 'connectors' | 'mcp_server';
+export const [agentSettingsSubTab, setAgentSettingsSubTab] =
+ createSignal<AgentSettingsSubTab>('connectors');
+
export const useSettingsState = () => {
const { insertSplit } = useSplitLayout();
diff --git a/js/app/packages/core/util/maybeResult.ts b/js/app/packages/core/util/maybeResult.ts
index e8edf4473a..52abe9a700 100644
--- a/js/app/packages/core/util/maybeResult.ts
+++ b/js/app/packages/core/util/maybeResult.ts
@@ -324,14 +324,20 @@ export class MaybeResultError<E extends string = string> extends Error {
* Wraps a MaybeResult-returning async function to throw on error.
* Useful for tanstack-query and other APIs that expect thrown errors.
*/
+export async function throwOnErr<E extends string>(
+ fn: () => Promise<MaybeError<E>>
+): Promise<void>;
export async function throwOnErr<E extends string, T>(
fn: () => Promise<MaybeResult<E, T>>
-): Promise<T> {
+): Promise<T>;
+export async function throwOnErr<E extends string, T>(
+ fn: () => Promise<MaybeError<E> | MaybeResult<E, T>>
+): Promise<T | void> {
const result = await fn();
if (isErr(result)) {
throw new MaybeResultError(result[0]);
}
- return result[1];
+ if (result.length > 1) return (result as [null, T])[1];
}
/**
diff --git a/js/app/packages/macro-icons/mcp-datadog.svg b/js/app/packages/macro-icons/mcp-datadog.svg
new file mode 100644
index 0000000000..de6f98c677
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-datadog.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Datadog</title><path d="M19.57 17.04l-1.997-1.316-1.665 2.782-1.937-.567-1.706 2.604.087.82 9.274-1.71-.538-5.794zm-8.649-2.498l1.488-.204c.241.108.409.15.697.223.45.117.97.23 1.741-.16.18-.088.553-.43.704-.625l6.096-1.106.622 7.527-10.444 1.882zm11.325-2.712l-.602.115L20.488 0 .789 2.285l2.427 19.693 2.306-.334c-.184-.263-.471-.581-.96-.989-.68-.564-.44-1.522-.039-2.127.53-1.022 3.26-2.322 3.106-3.956-.056-.594-.15-1.368-.702-1.898-.02.22.017.432.017.432s-.227-.289-.34-.683c-.112-.15-.2-.199-.319-.4-.085.233-.073.503-.073.503s-.186-.437-.216-.807c-.11.166-.137.48-.137.48s-.241-.69-.186-1.062c-.11-.323-.436-.965-.343-2.424.6.421 1.924.321 2.44-.439.171-.251.288-.939-.086-2.293-.24-.868-.835-2.16-1.066-2.651l-.028.02c.122.395.374 1.223.47 1.625.293 1.218.372 1.642.234 2.204-.116.488-.397.808-1.107 1.165-.71.358-1.653-.514-1.713-.562-.69-.55-1.224-1.447-1.284-1.883-.062-.477.275-.763.445-1.153-.243.07-.514.192-.514.192s.323-.334.722-.624c.165-.109.262-.178.436-.323a9.762 9.762 0 0 0-.456.003s.42-.227.855-.392c-.318-.014-.623-.003-.623-.003s.937-.419 1.678-.727c.509-.208 1.006-.147 1.286.257.367.53.752.817 1.569.996.501-.223.653-.337 1.284-.509.554-.61.99-.688.99-.688s-.216.198-.274.51c.314-.249.66-.455.66-.455s-.134.164-.259.426l.03.043c.366-.22.797-.394.797-.394s-.123.156-.268.358c.277-.002.838.012 1.056.037 1.285.028 1.552-1.374 2.045-1.55.618-.22.894-.353 1.947.68.903.888 1.609 2.477 1.259 2.833-.294.295-.874-.115-1.516-.916a3.466 3.466 0 0 1-.716-1.562 1.533 1.533 0 0 0-.497-.85s.23.51.23.96c0 .246.03 1.165.424 1.68-.039.076-.057.374-.1.43-.458-.554-1.443-.95-1.604-1.067.544.445 1.793 1.468 2.273 2.449.453.927.186 1.777.416 1.997.065.063.976 1.197 1.15 1.767.306.994.019 2.038-.381 2.685l-1.117.174c-.163-.045-.273-.068-.42-.153.08-.143.241-.5.243-.572l-.063-.111c-.348.492-.93.97-1.414 1.245-.633.359-1.363.304-1.838.156-1.348-.415-2.623-1.327-2.93-1.566 0 0-.01.191.048.234.34.383 1.119 1.077 1.872 1.56l-1.605.177.759 5.908c-.337.048-.39.071-.757.124-.325-1.147-.946-1.895-1.624-2.332-.599-.384-1.424-.47-2.214-.314l-.05.059a2.851 2.851 0 0 1 1.863.444c.654.413 1.181 1.481 1.375 2.124.248.822.42 1.7-.248 2.632-.476.662-1.864 1.028-2.986.237.3.481.705.876 1.25.95.809.11 1.577-.03 2.106-.574.452-.464.69-1.434.628-2.456l.714-.104.258 1.834 11.827-1.424zM15.05 6.848c-.034.075-.085.125-.007.37l.004.014.013.032.032.073c.14.287.295.558.552.696.067-.011.136-.019.207-.023.242-.01.395.028.492.08.009-.048.01-.119.005-.222-.018-.364.072-.982-.626-1.308-.264-.122-.634-.084-.757.068a.302.302 0 0 1 .058.013c.186.066.06.13.027.207m1.958 3.392c-.092-.05-.52-.03-.821.005-.574.068-1.193.267-1.328.372-.247.191-.135.523.047.66.511.382.96.638 1.432.575.29-.038.546-.497.728-.914.124-.288.124-.598-.058-.698m-5.077-2.942c.162-.154-.805-.355-1.556.156-.554.378-.571 1.187-.041 1.646.053.046.096.078.137.104a4.77 4.77 0 0 1 1.396-.412c.113-.125.243-.345.21-.745-.044-.542-.455-.456-.146-.749"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-github.svg b/js/app/packages/macro-icons/mcp-github.svg
new file mode 100644
index 0000000000..2786dfa389
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-github.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-gmail.svg b/js/app/packages/macro-icons/mcp-gmail.svg
new file mode 100644
index 0000000000..fa75c64f54
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-gmail.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Gmail</title><path d="M24 5.457v13.909c0 .904-.732 1.636-1.636 1.636h-3.819V11.73L12 16.64l-6.545-4.91v9.273H1.636A1.636 1.636 0 0 1 0 19.366V5.457c0-2.023 2.309-3.178 3.927-1.964L5.455 4.64 12 9.548l6.545-4.91 1.528-1.145C21.69 2.28 24 3.434 24 5.457z"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-grafana.svg b/js/app/packages/macro-icons/mcp-grafana.svg
new file mode 100644
index 0000000000..56eb0fe224
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-grafana.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Grafana</title><path d="M23.02 10.59a8.578 8.578 0 0 0-.862-3.034 8.911 8.911 0 0 0-1.789-2.445c.337-1.342-.413-2.505-.413-2.505-1.292-.08-2.113.4-2.416.62-.052-.02-.102-.044-.154-.064-.22-.089-.446-.172-.677-.247-.231-.073-.47-.14-.711-.197a9.867 9.867 0 0 0-.875-.161C14.557.753 12.94 0 12.94 0c-1.804 1.145-2.147 2.744-2.147 2.744l-.018.093c-.098.029-.2.057-.298.088-.138.042-.275.094-.413.143-.138.055-.275.107-.41.166a8.869 8.869 0 0 0-1.557.87l-.063-.029c-2.497-.955-4.716.195-4.716.195-.203 2.658.996 4.33 1.235 4.636a11.608 11.608 0 0 0-.607 2.635C1.636 12.677.953 15.014.953 15.014c1.926 2.214 4.171 2.351 4.171 2.351.003-.002.006-.002.006-.005.285.509.615.994.986 1.446.156.19.32.371.488.548-.704 2.009.099 3.68.099 3.68 2.144.08 3.553-.937 3.849-1.173a9.784 9.784 0 0 0 3.164.501h.08l.055-.003.107-.002.103-.005.003.002c1.01 1.44 2.788 1.646 2.788 1.646 1.264-1.332 1.337-2.653 1.337-2.94v-.058c0-.02-.003-.039-.003-.06.265-.187.52-.387.758-.6a7.875 7.875 0 0 0 1.415-1.7c1.43.083 2.437-.885 2.437-.885-.236-1.49-1.085-2.216-1.264-2.354l-.018-.013-.016-.013a.217.217 0 0 1-.031-.02c.008-.092.016-.18.02-.27.011-.162.016-.323.016-.48v-.253l-.005-.098-.008-.135a1.891 1.891 0 0 0-.01-.13c-.003-.042-.008-.083-.013-.125l-.016-.124-.018-.122a6.215 6.215 0 0 0-2.032-3.73 6.015 6.015 0 0 0-3.222-1.46 6.292 6.292 0 0 0-.85-.048l-.107.002h-.063l-.044.003-.104.008a4.777 4.777 0 0 0-3.335 1.695c-.332.4-.592.84-.768 1.297a4.594 4.594 0 0 0-.312 1.817l.003.091c.005.055.007.11.013.164a3.615 3.615 0 0 0 .698 1.82 3.53 3.53 0 0 0 1.827 1.282c.33.098.66.14.971.137.039 0 .078 0 .114-.002l.063-.003c.02 0 .041-.003.062-.003.034-.002.065-.007.099-.01.007 0 .018-.003.028-.003l.031-.005.06-.008a1.18 1.18 0 0 0 .112-.02c.036-.008.072-.013.109-.024a2.634 2.634 0 0 0 .914-.415c.028-.02.056-.041.085-.065a.248.248 0 0 0 .039-.35.244.244 0 0 0-.309-.06l-.078.042c-.09.044-.184.083-.283.116a2.476 2.476 0 0 1-.475.096c-.028.003-.054.006-.083.006l-.083.002c-.026 0-.054 0-.08-.002l-.102-.006h-.012l-.024.006c-.016-.003-.031-.003-.044-.006-.031-.002-.06-.007-.091-.01a2.59 2.59 0 0 1-.724-.213 2.557 2.557 0 0 1-.667-.438 2.52 2.52 0 0 1-.805-1.475 2.306 2.306 0 0 1-.029-.444l.006-.122v-.023l.002-.031c.003-.021.003-.04.005-.06a3.163 3.163 0 0 1 1.352-2.29 3.12 3.12 0 0 1 .937-.43 2.946 2.946 0 0 1 .776-.101h.06l.07.002.045.003h.026l.07.005a4.041 4.041 0 0 1 1.635.49 3.94 3.94 0 0 1 1.602 1.662 3.77 3.77 0 0 1 .397 1.414l.005.076.003.075c.002.026.002.05.002.075 0 .024.003.052 0 .07v.065l-.002.073-.008.174a6.195 6.195 0 0 1-.08.639 5.1 5.1 0 0 1-.267.927 5.31 5.31 0 0 1-.624 1.13 5.052 5.052 0 0 1-3.237 2.014 4.82 4.82 0 0 1-.649.066l-.039.003h-.287a6.607 6.607 0 0 1-1.716-.265 6.776 6.776 0 0 1-3.4-2.274 6.75 6.75 0 0 1-.746-1.15 6.616 6.616 0 0 1-.714-2.596l-.005-.083-.002-.02v-.056l-.003-.073v-.096l-.003-.104v-.07l.003-.163c.008-.22.026-.45.054-.678a8.707 8.707 0 0 1 .28-1.355c.128-.444.286-.872.473-1.277a7.04 7.04 0 0 1 1.456-2.1 5.925 5.925 0 0 1 .953-.763c.169-.111.343-.213.524-.306.089-.05.182-.091.273-.135.047-.02.093-.042.138-.062a7.177 7.177 0 0 1 .714-.267l.145-.045c.049-.015.098-.026.148-.041.098-.029.197-.052.296-.076.049-.013.1-.02.15-.033l.15-.032.151-.028.076-.013.075-.01.153-.024c.057-.01.114-.013.171-.023l.169-.021c.036-.003.073-.008.106-.01l.073-.008.036-.003.042-.002c.057-.003.114-.008.171-.01l.086-.006h.023l.037-.003.145-.007a7.999 7.999 0 0 1 1.708.125 7.917 7.917 0 0 1 2.048.68 8.253 8.253 0 0 1 1.672 1.09l.09.077.089.078c.06.052.114.107.171.159.057.052.112.106.166.16.052.055.107.107.159.164a8.671 8.671 0 0 1 1.41 1.978c.012.026.028.052.04.078l.04.078.075.156c.023.051.05.1.07.153l.065.15a8.848 8.848 0 0 1 .45 1.34.19.19 0 0 0 .201.142.186.186 0 0 0 .172-.184c.01-.246.002-.532-.024-.856z"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-linear.svg b/js/app/packages/macro-icons/mcp-linear.svg
new file mode 100644
index 0000000000..39bf6f8500
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-linear.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Linear</title><path d="M2.886 4.18A11.982 11.982 0 0 1 11.99 0C18.624 0 24 5.376 24 12.009c0 3.64-1.62 6.903-4.18 9.105L2.887 4.18ZM1.817 5.626l16.556 16.556c-.524.33-1.075.62-1.65.866L.951 7.277c.247-.575.537-1.126.866-1.65ZM.322 9.163l14.515 14.515c-.71.172-1.443.282-2.195.322L0 11.358a12 12 0 0 1 .322-2.195Zm-.17 4.862 9.823 9.824a12.02 12.02 0 0 1-9.824-9.824Z"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-notion.svg b/js/app/packages/macro-icons/mcp-notion.svg
new file mode 100644
index 0000000000..9dde8558af
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-notion.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Notion</title><path d="M4.459 4.208c.746.606 1.026.56 2.428.466l13.215-.793c.28 0 .047-.28-.046-.326L17.86 1.968c-.42-.326-.981-.7-2.055-.607L3.01 2.295c-.466.046-.56.28-.374.466zm.793 3.08v13.904c0 .747.373 1.027 1.214.98l14.523-.84c.841-.046.935-.56.935-1.167V6.354c0-.606-.233-.933-.748-.887l-15.177.887c-.56.047-.747.327-.747.933zm14.337.745c.093.42 0 .84-.42.888l-.7.14v10.264c-.608.327-1.168.514-1.635.514-.748 0-.935-.234-1.495-.933l-4.577-7.186v6.952L12.21 19s0 .84-1.168.84l-3.222.186c-.093-.186 0-.653.327-.746l.84-.233V9.854L7.822 9.76c-.094-.42.14-1.026.793-1.073l3.456-.233 4.764 7.279v-6.44l-1.215-.139c-.093-.514.28-.887.747-.933zM1.936 1.035l13.31-.98c1.634-.14 2.055-.047 3.082.7l4.249 2.986c.7.513.934.653.934 1.213v16.378c0 1.026-.373 1.634-1.68 1.726l-15.458.934c-.98.047-1.448-.093-1.962-.747l-3.129-4.06c-.56-.747-.793-1.306-.793-1.96V2.667c0-.839.374-1.54 1.447-1.632z"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/macro-icons/mcp-posthog.svg b/js/app/packages/macro-icons/mcp-posthog.svg
new file mode 100644
index 0000000000..f69461b41e
--- /dev/null
+++ b/js/app/packages/macro-icons/mcp-posthog.svg
@@ -0,0 +1 @@
+<svg fill="currentColor" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>PostHog</title><path d="M9.854 14.5 5 9.647.854 5.5A.5.5 0 0 0 0 5.854V8.44a.5.5 0 0 0 .146.353L5 13.647l.147.146L9.854 18.5l.146.147v-.049c.065.03.134.049.207.049h2.586a.5.5 0 0 0 .353-.854L9.854 14.5zm0-5-4-4a.487.487 0 0 0-.409-.144.515.515 0 0 0-.356.21.493.493 0 0 0-.089.288V8.44a.5.5 0 0 0 .147.353l9 9a.5.5 0 0 0 .853-.354v-2.585a.5.5 0 0 0-.146-.354l-5-5zm1-4a.5.5 0 0 0-.854.354V8.44a.5.5 0 0 0 .147.353l4 4a.5.5 0 0 0 .853-.354V9.854a.5.5 0 0 0-.146-.354l-4-4zm12.647 11.515a3.863 3.863 0 0 1-2.232-1.1l-4.708-4.707a.5.5 0 0 0-.854.354v6.585a.5.5 0 0 0 .5.5H23.5a.5.5 0 0 0 .5-.5v-.6c0-.276-.225-.497-.499-.532zm-5.394.032a.8.8 0 1 1 0-1.6.8.8 0 0 1 0 1.6zM.854 15.5a.5.5 0 0 0-.854.354v2.293a.5.5 0 0 0 .5.5h2.293c.222 0 .39-.135.462-.309a.493.493 0 0 0-.109-.545L.854 15.501zM5 14.647.854 10.5a.5.5 0 0 0-.854.353v2.586a.5.5 0 0 0 .146.353L4.854 18.5l.146.147h2.793a.5.5 0 0 0 .353-.854L5 14.647z"/></svg>
\ No newline at end of file
diff --git a/js/app/packages/queries/mcp-servers.ts b/js/app/packages/queries/mcp-servers.ts
new file mode 100644
index 0000000000..b7878b5c75
--- /dev/null
+++ b/js/app/packages/queries/mcp-servers.ts
@@ -0,0 +1,99 @@
+import { throwOnErr } from '@core/util/maybeResult';
+import { queryClient } from '@queries/client';
+import { cognitionApiServiceClient } from '@service-cognition/client';
+import type {
+ AddServerRequest,
+ ServerResponse,
+ StartAuthRequest,
+ UpdateServerRequest,
+} from '@service-cognition/generated/schemas';
+import { useMutation, useQuery } from '@tanstack/solid-query';
+
+const KEYS = {
+ all: ['mcpServers'] as const,
+ list: ['mcpServers', 'list'] as const,
+};
+
+export function useMcpServersQuery() {
+ return useQuery(() => ({
+ queryKey: KEYS.list,
+ queryFn: async () =>
+ throwOnErr(async () => await cognitionApiServiceClient.listMcpServers()),
+ refetchOnMount: 'always' as const,
+ refetchOnWindowFocus: 'always' as const,
+ }));
+}
+
+export function invalidateMcpServers() {
+ return queryClient.invalidateQueries({ queryKey: KEYS.list });
+}
+
+function upsertServer(server: ServerResponse) {
+ queryClient.setQueryData(
+ KEYS.list,
+ (current: ServerResponse[] | undefined) => {
+ if (!current) return [server];
+ const index = current.findIndex((s) => s.url === server.url);
+ if (index === -1) return [...current, server];
+ const next = [...current];
+ next[index] = server;
+ return next;
+ }
+ );
+}
+
+function removeServer(url: string) {
+ queryClient.setQueryData(
+ KEYS.list,
+ (current: ServerResponse[] | undefined) =>
+ current?.filter((s) => s.url !== url) ?? current
+ );
+}
+
+export function useAddMcpServerMutation() {
+ return useMutation(() => ({
+ mutationFn: async (request: AddServerRequest) =>
+ throwOnErr(
+ async () => await cognitionApiServiceClient.addMcpServer(request)
+ ),
+ onSuccess: async (server: ServerResponse) => {
+ upsertServer(server);
+ await invalidateMcpServers();
+ },
+ }));
+}
+
+export function useUpdateMcpServerMutation() {
+ return useMutation(() => ({
+ mutationFn: async (request: UpdateServerRequest) =>
+ throwOnErr(
+ async () => await cognitionApiServiceClient.updateMcpServer(request)
+ ),
+ onSuccess: async (server: ServerResponse) => {
+ upsertServer(server);
+ await invalidateMcpServers();
+ },
+ }));
+}
+
+export function useDeleteMcpServerMutation() {
+ return useMutation(() => ({
+ mutationFn: async (args: { url: string }) =>
+ throwOnErr(
+ async () => await cognitionApiServiceClient.deleteMcpServer(args)
+ ),
+ onSuccess: async (_result: unknown, variables: { url: string }) => {
+ removeServer(variables.url);
+ await invalidateMcpServers();
+ },
+ }));
+}
+
+export function useStartMcpAuthMutation() {
+ return useMutation(() => ({
+ mutationFn: async (request: StartAuthRequest) =>
+ throwOnErr(
+ async () => await cognitionApiServiceClient.startMcpAuth(request)
+ ),
+ }));
+}
diff --git a/js/app/packages/service-clients/service-cognition/client.ts b/js/app/packages/service-clients/service-cognition/client.ts
index d007e17af6..2cbafc0ddf 100644
--- a/js/app/packages/service-clients/service-cognition/client.ts
+++ b/js/app/packages/service-clients/service-cognition/client.ts
@@ -18,6 +18,7 @@ import { platformFetch } from '@core/util/platformFetch';
import type { SafeFetchInit } from '@core/util/safeFetch';
import type { DocumentTextPart } from '@service-cognition/generated/schemas/documentTextPart';
import type OpenAI from 'openai';
+import type { AddServerRequest } from './generated/schemas/addServerRequest';
import type { CreateChatRequest } from './generated/schemas/createChatRequest';
import type { GetBatchPreviewRequest } from './generated/schemas/getBatchPreviewRequest';
import type { GetBatchPreviewResponse } from './generated/schemas/getBatchPreviewResponse';
@@ -27,9 +28,13 @@ import type { GetChatsForAttachmentResponse } from './generated/schemas/getChats
import type { HttpSendChatMessageRequest } from './generated/schemas/httpSendChatMessageRequest';
import type { PatchChatRequest } from './generated/schemas/patchChatRequest';
import type { SendChatMessageResponse } from './generated/schemas/sendChatMessageResponse';
+import type { ServerResponse } from './generated/schemas/serverResponse';
+import type { StartAuthRequest } from './generated/schemas/startAuthRequest';
+import type { StartAuthResponse } from './generated/schemas/startAuthResponse';
import type { StopChatStreamRequest } from './generated/schemas/stopChatStreamRequest';
import type { StopChatStreamResponse } from './generated/schemas/stopChatStreamResponse';
import type { StringIDResponse } from './generated/schemas/stringIDResponse';
+import type { UpdateServerRequest } from './generated/schemas/updateServerRequest';
import type * as toolTypes from './generated/tools/tool.ts';
type ToolCallArgs = {
@@ -328,6 +333,49 @@ export const cognitionApiServiceClient = {
(result) => result
);
},
+
+ async listMcpServers() {
+ return mapOk(
+ await dcsFetch<ServerResponse[]>(`/mcp/servers`, { method: 'GET' }),
+ (result) => result
+ );
+ },
+
+ async addMcpServer(args: AddServerRequest) {
+ return mapOk(
+ await dcsFetch<ServerResponse>(`/mcp/servers`, {
+ method: 'POST',
+ body: JSON.stringify(args),
+ }),
+ (result) => result
+ );
+ },
+
+ async updateMcpServer(args: UpdateServerRequest) {
+ return mapOk(
+ await dcsFetch<ServerResponse>(`/mcp/servers`, {
+ method: 'PUT',
+ body: JSON.stringify(args),
+ }),
+ (result) => result
+ );
+ },
+
+ async deleteMcpServer(args: { url: string }) {
+ return await dcsFetch(`/mcp/servers?url=${encodeURIComponent(args.url)}`, {
+ method: 'DELETE',
+ });
+ },
+
+ async startMcpAuth(args: StartAuthRequest) {
+ return mapOk(
+ await dcsFetch<StartAuthResponse>(`/mcp/servers/auth/start`, {
+ method: 'POST',
+ body: JSON.stringify(args),
+ }),
+ (result) => result
+ );
+ },
};
export async function generateTitle(text: string): Promise<string | undefined> {
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePart.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePart.ts
index 1a302b037f..c510f7a52b 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePart.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePart.ts
@@ -5,12 +5,14 @@
* OpenAPI spec version: 1.0.0
*/
import type { AssistantMessagePartOneOf } from './assistantMessagePartOneOf';
+import type { AssistantMessagePartOneOfEight } from './assistantMessagePartOneOfEight';
import type { AssistantMessagePartOneOfFive } from './assistantMessagePartOneOfFive';
-import type { AssistantMessagePartOneOfSeven } from './assistantMessagePartOneOfSeven';
+import type { AssistantMessagePartOneOfOnezero } from './assistantMessagePartOneOfOnezero';
import type { AssistantMessagePartOneOfThree } from './assistantMessagePartOneOfThree';
export type AssistantMessagePart =
| AssistantMessagePartOneOf
| AssistantMessagePartOneOfThree
| AssistantMessagePartOneOfFive
- | AssistantMessagePartOneOfSeven;
+ | AssistantMessagePartOneOfEight
+ | AssistantMessagePartOneOfOnezero;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEight.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEight.ts
new file mode 100644
index 0000000000..914e1bf7f2
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEight.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+import type { AssistantMessagePartOneOfEightType } from './assistantMessagePartOneOfEightType';
+
+export type AssistantMessagePartOneOfEight = {
+ id: string;
+ json: unknown;
+ name: string;
+ type: AssistantMessagePartOneOfEightType;
+};
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEightType.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEightType.ts
new file mode 100644
index 0000000000..697d21747f
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfEightType.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+
+export type AssistantMessagePartOneOfEightType =
+ (typeof AssistantMessagePartOneOfEightType)[keyof typeof AssistantMessagePartOneOfEightType];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const AssistantMessagePartOneOfEightType = {
+ toolCallResponseJson: 'toolCallResponseJson',
+} as const;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFive.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFive.ts
index 429c3bd68e..1cd4acd0b3 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFive.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFive.ts
@@ -4,11 +4,17 @@
* Document Cognition Service
* OpenAPI spec version: 1.0.0
*/
+import type { AssistantMessagePartOneOfFiveDisplayName } from './assistantMessagePartOneOfFiveDisplayName';
import type { AssistantMessagePartOneOfFiveType } from './assistantMessagePartOneOfFiveType';
export type AssistantMessagePartOneOfFive = {
+ /** Human-readable title from the MCP server, if provided */
+ display_name?: AssistantMessagePartOneOfFiveDisplayName;
id: string;
json: unknown;
+ /** Demangled tool name from the MCP server */
name: string;
+ /** MCP server name */
+ service: string;
type: AssistantMessagePartOneOfFiveType;
};
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveDisplayName.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveDisplayName.ts
new file mode 100644
index 0000000000..1d15ac9549
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveDisplayName.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+
+/**
+ * Human-readable title from the MCP server, if provided
+ */
+export type AssistantMessagePartOneOfFiveDisplayName = string | null;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveType.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveType.ts
index f52f659993..3804b10fad 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveType.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfFiveType.ts
@@ -10,5 +10,5 @@ export type AssistantMessagePartOneOfFiveType =
// eslint-disable-next-line @typescript-eslint/no-redeclare
export const AssistantMessagePartOneOfFiveType = {
- toolCallResponseJson: 'toolCallResponseJson',
+ mcpToolCall: 'mcpToolCall',
} as const;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezero.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezero.ts
new file mode 100644
index 0000000000..6ac731fe41
--- /dev/null
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezero.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * Document Cognition Service
+ * OpenAPI spec version: 1.0.0
+ */
+import type { AssistantMessagePartOneOfOnezeroType } from './assistantMessagePartOneOfOnezeroType';
+
+export type AssistantMessagePartOneOfOnezero = {
+ description: string;
+ id: string;
+ name: string;
+ type: AssistantMessagePartOneOfOnezeroType;
+};
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSevenType.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezeroType.ts
similarity index 53%
rename from js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSevenType.ts
rename to js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezeroType.ts
index cfa2b8e025..337261a7a1 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSevenType.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfOnezeroType.ts
@@ -5,10 +5,10 @@
* OpenAPI spec version: 1.0.0
*/
-export type AssistantMessagePartOneOfSevenType =
- (typeof AssistantMessagePartOneOfSevenType)[keyof typeof AssistantMessagePartOneOfSevenType];
+export type AssistantMessagePartOneOfOnezeroType =
+ (typeof AssistantMessagePartOneOfOnezeroType)[keyof typeof AssistantMessagePartOneOfOnezeroType];
// eslint-disable-next-line @typescript-eslint/no-redeclare
-export const AssistantMessagePartOneOfSevenType = {
+export const AssistantMessagePartOneOfOnezeroType = {
toolCallErr: 'toolCallErr',
} as const;
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSeven.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSeven.ts
deleted file mode 100644
index 2af7fe7924..0000000000
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/assistantMessagePartOneOfSeven.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Generated by orval v7.21.0 🍺
- * Do not edit manually.
- * Document Cognition Service
- * OpenAPI spec version: 1.0.0
- */
-import type { AssistantMessagePartOneOfSevenType } from './assistantMessagePartOneOfSevenType';
-
-export type AssistantMessagePartOneOfSeven = {
- description: string;
- id: string;
- name: string;
- type: AssistantMessagePartOneOfSevenType;
-};
diff --git a/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts b/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
index 44c0cf794d..168d0bf465 100644
--- a/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/schemas/index.ts
@@ -10,10 +10,13 @@ export * from './addServerRequest';
export * from './aIModel';
export * from './assistantMessagePart';
export * from './assistantMessagePartOneOf';
+export * from './assistantMessagePartOneOfEight';
+export * from './assistantMessagePartOneOfEightType';
export * from './assistantMessagePartOneOfFive';
+export * from './assistantMessagePartOneOfFiveDisplayName';
export * from './assistantMessagePartOneOfFiveType';
-export * from './assistantMessagePartOneOfSeven';
-export * from './assistantMessagePartOneOfSevenType';
+export * from './assistantMessagePartOneOfOnezero';
+export * from './assistantMessagePartOneOfOnezeroType';
export * from './assistantMessagePartOneOfThree';
export * from './assistantMessagePartOneOfThreeType';
export * from './assistantMessagePartOneOfType';
diff --git a/js/app/packages/service-clients/service-cognition/openapi.json b/js/app/packages/service-clients/service-cognition/openapi.json
index df350cb270..0d8ac71094 100644
--- a/js/app/packages/service-clients/service-cognition/openapi.json
+++ b/js/app/packages/service-clients/service-cognition/openapi.json
@@ -1422,6 +1422,32 @@
}
}
},
+ {
+ "type": "object",
+ "required": ["name", "service", "json", "id", "type"],
+ "properties": {
+ "display_name": {
+ "type": ["string", "null"],
+ "description": "Human-readable title from the MCP server, if provided"
+ },
+ "id": {
+ "type": "string"
+ },
+ "json": {},
+ "name": {
+ "type": "string",
+ "description": "Demangled tool name from the MCP server"
+ },
+ "service": {
+ "type": "string",
+ "description": "MCP server name"
+ },
+ "type": {
+ "type": "string",
+ "enum": ["mcpToolCall"]
+ }
+ }
+ },
{
"type": "object",
"required": ["name", "json", "id", "type"],
diff --git a/rust/cloud-storage/ai/src/tool/completion.rs b/rust/cloud-storage/ai/src/tool/completion.rs
index 7bc1b33cd1..c10fb37ad9 100644
--- a/rust/cloud-storage/ai/src/tool/completion.rs
+++ b/rust/cloud-storage/ai/src/tool/completion.rs
@@ -42,6 +42,7 @@ pub async fn tool_completion<T>(
id: tool_call.id.clone(),
json: serde_json::from_str(&tool_call.function.arguments)?,
name: tool_call.function.name.clone(),
+ mcp: None,
}),
ChatCompletionMessageToolCalls::Custom(_) => Err(AiError::from(anyhow::anyhow!(
"Unexpected custom tool call"
diff --git a/rust/cloud-storage/ai/src/tool/tool_loop/chat/agent.rs b/rust/cloud-storage/ai/src/tool/tool_loop/chat/agent.rs
index c9a223b6dd..98110835fa 100644
--- a/rust/cloud-storage/ai/src/tool/tool_loop/chat/agent.rs
+++ b/rust/cloud-storage/ai/src/tool/tool_loop/chat/agent.rs
@@ -2,11 +2,13 @@ use super::MAX_RECURSIONS;
use crate::openai_toolset::OpenAIToolSetExt;
use crate::tool::types::{ChatCompletionStream, ExtendedPartStream, PartOrExt, ToolResponse};
use crate::tool::types::{
- PartialToolCall, RequestContext, StreamPart, ToolCall, ToolResult, ToolSet,
+ McpInfo, PartialToolCall, RequestContext, StreamPart, ToolCall, ToolInfo, ToolResult, ToolSet,
};
use crate::types::openai::message::convert_message;
use crate::types::traits::{ExtendedOpenAIStream, ExtendedOpenAIStreamItem};
-use crate::types::{ChatCompletionRequest, ChatMessage, ChatMessages};
+use crate::types::{
+ AssistantMessagePart, ChatCompletionRequest, ChatMessage, ChatMessageContent, ChatMessages,
+};
use crate::types::{ExtendedClient, Result};
use async_openai::types::chat::{
ChatCompletionMessageToolCall, ChatCompletionMessageToolCalls,
@@ -81,7 +83,44 @@ where
.map(|msg| convert_message(msg.clone(), Some(&self.tool_call_id_name_mapping)))
.collect::<Vec<_>>()
.into();
- messages.0
+ messages
+ .0
+ .into_iter()
+ .map(|msg| self.rewrite_mcp_tool_calls(msg))
+ .collect()
+ }
+
+ fn rewrite_mcp_tool_calls(&self, mut msg: ChatMessage) -> ChatMessage {
+ if let ChatMessageContent::AssistantMessageParts(parts) = msg.content {
+ let parts = parts
+ .into_iter()
+ .map(|part| {
+ let AssistantMessagePart::ToolCall { ref name, .. } = part else {
+ return part;
+ };
+ let Some(ToolInfo::ExternalTool {
+ service_name,
+ tool_name,
+ display_name,
+ }) = self.toolset.routing_description(name)
+ else {
+ return part;
+ };
+ let AssistantMessagePart::ToolCall { json, id, .. } = part else {
+ unreachable!()
+ };
+ AssistantMessagePart::McpToolCall {
+ name: tool_name,
+ service: service_name,
+ display_name,
+ json,
+ id,
+ }
+ })
+ .collect();
+ msg.content = ChatMessageContent::AssistantMessageParts(parts);
+ }
+ msg
}
}
@@ -119,12 +158,14 @@ where
let part_or_ext = item.unwrap();
match part_or_ext {
ref part @ PartOrExt::Part(ref p) => {
- yield Ok(p.to_owned());
+ let enriched = self.enrich_stream_part(p);
+ yield Ok(enriched);
stream_parts.push(part.to_owned());
}
ref part @ PartOrExt::Ext(ref e) => {
if let Some(p) = self.client.handle_extension_item(e.to_owned()) {
- yield Ok(p);
+ let enriched = self.enrich_stream_part(&p);
+ yield Ok(enriched);
}
stream_parts.push(part.to_owned());
}
@@ -326,6 +367,32 @@ where
})
}
+ fn enrich_stream_part(&self, part: &StreamPart) -> StreamPart {
+ match part {
+ StreamPart::ToolCall(call) => {
+ let mcp = self
+ .toolset
+ .routing_description(&call.name)
+ .map(|info| match info {
+ ToolInfo::ExternalTool {
+ service_name,
+ tool_name,
+ display_name,
+ } => McpInfo {
+ service: service_name,
+ tool_name,
+ display_name,
+ },
+ });
+ StreamPart::ToolCall(ToolCall {
+ mcp,
+ ..call.clone()
+ })
+ }
+ other => other.clone(),
+ }
+ }
+
fn map_stream<'a>(
mut stream: ExtendedOpenAIStream<I::ResponseExtension>,
) -> ExtendedPartStream<'a, I::ResponseExtension> {
diff --git a/rust/cloud-storage/ai/src/tool/types/mod.rs b/rust/cloud-storage/ai/src/tool/types/mod.rs
index 96b2a1b396..4760d3ca7d 100644
--- a/rust/cloud-storage/ai/src/tool/types/mod.rs
+++ b/rust/cloud-storage/ai/src/tool/types/mod.rs
@@ -7,5 +7,5 @@ pub use ai_toolset::{
ToolCallError, ToolCollection, ToolInfo, ToolResult, ToolSchema, ToolSet, ToolSetCreationError,
ToolSetError,
};
-pub use stream::{AiStream, ChatCompletionStream, StreamPart, ToolCall, ToolResponse};
+pub use stream::{AiStream, ChatCompletionStream, McpInfo, StreamPart, ToolCall, ToolResponse};
pub(crate) use stream::{ExtendedPartStream, PartOrExt, PartialToolCall};
diff --git a/rust/cloud-storage/ai/src/tool/types/stream.rs b/rust/cloud-storage/ai/src/tool/types/stream.rs
index 482d33c6a1..653e237cb8 100644
--- a/rust/cloud-storage/ai/src/tool/types/stream.rs
+++ b/rust/cloud-storage/ai/src/tool/types/stream.rs
@@ -39,19 +39,33 @@ pub enum ToolResponse {
impl TryFrom<PartialToolCall> for ToolCall {
type Error = serde_json::Error;
fn try_from(value: PartialToolCall) -> Result<Self, Self::Error> {
- serde_json::from_str(&value.json).map(|json| Self {
+ let raw = if value.json.is_empty() {
+ "{}"
+ } else {
+ &value.json
+ };
+ serde_json::from_str(raw).map(|json| Self {
id: value.id,
name: value.name,
json,
+ mcp: None,
})
}
}
+#[derive(Debug, Clone, Serialize)]
+pub struct McpInfo {
+ pub service: String,
+ pub tool_name: String,
+ pub display_name: Option<String>,
+}
+
#[derive(Debug, Clone, Serialize)]
pub struct ToolCall {
pub id: String,
pub name: String,
pub json: serde_json::Value,
+ pub mcp: Option<McpInfo>,
}
#[derive(Debug, Clone, Default, Serialize)]
diff --git a/rust/cloud-storage/ai/src/types/client/anthropic.rs b/rust/cloud-storage/ai/src/types/client/anthropic.rs
index 47ff428512..8b63044249 100644
--- a/rust/cloud-storage/ai/src/types/client/anthropic.rs
+++ b/rust/cloud-storage/ai/src/types/client/anthropic.rs
@@ -63,6 +63,7 @@ impl ExtendedClient for AnthropicClient {
id: tool_call.id,
json: tool_call.input,
name: tool_call.name,
+ mcp: None,
}))
}
AnthropicResponseExtension::WebSearchToolResponse(response) => {
diff --git a/rust/cloud-storage/ai/src/types/message/chat_message.rs b/rust/cloud-storage/ai/src/types/message/chat_message.rs
index 2ae3d64afb..fce6ac04b0 100644
--- a/rust/cloud-storage/ai/src/types/message/chat_message.rs
+++ b/rust/cloud-storage/ai/src/types/message/chat_message.rs
@@ -56,6 +56,17 @@ pub enum AssistantMessagePart {
json: serde_json::Value,
id: String,
},
+ McpToolCall {
+ /// Demangled tool name from the MCP server
+ name: String,
+ /// MCP server name
+ service: String,
+ /// Human-readable title from the MCP server, if provided
+ #[serde(skip_serializing_if = "Option::is_none")]
+ display_name: Option<String>,
+ json: serde_json::Value,
+ id: String,
+ },
ToolCallResponseJson {
name: String,
json: serde_json::Value,
@@ -154,6 +165,12 @@ impl Display for AssistantMessagePart {
match self {
Self::Text { text } => write!(f, "{}", text),
Self::ToolCall { name, json, .. } => write!(f, "tool call: {}\n{}", name, json),
+ Self::McpToolCall {
+ name,
+ service,
+ json,
+ ..
+ } => write!(f, "mcp tool call: {}/{}\n{}", service, name, json),
Self::ToolCallResponseJson { name, json, .. } => {
write!(f, "tool response {}: {}", name, json)
}
diff --git a/rust/cloud-storage/ai/src/types/providers/openai/message.rs b/rust/cloud-storage/ai/src/types/providers/openai/message.rs
index 28fd1cf6ce..b2de3a653b 100644
--- a/rust/cloud-storage/ai/src/types/providers/openai/message.rs
+++ b/rust/cloud-storage/ai/src/types/providers/openai/message.rs
@@ -157,6 +157,26 @@ impl From<ChatMessage> for Vec<ChatCompletionRequestMessage> {
);
pending_tool_calls.push(tool_call);
}
+ AssistantMessagePart::McpToolCall {
+ name,
+ service,
+ json,
+ id,
+ ..
+ } => {
+ let mangled = format!("mcp__{}__{}", service, name);
+ let tool_call = ChatCompletionMessageToolCalls::Function(
+ ChatCompletionMessageToolCall {
+ function: FunctionCall {
+ arguments: serde_json::to_string(&json)
+ .unwrap_or(String::new()),
+ name: mangled,
+ },
+ id: id.clone(),
+ },
+ );
+ pending_tool_calls.push(tool_call);
+ }
AssistantMessagePart::ToolCallResponseJson { json, id, .. } => {
// flush pending text and tool calls as an assistant message
flush_pending(
diff --git a/rust/cloud-storage/ai_toolset/src/toolset/types.rs b/rust/cloud-storage/ai_toolset/src/toolset/types.rs
index 714c47a68d..10b4a6588c 100644
--- a/rust/cloud-storage/ai_toolset/src/toolset/types.rs
+++ b/rust/cloud-storage/ai_toolset/src/toolset/types.rs
@@ -18,6 +18,8 @@ pub enum ToolInfo {
service_name: String,
/// the name of the tool
tool_name: String,
+ /// Human-readable title from the MCP server, if provided
+ display_name: Option<String>,
},
}
diff --git a/rust/cloud-storage/chat/src/domain/service/chat.rs b/rust/cloud-storage/chat/src/domain/service/chat.rs
index e4eb4d60a1..e3dede43ea 100644
--- a/rust/cloud-storage/chat/src/domain/service/chat.rs
+++ b/rust/cloud-storage/chat/src/domain/service/chat.rs
@@ -439,7 +439,7 @@ where
match content {
ChatMessageContent::AssistantMessageParts(parts) => {
let has_tool = parts.iter().any(|part| {
- matches!(part, AssistantMessagePart::ToolCall { id, .. } if id == tool_call_id)
+ matches!(part, AssistantMessagePart::ToolCall { id, .. } | AssistantMessagePart::McpToolCall { id, .. } if id == tool_call_id)
});
if has_tool {
Ok(parts)
@@ -462,6 +462,9 @@ fn find_tool_call<'a>(
AssistantMessagePart::ToolCall { id, name, json } if id == tool_call_id => {
Some((name.as_str(), json))
}
+ AssistantMessagePart::McpToolCall { id, name, json, .. } if id == tool_call_id => {
+ Some((name.as_str(), json))
+ }
_ => None,
})
}
@@ -473,11 +476,15 @@ fn update_tool_call_args(
new_args: serde_json::Value,
) {
for part in parts.iter_mut() {
- if let AssistantMessagePart::ToolCall { id, json, .. } = part
- && id == tool_call_id
- {
- *json = new_args;
- return;
+ match part {
+ AssistantMessagePart::ToolCall { id, json, .. }
+ | AssistantMessagePart::McpToolCall { id, json, .. }
+ if id == tool_call_id =>
+ {
+ *json = new_args;
+ return;
+ }
+ _ => {}
}
}
}
diff --git a/rust/cloud-storage/document_cognition_service/out.log b/rust/cloud-storage/document_cognition_service/out.log
new file mode 100644
index 0000000000..f222a3b65a
--- /dev/null
+++ b/rust/cloud-storage/document_cognition_service/out.log
@@ -0,0 +1,294 @@
+ 2026-05-14T20:08:56.785327Z  INFO document_cognition_service: initialized config
+ at document_cognition_service/src/main.rs:61
+
+ 2026-05-14T20:08:56.913991Z  INFO document_cognition_service: initialized db connection, min_connections: 3, max_connections: 10
+ at document_cognition_service/src/main.rs:76
+
+ 2026-05-14T20:08:57.010698Z  INFO document_cognition_service: initialized dss client
+ at document_cognition_service/src/main.rs:105
+
+ 2026-05-14T20:08:57.010815Z  INFO document_cognition_service: initialized comms client
+ at document_cognition_service/src/main.rs:109
+
+ 2026-05-14T20:08:57.010940Z  INFO document_cognition_service: initialized sync service client
+ at document_cognition_service/src/main.rs:124
+
+ 2026-05-14T20:08:57.011038Z  INFO document_cognition_service: initialized search service client
+ at document_cognition_service/src/main.rs:130
+
+ 2026-05-14T20:08:57.011663Z  INFO document_cognition_service: initialized static file service client
+ at document_cognition_service/src/main.rs:146
+
+ 2026-05-14T20:08:57.015804Z  INFO document_cognition_service: initialized stream repo
+ at document_cognition_service/src/main.rs:164
+
+ 2026-05-14T20:08:57.193061Z  INFO ensure_exists::dynamodb: return: Some(Runtime("connection-gateway-table-dev-f2b369a"))
+ at ensure_exists/src/dynamodb.rs:89
+ in ensure_exists::dynamodb::check_exists
+
+ 2026-05-14T20:08:57.193174Z  INFO connection_gateway::service::connection: creating new connection manager
+ at connection_gateway/src/service/connection.rs:81
+
+ 2026-05-14T20:08:57.193360Z  INFO document_cognition_service: initialized connection repo
+ at document_cognition_service/src/main.rs:171
+
+ 2026-05-14T20:08:57.195388Z  INFO document_cognition_service: initialized notification ingress service
+ at document_cognition_service/src/main.rs:198
+
+ 2026-05-14T20:08:57.195663Z  INFO document_cognition_service: initialized soup service
+ at document_cognition_service/src/main.rs:225
+
+ 2026-05-14T20:08:57.199383Z  INFO document_cognition_service: initialized document tool context
+ at document_cognition_service/src/main.rs:268
+
+ 2026-05-14T20:08:57.199600Z  INFO document_cognition_service: initialized attachment provider
+ at document_cognition_service/src/main.rs:297
+
+ 2026-05-14T20:08:57.199803Z  INFO document_cognition_service: initialized properties tool context
+ at document_cognition_service/src/main.rs:316
+
+ 2026-05-14T20:08:57.199829Z  INFO document_cognition_service: initialized email tool context
+ at document_cognition_service/src/main.rs:331
+
+ 2026-05-14T20:08:57.199864Z  INFO document_cognition_service: initialized call tool context
+ at document_cognition_service/src/main.rs:349
+
+ 2026-05-14T20:08:57.199911Z  INFO document_cognition_service: initialized chat tool context
+ at document_cognition_service/src/main.rs:363
+
+ 2026-05-14T20:08:57.213968Z  INFO document_cognition_service: initialized memory service
+ at document_cognition_service/src/main.rs:392
+
+ 2026-05-14T20:08:57.220057Z  INFO document_cognition_service::api: document cognition service is up and running, port: 8085, environment: Local
+ at document_cognition_service/src/api/mod.rs:62
+ in document_cognition_service::api::setup_and_serve
+
+ 2026-05-14T20:10:52.880604Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-SEND-REQUEST, model_name: claude-opus-4-6, duration_ms: 39
+ at document_cognition_service/src/api/utils/log.rs:13
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:10:52.884643Z  INFO document_cognition_service::api::stream::chat_message: return: Json(SendChatMessageResponse { stream_id: "280e330a-2692-4340-a416-f258afe5545c", message_id: "280e330a-2692-4340-a416-f258afe5545c", chat_id: "f3d025f9-b425-493b-82f4-a60e167fd6b1" })
+ at document_cognition_service/src/api/stream/chat_message.rs:138
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:10:53.467875Z  INFO rmcp::service: Service initialized as client, peer_info: Some(InitializeResult { protocol_version: ProtocolVersion("2025-11-25"), capabilities: ServerCapabilities { experimental: None, extensions: None, logging: None, completions: None, prompts: None, resources: None, tools: Some(ToolsCapability { list_changed: Some(true) }), tasks: None }, server_info: Implementation { name: "Linear MCP", title: Some("Linear"), version: "1.0.0", description: None, icons: Some([Icon { src: "https://static.linear.app/integrations/mcp/icon.svg", mime_type: Some("image/svg+xml"), sizes: None, theme: None }]), website_url: Some("https://linear.app") }, instructions: Some("When passing string values to tools, send the content directly without escape sequences. For example, use real newlines in markdown content rather than literal backslash-n (\\n) characters.") })
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:759
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:10:53.545232Z  INFO ai::tool::tool_loop::chat::agent: tool_loop iteration start, iteration: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:141
+
+ 2026-05-14T20:10:53.545282Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: pre-correction message count, message_count: 16
+ at ai/src/tool/tool_loop/chat/agent.rs:550
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:10:53.545350Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: post-correction message count, message_count: 16
+ at ai/src/tool/tool_loop/chat/agent.rs:555
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:10:55.887805Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-FIRST-TOKEN, model_name: claude-opus-4-6, duration_ms: 3046
+ at document_cognition_service/src/api/utils/log.rs:13
+
+ 2026-05-14T20:10:57.672361Z  INFO ai::tool::tool_loop::chat::agent: tool_loop processing stream_parts, iteration: 0, ext_count: 0, part_count: 6, total: 6
+ at ai/src/tool/tool_loop/chat/agent.rs:184
+
+ 2026-05-14T20:10:57.672441Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts: tool call summary before execution, pending_part_tool_calls: 0, ext_tool_calls: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:314
+
+ 2026-05-14T20:10:57.672486Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts complete, msg_types: ["assistant"], tool_responses: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:405
+
+ 2026-05-14T20:10:57.672510Z  INFO ai::tool::tool_loop::chat::agent: tool_loop process_stream_parts result, iteration: 0, tool_responses: 0, new_messages: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:196
+
+ 2026-05-14T20:10:57.672534Z  INFO ai::tool::tool_loop::chat::agent: tool_loop breaking: no tool_responses, iteration: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:209
+
+ 2026-05-14T20:10:57.681599Z  INFO rmcp::service: task cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:845
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:10:57.682620Z  INFO rmcp::service: serve finished, quit_reason: Cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:1082
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:03.744220Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-SEND-REQUEST, model_name: claude-opus-4-6, duration_ms: 16
+ at document_cognition_service/src/api/utils/log.rs:13
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:11:03.747230Z  INFO document_cognition_service::api::stream::chat_message: return: Json(SendChatMessageResponse { stream_id: "32176619-d752-4626-9928-f989cc2e103e", message_id: "32176619-d752-4626-9928-f989cc2e103e", chat_id: "f3d025f9-b425-493b-82f4-a60e167fd6b1" })
+ at document_cognition_service/src/api/stream/chat_message.rs:138
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:11:04.204545Z  INFO rmcp::service: Service initialized as client, peer_info: Some(InitializeResult { protocol_version: ProtocolVersion("2025-11-25"), capabilities: ServerCapabilities { experimental: None, extensions: None, logging: None, completions: None, prompts: None, resources: None, tools: Some(ToolsCapability { list_changed: Some(true) }), tasks: None }, server_info: Implementation { name: "Linear MCP", title: Some("Linear"), version: "1.0.0", description: None, icons: Some([Icon { src: "https://static.linear.app/integrations/mcp/icon.svg", mime_type: Some("image/svg+xml"), sizes: None, theme: None }]), website_url: Some("https://linear.app") }, instructions: Some("When passing string values to tools, send the content directly without escape sequences. For example, use real newlines in markdown content rather than literal backslash-n (\\n) characters.") })
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:759
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:04.310990Z  INFO ai::tool::tool_loop::chat::agent: tool_loop iteration start, iteration: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:141
+
+ 2026-05-14T20:11:04.311129Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: pre-correction message count, message_count: 18
+ at ai/src/tool/tool_loop/chat/agent.rs:550
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:04.311295Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: post-correction message count, message_count: 18
+ at ai/src/tool/tool_loop/chat/agent.rs:555
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:06.641693Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-FIRST-TOKEN, model_name: claude-opus-4-6, duration_ms: 2913
+ at document_cognition_service/src/api/utils/log.rs:13
+
+ 2026-05-14T20:11:06.649468Z  INFO ai::tool::tool_loop::chat::agent: tool_loop processing stream_parts, iteration: 0, ext_count: 0, part_count: 2, total: 2
+ at ai/src/tool/tool_loop/chat/agent.rs:184
+
+ 2026-05-14T20:11:06.649585Z  INFO ai::tool::tool_loop::chat::agent: Part: tool_call queued for local execution, id: toolu_01JwXCvb4vpERiLrGFw1pMns, name: mcp__Linear__list_issue_labels
+ at ai/src/tool/tool_loop/chat/agent.rs:290
+
+ 2026-05-14T20:11:06.649716Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts: tool call summary before execution, pending_part_tool_calls: 1, ext_tool_calls: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:314
+
+ 2026-05-14T20:11:08.480268Z  INFO ai::tool::tool_loop::chat::agent: tool execution succeeded, id: toolu_01JwXCvb4vpERiLrGFw1pMns, name: mcp__Linear__list_issue_labels
+ at ai/src/tool/tool_loop/chat/agent.rs:342
+
+ 2026-05-14T20:11:08.480410Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts complete, msg_types: ["assistant", "tool"], tool_responses: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:405
+
+ 2026-05-14T20:11:08.480448Z  INFO ai::tool::tool_loop::chat::agent: tool_loop process_stream_parts result, iteration: 0, tool_responses: 1, new_messages: 2
+ at ai/src/tool/tool_loop/chat/agent.rs:196
+
+ 2026-05-14T20:11:08.485137Z  INFO ai::tool::tool_loop::chat::agent: tool_loop iteration start, iteration: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:141
+
+ 2026-05-14T20:11:08.485176Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: pre-correction message count, message_count: 20
+ at ai/src/tool/tool_loop/chat/agent.rs:550
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:08.485254Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: post-correction message count, message_count: 20
+ at ai/src/tool/tool_loop/chat/agent.rs:555
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:11.535928Z  INFO ai::tool::tool_loop::chat::agent: tool_loop processing stream_parts, iteration: 1, ext_count: 0, part_count: 5, total: 5
+ at ai/src/tool/tool_loop/chat/agent.rs:184
+
+ 2026-05-14T20:11:11.536244Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts: tool call summary before execution, pending_part_tool_calls: 0, ext_tool_calls: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:314
+
+ 2026-05-14T20:11:11.536413Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts complete, msg_types: ["assistant"], tool_responses: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:405
+
+ 2026-05-14T20:11:11.536524Z  INFO ai::tool::tool_loop::chat::agent: tool_loop process_stream_parts result, iteration: 1, tool_responses: 0, new_messages: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:196
+
+ 2026-05-14T20:11:11.536607Z  INFO ai::tool::tool_loop::chat::agent: tool_loop breaking: no tool_responses, iteration: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:209
+
+ 2026-05-14T20:11:11.556560Z  INFO rmcp::service: task cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:845
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:11.557801Z  INFO rmcp::service: serve finished, quit_reason: Cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:1082
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:16.687137Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-SEND-REQUEST, model_name: claude-opus-4-6, duration_ms: 22
+ at document_cognition_service/src/api/utils/log.rs:13
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:11:16.690201Z  INFO document_cognition_service::api::stream::chat_message: return: Json(SendChatMessageResponse { stream_id: "9d417992-88ab-49b3-82ef-21bb4d464f21", message_id: "9d417992-88ab-49b3-82ef-21bb4d464f21", chat_id: "f3d025f9-b425-493b-82f4-a60e167fd6b1" })
+ at document_cognition_service/src/api/stream/chat_message.rs:138
+ in document_cognition_service::api::stream::chat_message::send_chat_message with chat_id: Some("f3d025f9-b425-493b-82f4-a60e167fd6b1"), user_id: macro|[email protected], attachment_ids: []
+ in macro_middleware::user_permissions::attach_user_permissions::handler with user_id: "macro|[email protected]"
+
+ 2026-05-14T20:11:17.034683Z  INFO rmcp::service: Service initialized as client, peer_info: Some(InitializeResult { protocol_version: ProtocolVersion("2025-11-25"), capabilities: ServerCapabilities { experimental: None, extensions: None, logging: None, completions: None, prompts: None, resources: None, tools: Some(ToolsCapability { list_changed: Some(true) }), tasks: None }, server_info: Implementation { name: "Linear MCP", title: Some("Linear"), version: "1.0.0", description: None, icons: Some([Icon { src: "https://static.linear.app/integrations/mcp/icon.svg", mime_type: Some("image/svg+xml"), sizes: None, theme: None }]), website_url: Some("https://linear.app") }, instructions: Some("When passing string values to tools, send the content directly without escape sequences. For example, use real newlines in markdown content rather than literal backslash-n (\\n) characters.") })
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:759
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:17.151405Z  INFO ai::tool::tool_loop::chat::agent: tool_loop iteration start, iteration: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:141
+
+ 2026-05-14T20:11:17.151532Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: pre-correction message count, message_count: 22
+ at ai/src/tool/tool_loop/chat/agent.rs:550
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:17.151658Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: post-correction message count, message_count: 22
+ at ai/src/tool/tool_loop/chat/agent.rs:555
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:19.541004Z  INFO document_cognition_service::api::utils::log: metric: TIME-TO-FIRST-TOKEN, model_name: claude-opus-4-6, duration_ms: 2876
+ at document_cognition_service/src/api/utils/log.rs:13
+
+ 2026-05-14T20:11:19.546119Z  INFO ai::tool::tool_loop::chat::agent: tool_loop processing stream_parts, iteration: 0, ext_count: 0, part_count: 2, total: 2
+ at ai/src/tool/tool_loop/chat/agent.rs:184
+
+ 2026-05-14T20:11:19.546173Z  INFO ai::tool::tool_loop::chat::agent: Part: tool_call queued for local execution, id: toolu_01FDuXRYHQ3v6JG2DbqUrcr9, name: mcp__Linear__list_teams
+ at ai/src/tool/tool_loop/chat/agent.rs:290
+
+ 2026-05-14T20:11:19.546222Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts: tool call summary before execution, pending_part_tool_calls: 1, ext_tool_calls: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:314
+
+ 2026-05-14T20:11:19.765853Z  INFO ai::tool::tool_loop::chat::agent: tool execution succeeded, id: toolu_01FDuXRYHQ3v6JG2DbqUrcr9, name: mcp__Linear__list_teams
+ at ai/src/tool/tool_loop/chat/agent.rs:342
+
+ 2026-05-14T20:11:19.766113Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts complete, msg_types: ["assistant", "tool"], tool_responses: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:405
+
+ 2026-05-14T20:11:19.766149Z  INFO ai::tool::tool_loop::chat::agent: tool_loop process_stream_parts result, iteration: 0, tool_responses: 1, new_messages: 2
+ at ai/src/tool/tool_loop/chat/agent.rs:196
+
+ 2026-05-14T20:11:19.771725Z  INFO ai::tool::tool_loop::chat::agent: tool_loop iteration start, iteration: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:141
+
+ 2026-05-14T20:11:19.771850Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: pre-correction message count, message_count: 24
+ at ai/src/tool/tool_loop/chat/agent.rs:550
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:19.772155Z  INFO ai::tool::tool_loop::chat::agent: make_openai_chat_completion_stream: post-correction message count, message_count: 24
+ at ai/src/tool/tool_loop/chat/agent.rs:555
+ in ai::tool::tool_loop::chat::agent::make_openai_chat_completion_stream
+
+ 2026-05-14T20:11:22.660325Z  INFO ai::tool::tool_loop::chat::agent: tool_loop processing stream_parts, iteration: 1, ext_count: 0, part_count: 5, total: 5
+ at ai/src/tool/tool_loop/chat/agent.rs:184
+
+ 2026-05-14T20:11:22.660514Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts: tool call summary before execution, pending_part_tool_calls: 0, ext_tool_calls: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:314
+
+ 2026-05-14T20:11:22.660623Z  INFO ai::tool::tool_loop::chat::agent: process_stream_parts complete, msg_types: ["assistant"], tool_responses: 0
+ at ai/src/tool/tool_loop/chat/agent.rs:405
+
+ 2026-05-14T20:11:22.660694Z  INFO ai::tool::tool_loop::chat::agent: tool_loop process_stream_parts result, iteration: 1, tool_responses: 0, new_messages: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:196
+
+ 2026-05-14T20:11:22.660755Z  INFO ai::tool::tool_loop::chat::agent: tool_loop breaking: no tool_responses, iteration: 1
+ at ai/src/tool/tool_loop/chat/agent.rs:209
+
+ 2026-05-14T20:11:22.677425Z  INFO rmcp::service: task cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:845
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
+ 2026-05-14T20:11:22.679083Z  INFO rmcp::service: serve finished, quit_reason: Cancelled
+ at /Users/eric/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rmcp-1.6.0/src/service.rs:1082
+ in rmcp::service::serve_inner
+ in mcp_client::domain::models::server::connect
+ in mcp_client::domain::service::toolset::new
+
diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
index 46ad228b69..e934d2cee2 100644
--- a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs
@@ -388,7 +388,8 @@ fn resolve_pending_tool_calls(parts: Vec<AssistantMessagePart>) -> Vec<Assistant
let mut pending: HashSet<String> = HashSet::new();
for part in &parts {
match part {
- AssistantMessagePart::ToolCall { id, .. } => {
+ AssistantMessagePart::ToolCall { id, .. }
+ | AssistantMessagePart::McpToolCall { id, .. } => {
pending.insert(id.clone());
}
AssistantMessagePart::ToolCallResponseJson { id, .. }
@@ -404,7 +405,10 @@ fn resolve_pending_tool_calls(parts: Vec<AssistantMessagePart>) -> Vec<Assistant
let mut out: Vec<AssistantMessagePart> = Vec::with_capacity(parts.len() + pending.len());
for part in parts {
let synthetic = match &part {
- AssistantMessagePart::ToolCall { id, name, .. } if pending.contains(id) => {
+ AssistantMessagePart::ToolCall { id, name, .. }
+ | AssistantMessagePart::McpToolCall { id, name, .. }
+ if pending.contains(id) =>
+ {
Some(AssistantMessagePart::ToolCallErr {
name: name.clone(),
id: id.clone(),
@@ -561,10 +565,19 @@ fn stream_and_save_message(
}
AssistantMessagePart::Text { text: content }
}
- StreamPart::ToolCall(call) => AssistantMessagePart::ToolCall {
- name: call.name,
- json: call.json,
- id: call.id,
+ StreamPart::ToolCall(call) => match call.mcp {
+ Some(mcp) => AssistantMessagePart::McpToolCall {
+ name: mcp.tool_name,
+ service: mcp.service,
+ display_name: mcp.display_name,
+ json: call.json,
+ id: call.id,
+ },
+ None => AssistantMessagePart::ToolCall {
+ name: call.name,
+ json: call.json,
+ id: call.id,
+ },
},
StreamPart::Usage(usage) => {
tracing::debug!(record=?usage, "usage");
diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rs
index a5e6e411d1..3a7d968f09 100644
--- a/rust/cloud-storage/document_cognition_service/src/config.rs
+++ b/rust/cloud-storage/document_cognition_service/src/config.rs
@@ -80,6 +80,7 @@ env_var!(
pub DocumentStorageServiceCloudfrontSignerPublicKeyId,
pub DocumentStorageServiceCloudfrontSignerPrivateKeySecretName,
pub McpCredentialsKeySecretName,
+ pub DocumentCognitionServiceUrl,
}
);
@@ -104,8 +105,6 @@ impl Config {
.and_then(|v| v.parse::<i64>().ok())
.unwrap_or(DEFAULT_DOCUMENT_BATCH_LIMIT);
- let document_cognition_service_url = format!("http://127.0.0.1:{}", port);
-
let EnvVars {
database_url,
document_storage_bucket,
@@ -128,6 +127,7 @@ impl Config {
document_storage_service_cloudfront_signer_public_key_id,
document_storage_service_cloudfront_signer_private_key_secret_name,
mcp_credentials_key_secret_name,
+ document_cognition_service_url,
} = env_vars;
Ok(Config {
@@ -146,7 +146,7 @@ impl Config {
sync_service_url: sync_service_url.to_string(),
lexical_service_url: lexical_service_url.to_string(),
email_service_url: email_service_url.to_string(),
- document_cognition_service_url,
+ document_cognition_service_url: document_cognition_service_url.to_string(),
static_file_service_url: static_file_service_url.to_string(),
authentication_service_url: authentication_service_url.to_string(),
authentication_service_secret_key: authentication_service_secret_key.to_string(),
diff --git a/rust/cloud-storage/mcp_client/src/domain/models/aes_key.rs b/rust/cloud-storage/mcp_client/src/domain/models/aes_key.rs
index 68191e43ca..ee9fa8de28 100644
--- a/rust/cloud-storage/mcp_client/src/domain/models/aes_key.rs
+++ b/rust/cloud-storage/mcp_client/src/domain/models/aes_key.rs
@@ -12,6 +12,7 @@ impl AesKey {
impl TryFrom<Vec<u8>> for AesKey {
type Error = AesKeyError;
+ #[tracing::instrument(skip_all, err)]
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
let bytes: [u8; 32] = bytes
.try_into()
@@ -24,6 +25,7 @@ impl TryFrom<&str> for AesKey {
type Error = AesKeyError;
/// Decode a base64-encoded key string into an [`AesKey`].
+ #[tracing::instrument(skip_all, err)]
fn try_from(b64: &str) -> Result<Self, Self::Error> {
use base64::Engine;
let bytes = base64::engine::general_purpose::STANDARD
diff --git a/rust/cloud-storage/mcp_client/src/domain/models/mod.rs b/rust/cloud-storage/mcp_client/src/domain/models/mod.rs
index af6db65624..792735de27 100644
--- a/rust/cloud-storage/mcp_client/src/domain/models/mod.rs
+++ b/rust/cloud-storage/mcp_client/src/domain/models/mod.rs
@@ -4,6 +4,7 @@ mod result;
mod server;
pub use aes_key::{AesKey, AesKeyError};
+pub use consts::*;
pub use macro_user_id::user_id::MacroUserIdStr;
pub use result::{Error, Result};
pub use rmcp::transport::auth::StoredCredentials;
diff --git a/rust/cloud-storage/mcp_client/src/domain/models/server.rs b/rust/cloud-storage/mcp_client/src/domain/models/server.rs
index 7fc0a9ea2e..faa94a5294 100644
--- a/rust/cloud-storage/mcp_client/src/domain/models/server.rs
+++ b/rust/cloud-storage/mcp_client/src/domain/models/server.rs
@@ -51,6 +51,7 @@ pub struct McpServerRecord {
}
impl McpConnector for McpServerRecord {
+ #[tracing::instrument(skip_all, err)]
async fn connect(&self) -> anyhow::Result<McpServer> {
match &self.credentials {
Some(credentials) => {
diff --git a/rust/cloud-storage/mcp_client/src/domain/service/oauth.rs b/rust/cloud-storage/mcp_client/src/domain/service/oauth.rs
index ae98a3fc13..90807d3606 100644
--- a/rust/cloud-storage/mcp_client/src/domain/service/oauth.rs
+++ b/rust/cloud-storage/mcp_client/src/domain/service/oauth.rs
@@ -1,3 +1,4 @@
+use crate::domain::models::MCP_CLIENT_NAME;
use crate::domain::models::{MacroUserIdStr, McpServerRecord, StoredCredentials};
use crate::domain::ports::{McpServerStore, OAuthClient, OAuthStateStore, PendingAuth};
use macro_user_id::cowlike::CowLike;
@@ -34,6 +35,7 @@ where
R: OAuthStateStore,
anyhow::Error: From<S::Err>,
{
+ #[tracing::instrument(skip_all, err)]
async fn start_authorization(
&self,
user_id: &MacroUserIdStr<'static>,
@@ -49,7 +51,7 @@ where
auth_manager.set_credential_store(InMemoryCredentialStore::new());
let client_config = auth_manager
- .register_client("macro", &self.redirect_uri, &[])
+ .register_client(MCP_CLIENT_NAME, &self.redirect_uri, &[])
.await?;
let auth_url = auth_manager.get_authorization_url(&[]).await?;
@@ -74,6 +76,7 @@ where
Ok(auth_url)
}
+ #[tracing::instrument(skip_all, err)]
async fn exchange_authorization_code(
&self,
code: &str,
@@ -141,6 +144,7 @@ where
}
}
+#[tracing::instrument(err)]
fn extract_state_param(url: &str) -> anyhow::Result<String> {
reqwest::Url::parse(url)?
.query_pairs()
diff --git a/rust/cloud-storage/mcp_client/src/domain/service/toolset.rs b/rust/cloud-storage/mcp_client/src/domain/service/toolset.rs
index 572f1213da..43b9d3334d 100644
--- a/rust/cloud-storage/mcp_client/src/domain/service/toolset.rs
+++ b/rust/cloud-storage/mcp_client/src/domain/service/toolset.rs
@@ -1,8 +1,9 @@
-use crate::domain::models::{Error, McpServerRecord};
+use crate::domain::models::{Error, McpServer, McpServerRecord};
use crate::domain::ports::McpConnector;
use ai::openai_toolset::OpenAIToolSetExt;
use ai_toolset::{
- AsyncToolCollection, RequestContext, RequestSchema, ToolInfo, ToolResult, ToolSet, ToolSetError,
+ AsyncToolCollection, RequestContext, RequestSchema, ToolCallError, ToolInfo, ToolResult,
+ ToolSet, ToolSetError,
};
use async_openai::types::chat::{ChatCompletionTool, ChatCompletionTools, FunctionObject};
use rmcp::RoleClient;
@@ -13,19 +14,23 @@ use std::collections::BTreeMap;
use std::pin::Pin;
use std::sync::Arc;
-const MANGLED_PREFIX: &str = "mcp_";
+const MANGLED_PREFIX: &str = "mcp__";
+const MANGLED_SEPARATOR: &str = "__";
-/// A mangled tool name in the format `mcp_<server>_<tool>`.
+/// A mangled tool name in the format `mcp__<server>__<tool>`.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct MangledName(String);
impl MangledName {
fn new(server_name: &str, tool_name: &str) -> Self {
- Self(format!("{MANGLED_PREFIX}{server_name}_{tool_name}"))
+ Self(format!(
+ "{MANGLED_PREFIX}{server_name}{MANGLED_SEPARATOR}{tool_name}"
+ ))
}
fn parse(s: &str) -> Option<(&str, &str)> {
- s.strip_prefix(MANGLED_PREFIX)?.split_once('_')
+ s.strip_prefix(MANGLED_PREFIX)?
+ .split_once(MANGLED_SEPARATOR)
}
fn as_str(&self) -> &str {
@@ -46,10 +51,12 @@ struct RegisteredTool {
/// Dispatches tool calls to connected MCP servers using name-mangled routing.
///
-/// Every tool is exposed as `mcp_<server_name>_<tool_name>` to guarantee
+/// Every tool is exposed as `mcp__<server_name>__<tool_name>` to guarantee
/// uniqueness across servers.
pub struct McpToolSet {
tools: BTreeMap<MangledName, RegisteredTool>,
+ /// Kept alive so the background transport tasks aren't cancelled.
+ _connections: Vec<McpServer>,
}
impl McpToolSet {
@@ -82,6 +89,7 @@ impl McpToolSet {
let results = futures::future::join_all(futs).await;
let mut tools = BTreeMap::new();
+ let mut connections = Vec::new();
for (server_name, client, server_tools) in results.into_iter().flatten() {
for tool in server_tools {
let mangled = MangledName::new(&server_name, &tool.name);
@@ -94,14 +102,18 @@ impl McpToolSet {
tools.insert(
mangled,
RegisteredTool {
- peer: client.clone(),
+ peer: client.peer().clone(),
tool,
},
);
}
+ connections.push(client);
}
- Self { tools }
+ Self {
+ tools,
+ _connections: connections,
+ }
}
/// Returns `true` when no tools were discovered.
@@ -109,6 +121,7 @@ impl McpToolSet {
self.tools.is_empty()
}
+ #[tracing::instrument(skip(self, arguments), err)]
async fn call_tool(
&self,
name: &str,
@@ -146,10 +159,19 @@ impl<Context: Send + Sync + 'static> ToolSet<Context> for McpToolSet {
_ => serde_json::Map::new(),
};
- let result = self
- .call_tool(tool_name, arguments)
- .await
- .map_err(|e| ToolSetError::NotFound(e.to_string()))?;
+ let result = match self.call_tool(tool_name, arguments).await {
+ Ok(result) => result,
+ Err(Error::UnknownTool(name)) => {
+ return Err(ToolSetError::NotFound(name));
+ }
+ Err(e) => {
+ let description = e.to_string();
+ return Ok(Err(ToolCallError {
+ internal_error: anyhow::anyhow!("{}", &description),
+ description,
+ }));
+ }
+ };
let text = result
.content
@@ -158,12 +180,13 @@ impl<Context: Send + Sync + 'static> ToolSet<Context> for McpToolSet {
.collect::<Vec<_>>()
.join("");
- let value = serde_json::Value::String(text);
-
if result.is_error.unwrap_or(false) {
- Err(ToolSetError::NotFound(value.to_string()))
+ Ok(Err(ToolCallError {
+ internal_error: anyhow::anyhow!("{}", &text),
+ description: text,
+ }))
} else {
- Ok(Ok(value))
+ Ok(Ok(serde_json::Value::String(text)))
}
})
}
@@ -187,9 +210,15 @@ impl<Context: Send + Sync + 'static> ToolSet<Context> for McpToolSet {
fn routing_description<'a>(&'a self, tool_name: &'a str) -> Option<ToolInfo> {
let (server_name, original_name) = MangledName::parse(tool_name)?;
+ let key = MangledName(tool_name.to_owned());
+ let display_name = self
+ .tools
+ .get(&key)
+ .and_then(|entry| entry.tool.title.clone());
Some(ToolInfo::ExternalTool {
service_name: server_name.to_owned(),
tool_name: original_name.to_owned(),
+ display_name,
})
}
}
diff --git a/rust/cloud-storage/mcp_client/src/inbound/axum_router.rs b/rust/cloud-storage/mcp_client/src/inbound/axum_router.rs
index c5817f9f1e..0bfe42696e 100644
--- a/rust/cloud-storage/mcp_client/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/mcp_client/src/inbound/axum_router.rs
@@ -204,6 +204,7 @@ impl IntoResponse for McpHandlerErr {
)
)]
/// List all MCP servers configured for the authenticated user.
+#[tracing::instrument(skip_all, err)]
pub async fn list_servers<S, O>(
State(state): State<McpRouterState<S, O>>,
MacroUserExtractor { macro_user_id, .. }: MacroUserExtractor,
@@ -237,6 +238,7 @@ where
)
)]
/// Add a new MCP server for the authenticated user.
+#[tracing::instrument(skip_all, err)]
pub async fn add_server<S, O>(
State(state): State<McpRouterState<S, O>>,
MacroUserExtractor { macro_user_id, .. }: MacroUserExtractor,
@@ -281,6 +283,7 @@ where
)
)]
/// Update an existing MCP server's name or enabled status.
+#[tracing::instrument(skip_all, err)]
pub async fn update_server<S, O>(
State(state): State<McpRouterState<S, O>>,
MacroUserExtractor { macro_user_id, .. }: MacroUserExtractor,
@@ -327,6 +330,7 @@ where
)
)]
/// Delete an MCP server by URL.
+#[tracing::instrument(skip_all, err)]
pub async fn delete_server<S, O>(
State(state): State<McpRouterState<S, O>>,
MacroUserExtractor { macro_user_id, .. }: MacroUserExtractor,
@@ -359,6 +363,7 @@ where
)
)]
/// Start the OAuth authorization flow for an MCP server.
+#[tracing::instrument(skip_all, err)]
pub async fn start_auth<S, O>(
State(state): State<McpRouterState<S, O>>,
MacroUserExtractor { macro_user_id, .. }: MacroUserExtractor,
@@ -388,10 +393,11 @@ where
)
)]
/// OAuth callback endpoint — receives code and state from the authorization server.
+#[tracing::instrument(skip_all, err)]
pub async fn auth_callback<S, O>(
State(state): State<McpRouterState<S, O>>,
Query(params): Query<AuthCallbackParams>,
-) -> Result<StatusCode, McpHandlerErr>
+) -> Result<String, McpHandlerErr>
where
S: McpServerStore,
O: OAuthClient,
@@ -401,5 +407,5 @@ where
.exchange_authorization_code(&params.code, &params.state)
.await?;
- Ok(StatusCode::OK)
+ Ok("Authorization successful. You can close this tab.".to_string())
}
diff --git a/rust/cloud-storage/mcp_client/src/outbound/pg_server_repo.rs b/rust/cloud-storage/mcp_client/src/outbound/pg_server_repo.rs
index 6b142ebee2..02dae4356f 100644
--- a/rust/cloud-storage/mcp_client/src/outbound/pg_server_repo.rs
+++ b/rust/cloud-storage/mcp_client/src/outbound/pg_server_repo.rs
@@ -27,6 +27,7 @@ impl PgServerRepo {
}
}
+ #[tracing::instrument(skip_all, err)]
fn encrypt(&self, creds: &StoredCredentials) -> Result<Vec<u8>, sqlx::Error> {
let plaintext =
serde_json::to_vec(creds).map_err(|e| sqlx::Error::Protocol(e.to_string()))?;
@@ -41,6 +42,7 @@ impl PgServerRepo {
Ok(out)
}
+ #[tracing::instrument(skip_all, err)]
fn decrypt(&self, data: &[u8]) -> Result<StoredCredentials, sqlx::Error> {
if data.len() <= NONCE_LEN {
return Err(sqlx::Error::Decode(
@@ -60,6 +62,7 @@ impl PgServerRepo {
impl McpServerStore for PgServerRepo {
type Err = sqlx::Error;
+ #[tracing::instrument(skip_all, err)]
async fn save(&self, record: &McpServerRecord) -> Result<(), Self::Err> {
let encrypted: Option<Vec<u8>> = record
.credentials
@@ -89,6 +92,7 @@ impl McpServerStore for PgServerRepo {
Ok(())
}
+ #[tracing::instrument(skip_all, err)]
async fn load(
&self,
user_id: &MacroUserIdStr<'static>,
@@ -110,6 +114,7 @@ impl McpServerStore for PgServerRepo {
.transpose()
}
+ #[tracing::instrument(skip_all, err)]
async fn delete(
&self,
user_id: &MacroUserIdStr<'static>,
@@ -129,6 +134,7 @@ impl McpServerStore for PgServerRepo {
Ok(())
}
+ #[tracing::instrument(skip_all, err)]
async fn list(
&self,
user_id: &MacroUserIdStr<'static>,
@@ -152,6 +158,7 @@ impl McpServerStore for PgServerRepo {
}
impl PgServerRepo {
+ #[tracing::instrument(skip_all, err)]
fn to_record(
&self,
user_id: String,
diff --git a/rust/cloud-storage/mcp_client/src/outbound/redis_state_store.rs b/rust/cloud-storage/mcp_client/src/outbound/redis_state_store.rs
index 3eafa8540a..ec9495244d 100644
--- a/rust/cloud-storage/mcp_client/src/outbound/redis_state_store.rs
+++ b/rust/cloud-storage/mcp_client/src/outbound/redis_state_store.rs
@@ -19,6 +19,7 @@ impl RedisOAuthStateStore {
}
impl OAuthStateStore for RedisOAuthStateStore {
+ #[tracing::instrument(skip_all, err)]
async fn save(&self, csrf_token: &str, pending: PendingAuth) -> anyhow::Result<()> {
let key = format!("{KEY_PREFIX}{csrf_token}");
let value = serde_json::to_string(&pending)?;
@@ -31,6 +32,7 @@ impl OAuthStateStore for RedisOAuthStateStore {
Ok(())
}
+ #[tracing::instrument(skip_all, err)]
async fn take(&self, csrf_token: &str) -> anyhow::Result<Option<PendingAuth>> {
let key = format!("{KEY_PREFIX}{csrf_token}");
let mut conn = self
diff --git a/rust/cloud-storage/model_file_type/generated/.gitkeep b/rust/cloud-storage/model_file_type/generated/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000