Skip to main content

selfware/mcp/
mod.rs

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