1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//! # MCP (Model Context Protocol) Server Registry
//!
//! Rust-based MCP server implementation for ReasonKit.
//!
//! ## Overview
//!
//! This module provides:
//! - **Server Registry**: Dynamic server discovery and registration
//! - **MCP Client**: Connect to and interact with external MCP servers
//! - **Health Monitoring**: Automatic health checks for registered servers
//! - **Tool Management**: Tool capability reporting and execution
//! - **Protocol Compliance**: Full MCP specification support
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ MCP Registry (Coordinator) │
//! │ - Server discovery │
//! │ - Health monitoring │
//! │ - Capability aggregation │
//! ├─────────────────────────────────────────────────────────────┤
//! │ MCP Client (Consumer) │
//! │ - Connect to external MCP servers │
//! │ - Execute tools via RPC │
//! │ - Access resources │
//! ├─────────────────────────────────────────────────────────────┤
//! │ MCP Servers (Multiple instances) │
//! │ - ThinkTool servers (GigaThink, LaserLogic, etc.) │
//! │ - Custom tool servers │
//! │ - Resource providers │
//! ├─────────────────────────────────────────────────────────────┤
//! │ Transport Layer │
//! │ - JSON-RPC 2.0 over stdio (primary) │
//! │ - HTTP/SSE (optional) │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## MCP Protocol
//!
//! Based on MCP specification (2025-11-25):
//! - JSON-RPC 2.0 messaging
//! - Lifecycle management (initialize, shutdown)
//! - Tools, Resources, and Prompts primitives
//! - Progress notifications
//! - Cancellation support
//!
//! ## Example: MCP Client
//!
//! ```rust,ignore
//! use reasonkit::mcp::{McpClient, McpClientConfig, McpClientTrait};
//! use std::collections::HashMap;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // Create client configuration
//! let config = McpClientConfig {
//! name: "sequential-thinking".to_string(),
//! command: "npx".to_string(),
//! args: vec![
//! "-y".to_string(),
//! "@modelcontextprotocol/server-sequential-thinking".to_string()
//! ],
//! env: HashMap::new(),
//! timeout_secs: 30,
//! auto_reconnect: true,
//! max_retries: 3,
//! };
//!
//! // Connect to the server
//! let mut client = McpClient::new(config);
//! client.connect().await?;
//!
//! // List available tools
//! let tools = client.list_tools().await?;
//! println!("Available tools: {:?}", tools);
//!
//! // Call a tool
//! let result = client.call_tool(
//! "think",
//! serde_json::json!({
//! "query": "What is chain-of-thought reasoning?"
//! })
//! ).await?;
//!
//! println!("Result: {:?}", result);
//!
//! // Disconnect
//! client.disconnect().await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Example: Server Registry
//!
//! ```rust,ignore
//! use reasonkit::mcp::{McpRegistry, McpServerConfig, TransportType};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // Create registry
//! let mut registry = McpRegistry::new();
//!
//! // Register a ThinkTool server
//! let config = McpServerConfig {
//! name: "gigathink".to_string(),
//! command: "rk-thinktool".to_string(),
//! args: vec!["--module".to_string(), "gigathink".to_string()],
//! transport: TransportType::Stdio,
//! env: Default::default(),
//! };
//!
//! registry.register_server(config).await?;
//!
//! // Discover all available tools
//! let tools = registry.list_all_tools().await?;
//! for tool in tools {
//! println!("Tool: {} from server {}", tool.name, tool.server);
//! }
//!
//! Ok(())
//! }
//! ```
// ============================================================================
// MCP Modules - OSS/Pro Feature Gating
// ============================================================================
// OSS Modules (always available or with mcp-client feature)
// Pro Modules (require mcp-server-pro feature - license required)
// Optional Modules (additional feature gates)
// Registry requires server module (Pro feature)
// Tool Modules (OSS - ThinkTools are open source)
// ============================================================================
// Re-exports - OSS (always available)
// ============================================================================
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use DeltaToolHandler;
pub use DocsetHandler;
pub use register_docset_tools;
pub use ;
pub use ArchitectAgentHandler;
pub use RustAgentHandler;
pub use register_thinktools;
pub use RerankToolHandler;
// ============================================================================
// Re-exports - Pro (require mcp-server-pro feature)
// ============================================================================
pub use ;
pub use ;
pub use ;
/// MCP protocol version (2025-11-25)
pub const MCP_VERSION: &str = "2025-11-25";
/// Default health check interval (30 seconds)
pub const DEFAULT_HEALTH_CHECK_INTERVAL_SECS: u64 = 30;
/// Maximum server startup timeout (10 seconds)
pub const MAX_SERVER_STARTUP_TIMEOUT_SECS: u64 = 10;