MCP Integration
Connect agents to external tool servers using the Model Context Protocol (MCP).
Configure an MCP server
Add an MCP server to your agent’s configuration in runtime.toml:
[[agents]]
name = "researcher"
wasm_path = "researcher.wasm"
[agents.capabilities]
mcp = true
inference = true
[[agents.mcp_servers]]
name = "web-search"
argv = ["npx", "-y", "@anthropic/mcp-server-web-search"]
[[agents.mcp_servers]]
name = "filesystem"
argv = ["npx", "-y", "@anthropic/mcp-server-filesystem", "/data"]
The argv array specifies the command to start the MCP server process. Akshi
manages the server lifecycle and communicates over stdio.
Call MCP tools from agent code
#![allow(unused)]
fn main() {
// List available tools
let tools = ctx.mcp_list_tools("web-search")?;
// Call a specific tool
let result = ctx.mcp_call("web-search", "search", json!({
"query": "Akshi agent runtime"
}))?;
}
Example: research agent with search
#![allow(unused)]
fn main() {
use akshi_sdk::prelude::*;
struct Researcher;
impl Agent for Researcher {
fn tick(&mut self, ctx: &Context) -> Result<()> {
// Search the web
let results = ctx.mcp_call("web-search", "search", json!({
"query": "latest Rust WASM developments"
}))?;
// Summarize with LLM
let summary = ctx.infer(&format!(
"Summarize these search results:\n{results}"
))?;
// Store in journal
ctx.journal_insert("research-summary", &summary)?;
Ok(())
}
}
export_agent!(Researcher);
}
Multiple MCP servers
An agent can connect to multiple MCP servers. Each is identified by its name
field. Tool names are scoped per server, so tools with the same name on
different servers do not conflict.
Server lifecycle
- MCP servers start when the agent first calls
mcp_list_toolsormcp_call. - Servers are restarted automatically if they crash.
- Servers stop when the agent is unloaded or the runtime shuts down.
- Server stdout/stderr is captured in the runtime logs.