Skip to main content

selfware/mcp/
mod.rs

1#![allow(dead_code, unused_imports, unused_variables)]
2//! Model Context Protocol (MCP) client implementation.
3//!
4//! Enables Selfware to connect to MCP servers (GitHub, Playwright, databases, etc.)
5//! and use their tools as native tools in the agent's tool registry.
6//!
7//! MCP uses JSON-RPC 2.0 over stdio transport. Each server is a child process
8//! that communicates via stdin/stdout.
9
10pub mod client;
11pub mod discovery;
12pub mod server;
13pub mod tool_bridge;
14pub mod transport;
15
16pub use client::McpClient;
17pub use discovery::discover_tools;
18pub use tool_bridge::McpTool;
19pub use transport::{StdioTransport, Transport};
20
21use serde::{Deserialize, Serialize};
22
23/// Configuration for a single MCP server.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct McpServerConfig {
26    /// Human-readable name for this server.
27    pub name: String,
28    /// Command to spawn the server process.
29    pub command: String,
30    /// Arguments to pass to the command.
31    #[serde(default)]
32    pub args: Vec<String>,
33    /// Environment variables to set for the server process.
34    #[serde(default)]
35    pub env: std::collections::HashMap<String, String>,
36    /// Timeout in seconds for server initialization (default: 30).
37    #[serde(default = "default_init_timeout")]
38    pub init_timeout_secs: u64,
39}
40
41fn default_init_timeout() -> u64 {
42    30
43}
44
45/// Top-level MCP configuration section.
46#[derive(Debug, Clone, Default, Serialize, Deserialize)]
47pub struct McpConfig {
48    /// List of MCP servers to connect to.
49    #[serde(default)]
50    pub servers: Vec<McpServerConfig>,
51}