agent: wire MCP connectors into the loop (rmcp v3, Initialize lifecycle)

- src/mcp: streamable-HTTP client (rmcp v3.12) negotiating Initialize +
  LATEST_WITH_INITIALIZE; namespaced mcp__{connector}__{tool} surface, write
  badges from ToolAnnotations, persisted discovery (tools_json) so the agent
  tool declarations stay byte-stable for KV-cache reuse.
- store: mcp_connectors catalog + tools_json column (idempotent migration) and
  set_mcp_tools; per-session per-tool allowlist (SessionSettings.mcp_enabled).
- agent: execute_mcp routes namespaced calls, gated on the session allowlist
  before any network call; Bearer token comes from the DB catalog, never echoed.
- api/sessions: build the MCP surface into Ambient + the agent tool declarations
  on both the turn and prewarm paths (identical rebuild keeps the prefix stable).
- api/mcp + GUI: connector CRUD, tool-discovery picker, per-session enable.
- examples/mcp_probe: read-only CLI discovery spike.

Live-verified: 22 gmail tools discovered, gmail_labels returned 25 labels, and a
full model-driven GUI turn (7 enabled tools) with a 9197-token RESUME cache hit.
This commit is contained in:
adm committed 2026-11-30 02:29:55 +01:00
1 parent 2f5b263d4e
commit 0d335b808c
18 files changed
+2266 -17

No files matched your search

+36 -1
View File
@@ -307,7 +307,7 @@ details.thinking .reasoning {
.queue-chip button:hover { color: var(--danger); }
/* ---- Stats modal ---- */
#stats-modal, #dialog, #settings-modal, #notepad-modal {
#stats-modal, #dialog, #settings-modal, #notepad-modal, #mcp-picker-modal {
position: fixed; inset: 0; z-index: 40;
background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center;
padding: 20px;
@@ -317,6 +317,8 @@ details.thinking .reasoning {
padding: 20px; max-width: 420px; width: 100%;
}
.modal-card h2 { margin: 0 0 12px; font-size: 1.1rem; }
/* The MCP tool picker lists many tools with descriptions: give it room to scroll. */
#mcp-picker-modal .modal-card { width: min(560px, 100%); max-width: 560px; max-height: 85dvh; overflow-y: auto; }
/* ---- Stats dashboard ---- */
.stats-card {
@@ -454,4 +456,37 @@ details.thinking .reasoning {
background: var(--accent);
}
#splitter:focus-visible { outline: none; }
}
/* ---- MCP connectors / tool picker (settings) ---- */
.mcp-block { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.mcp-block h3 { margin: 0 0 4px; font-size: 0.95rem; }
.mcp-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.mcp-row {
display: flex; align-items: center; justify-content: space-between; gap: 8px;
padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
}
.mcp-row-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mcp-name { font-weight: 600; }
.mcp-url, .mcp-token { font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; }
.mcp-count { font-size: 0.75rem; color: var(--muted); }
.mcp-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mcp-add { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mcp-add input {
flex: 1 1 140px; min-width: 0; padding: 8px; font-size: 0.85rem;
background: var(--panel); border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.mcp-picker-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; margin: 8px 0; }
.mcp-tool {
display: flex; align-items: flex-start; gap: 8px; padding: 8px;
background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.mcp-tool input { margin-top: 3px; flex-shrink: 0; }
.mcp-tool-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mcp-tool-name { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mcp-tool-desc { font-size: 0.75rem; color: var(--muted); overflow-wrap: anywhere; }
.mcp-write-badge {
font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.03em;
padding: 1px 6px; border-radius: 999px; color: var(--danger);
border: 1px solid var(--danger); background: transparent;
}