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

+7 -1
View File
@@ -15,7 +15,7 @@ use std::sync::Arc;
use super::anthropic::{self, AnthropicRequest, AnthropicStream};
use super::service::ChatService;
use super::types::{ApiErrorEnvelope, ChatRequest, ModelCard, ModelList};
use super::{files, sessions, uploads, web};
use super::{files, mcp, sessions, uploads, web};
use crate::store::Store;
/// Build the router. Mount this inside any axum `Router` or serve it directly.
@@ -95,6 +95,12 @@ fn build_router(state: AppState, auth: AuthConfig) -> Router {
get(sessions::get_defaults).put(sessions::put_defaults),
)
.route("/api/stats", get(sessions::stats))
.route("/api/mcp/connectors", get(mcp::list_connectors))
.route(
"/api/mcp/connectors/{name}",
axum::routing::put(mcp::upsert_connector).delete(mcp::delete_connector),
)
.route("/api/mcp/connectors/{name}/tools", post(mcp::list_tools))
.route("/", get(web::index))
.route("/assets/{*path}", get(web::asset));
}