Skip to main content

Crate graphrt_mcp

Crate graphrt_mcp 

Source
Expand description

§graphrt-mcp

Exposes the tools of Model Context Protocol servers to graphrt’s tool and agent nodes.

use graphrt_mcp::{McpServers, connect_all};

let servers: McpServers = serde_json::from_str(r#"{
    "mcpServers": {
        "fs": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"] },
        "remote": { "url": "https://mcp.example.com/mcp", "bearer_token": "..." }
    }
}"#).unwrap_or_default();
let tools = connect_all(&servers.into_configs()).await?;
let services = graphrt_core::Services::new().with(tools);

Each server is registered in the ToolRegistry under both <name> and mcp:<name>, so a tool node can use provider_id: mcp:fs.

Security defaults: stdio servers start with an empty environment except for a few launcher essentials (config::DEFAULT_PASS_ENV) plus explicitly listed variables; every request has a timeout; allowed_tools restricts which tools are exposed.

Re-exports§

pub use config::HttpConfig;
pub use config::McpServerConfig;
pub use config::McpServers;
pub use config::McpTransport;
pub use config::StdioConfig;
pub use runtime::McpError;
pub use runtime::McpToolRuntime;

Modules§

config
MCP server configuration.
content
Mapping between MCP wire types and graphrt tool types.
runtime
McpToolRuntime: a ToolRuntime backed by one MCP server connection.

Constants§

PROVIDER_PREFIX
Prefix of the alias provider name for MCP servers.

Functions§

connect_all
Connect to every server concurrently and build a ToolRegistry. Names are validated first; fails on the first server that cannot be connected.
register
Register a connected server under <name> and mcp:<name>, replacing any provider already registered under those names. Prefer try_register, which refuses to shadow an existing provider.
try_register
Register a connected server under <name> and mcp:<name>. Fails if either name is already taken, so a server can never silently replace another provider (for example one named builtin).
validate_configs
Check server names before connecting: non-empty, no / (tools are referenced as provider/tool), and unique.