exfiltrate 0.1.0

An embeddable MCP server for Rust.
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
use exfiltrate::mcp::tools::{Argument, InputSchema, ToolCallResponse};
use std::collections::HashMap;
#[cfg(not(target_arch = "wasm32"))]
use std::time;
#[cfg(target_arch = "wasm32")]
use web_time as time;

pub struct MyTool {}
impl exfiltrate::mcp::tools::Tool for MyTool {
    fn name(&self) -> &str {
        "my_tool"
    }

    fn description(&self) -> &str {
        "A tool that does something"
    }

    fn call(
        &self,
        params: HashMap<String, serde_json::Value>,
    ) -> Result<ToolCallResponse, exfiltrate::mcp::tools::ToolCallError> {
        let params = params
            .get("input")
            .and_then(|v| v.as_f64())
            .ok_or_else(|| {
                exfiltrate::mcp::tools::ToolCallError::new(vec!["Invalid input parameter".into()])
            })?;
        Ok(ToolCallResponse::new(vec![
            format!("This is a response from my tool: {}", params).into(),
        ]))
    }
    fn input_schema(&self) -> exfiltrate::mcp::tools::InputSchema {
        InputSchema::new(vec![Argument::new(
            "input".to_string(),
            "number".to_string(),
            "Your favorite number".to_string(),
            true,
        )])
    }
}

pub struct EventualTool {}
impl exfiltrate::mcp::tools::Tool for EventualTool {
    fn name(&self) -> &str {
        "eventual_tool"
    }

    fn description(&self) -> &str {
        "A tool that arrives late"
    }

    fn call(
        &self,
        params: HashMap<String, serde_json::Value>,
    ) -> Result<ToolCallResponse, exfiltrate::mcp::tools::ToolCallError> {
        let params = params
            .get("input")
            .and_then(|v| v.as_f64())
            .ok_or_else(|| {
                exfiltrate::mcp::tools::ToolCallError::new(vec!["Invalid input parameter".into()])
            })?;
        Ok(ToolCallResponse::new(vec![
            format!("This is a response from my tool: {}", params).into(),
        ]))
    }
    fn input_schema(&self) -> exfiltrate::mcp::tools::InputSchema {
        InputSchema::new(vec![Argument::new(
            "input".to_string(),
            "number".to_string(),
            "Your favorite number".to_string(),
            true,
        )])
    }
}

fn main() {
    let proxy = exfiltrate::transit::transit_proxy::TransitProxy::new();
    let _server = exfiltrate::transit::http::Server::new("127.0.0.1:1984", proxy);
    exfiltrate::mcp::tools::add_tool(Box::new(MyTool {}));
    std::thread::sleep(time::Duration::from_secs(10));
    //insert a new tool
    exfiltrate::mcp::tools::add_tool(Box::new(EventualTool {}));
    eprintln!("Added late tool");
    std::thread::sleep(time::Duration::from_secs(1000));
}