Skip to main content

a3s_code_core/mcp/
mod.rs

1//! MCP (Model Context Protocol) Support
2//!
3//! Provides integration with MCP servers for extending A3S Code with external tools.
4//!
5//! ## Overview
6//!
7//! MCP is an open protocol for connecting AI assistants to external tools and data sources.
8//! This module implements:
9//!
10//! - **Protocol types**: JSON-RPC messages, tool definitions, resources
11//! - **Transport layer**: stdio (local processes), HTTP+SSE (remote servers)
12//! - **Client**: High-level API for MCP server communication
13//! - **Manager**: Lifecycle management for multiple MCP servers
14//! - **Tools integration**: Automatic registration of MCP tools to ToolRegistry
15//!
16//! ## Usage
17//!
18//! ```rust,ignore
19//! use a3s_code::mcp::{McpManager, McpServerConfig, McpTransportConfig};
20//!
21//! // Create manager
22//! let manager = McpManager::new();
23//!
24//! // Register server
25//! let config = McpServerConfig {
26//!     name: "github".to_string(),
27//!     transport: McpTransportConfig::Stdio {
28//!         command: "npx".to_string(),
29//!         args: vec!["-y".to_string(), "@modelcontextprotocol/server-github".to_string()],
30//!     },
31//!     enabled: true,
32//!     env: [("GITHUB_TOKEN".to_string(), "...".to_string())].into(),
33//!     oauth: None,
34//! };
35//! manager.register_server(config).await;
36//!
37//! // Connect
38//! manager.connect("github").await?;
39//!
40//! // Get tools
41//! let tools = manager.get_all_tools().await;
42//! // tools: [("mcp__github__create_issue", McpTool { ... }), ...]
43//!
44//! // Call tool
45//! let result = manager.call_tool("mcp__github__create_issue", Some(json!({
46//!     "title": "Bug report",
47//!     "body": "Description..."
48//! }))).await?;
49//! ```
50//!
51//! ## Tool Naming Convention
52//!
53//! MCP tools are registered with the prefix `mcp__<server>__<tool>`:
54//!
55//! | Full Name | Server | Tool |
56//! |-----------|--------|------|
57//! | `mcp__github__create_issue` | github | create_issue |
58//! | `mcp__postgres__query` | postgres | query |
59
60pub mod client;
61pub mod manager;
62pub mod protocol;
63pub mod tools;
64pub mod transport;
65
66pub use client::McpClient;
67pub use manager::{tool_result_to_string, McpManager, McpServerStatus};
68pub use protocol::{
69    CallToolResult, McpNotification, McpResource, McpServerConfig, McpTool, McpTransportConfig,
70    OAuthConfig, ServerCapabilities, ToolContent,
71};
72pub use tools::{create_mcp_tools, McpToolWrapper};