klieo-tools-mcp 3.3.0

MCP (Model Context Protocol) adapter for klieo-core's Tool trait.
Documentation

klieo-tools-mcp

MCP (Model Context Protocol) adapter for klieo-core's Tool trait.

Part of the klieo Rust agent framework.

Features

  • Wraps any MCP server's tools as Arc<dyn Tool> ready to register in klieo
  • stdio transport (subprocess) supported; HTTP/SSE transports planned
  • Schema and argument pass-through — the MCP server's JSON schema is used as-is
  • Tool names are namespaced as mcp:<server_id>.<original_name>
  • Secure-by-default subprocess spawning: child receives an empty environment unless you explicitly allowlist variables via StdioConnectOptions

Usage

[dependencies]
klieo-tools-mcp = "3"

Connect to an MCP server via stdio

use klieo_tools_mcp::{McpServerId, McpToolset, StdioConnectOptions};
use klieo_tools::ChainedInvoker;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Connect to an MCP server subprocess and pull its tool catalogue.
    let tools = McpToolset::connect_stdio(
        McpServerId::new("filesystem"),
        "npx",
        StdioConnectOptions {
            args: vec![
                "-y".into(),
                "@modelcontextprotocol/server-filesystem".into(),
                "/tmp".into(),
            ],
            ..Default::default()
        },
    )
    .await?;

    let mut invoker = ChainedInvoker::new();
    for tool in tools {
        invoker = invoker.with_tool(tool)?;
    }
    Ok(())
}

Forwarding environment variables to the subprocess

use klieo_tools_mcp::StdioConnectOptions;

// Forward only the variables the MCP server needs.
let opts = StdioConnectOptions {
    args: vec!["--port".into(), "3000".into()],
    env_allowlist: Some(vec!["HOME".into(), "PATH".into()]),
    working_dir: None,
};

Security note: the default empty allowlist prevents leaking API keys or cloud credentials to untrusted MCP server subprocesses. Call StdioConnectOptions::inherit_parent_env() only for servers you fully control.

Status

3.x — stable. See docs/SEMVER.md.

License

MIT — see LICENSE.