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:
1 parent
2f5b263d4e
commit
0d335b808c
18 files changed
+2266
-17
No files matched your search
@@ -116,6 +116,53 @@ async fn create_session(app: &axum::Router) -> String {
|
||||
v["id"].as_str().unwrap().to_string()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_connector_crud_and_validation() {
|
||||
let (app, _store) = build_app().await;
|
||||
// Empty catalog.
|
||||
let (st, text) = req(&app, Method::GET, "/api/mcp/connectors", None).await;
|
||||
assert_eq!(st, StatusCode::OK);
|
||||
assert_eq!(
|
||||
serde_json::from_str::<serde_json::Value>(&text)
|
||||
.unwrap()
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.len(),
|
||||
0
|
||||
);
|
||||
// Upsert; the name is sanitized into a namespace-safe id ("GMail" -> "gmail").
|
||||
let (st, _) = req(
|
||||
&app,
|
||||
Method::PUT,
|
||||
"/api/mcp/connectors/GMail",
|
||||
Some(serde_json::json!({"url":"http://192.168.50.117:8080/","token":"test-token-value"})),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(st, StatusCode::OK);
|
||||
let (_, text) = req(&app, Method::GET, "/api/mcp/connectors", None).await;
|
||||
let v: serde_json::Value = serde_json::from_str(&text).unwrap();
|
||||
assert_eq!(v[0]["name"], "gmail");
|
||||
assert_eq!(v[0]["url"], "http://192.168.50.117:8080/");
|
||||
assert_eq!(v[0]["token"], "test-token-value");
|
||||
// An empty token is rejected.
|
||||
let (st, _) = req(
|
||||
&app,
|
||||
Method::PUT,
|
||||
"/api/mcp/connectors/bad",
|
||||
Some(serde_json::json!({"url":"http://x/","token":""})),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(st, StatusCode::BAD_REQUEST);
|
||||
// Discovery for an unknown connector is a 404 before any network attempt.
|
||||
let (st, _) = req(&app, Method::POST, "/api/mcp/connectors/nope/tools", None).await;
|
||||
assert_eq!(st, StatusCode::NOT_FOUND);
|
||||
// Delete, then deleting again is a 404.
|
||||
let (st, _) = req(&app, Method::DELETE, "/api/mcp/connectors/gmail", None).await;
|
||||
assert_eq!(st, StatusCode::NO_CONTENT);
|
||||
let (st, _) = req(&app, Method::DELETE, "/api/mcp/connectors/gmail", None).await;
|
||||
assert_eq!(st, StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_holds_context_and_persists_usage() {
|
||||
let (app, _store) = build_app().await;
|
||||
|
||||
Reference in new issue
Block a user