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
@@ -0,0 +1,67 @@
|
||||
//! Bounded MCP connectivity spike: connect to ONE external MCP server over
|
||||
//! streamable-HTTP with a Bearer token, discover its tools, print each name +
|
||||
//! read/write hint + the namespaced name the agent would see, then close.
|
||||
//! READ-ONLY: no tool is ever called.
|
||||
//!
|
||||
//! Usage (token passed as an argument; no env vars):
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo run --example mcp_probe -- http://192.168.50.117:8080/ <token> gmail
|
||||
//! ```
|
||||
//!
|
||||
//! The GUI settings picker does the same discovery against the saved catalog;
|
||||
//! this spike is for quick command-line checks.
|
||||
|
||||
use strata_ctl::mcp::{self, ConnectorSpec};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if args.len() < 3 {
|
||||
eprintln!("usage: cargo run --example mcp_probe -- <url> <token> [connector-name]");
|
||||
std::process::exit(2);
|
||||
}
|
||||
let spec = ConnectorSpec {
|
||||
url: args[1].clone(),
|
||||
token: args[2].clone(),
|
||||
name: args.get(3).cloned().unwrap_or_else(|| "gmail".into()),
|
||||
};
|
||||
|
||||
println!("connecting to {} (connector '{}') ...", spec.url, spec.name);
|
||||
let client = match mcp::client::McpClient::connect(&spec, &spec.token).await {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
eprintln!("connect error: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
println!("connected.");
|
||||
|
||||
match client.list_tools().await {
|
||||
Ok(tools) => {
|
||||
println!("discovered {} tools:", tools.len());
|
||||
for t in &tools {
|
||||
let badge = if mcp::is_write_tool(t) {
|
||||
"write"
|
||||
} else {
|
||||
"read "
|
||||
};
|
||||
println!(
|
||||
" [{badge}] {} -> {}",
|
||||
t.name,
|
||||
mcp::namespaced(&spec.name, t.name.as_ref())
|
||||
);
|
||||
if let Some(d) = &t.description {
|
||||
if let Some(first) = d.lines().next() {
|
||||
println!(" {first}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("list error: {e}"),
|
||||
}
|
||||
|
||||
if let Err(e) = client.close().await {
|
||||
eprintln!("close error: {e}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user