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
//! High-performance MCP server implementation using the pmcp SDK
//!
//! This module provides an experimental Model Context Protocol (MCP) server
//! implementation built on top of the pmcp Rust SDK. It offers significant
//! performance improvements and native async/await support compared to the
//! standard implementation.
//!
//! # Features
//!
//! - **10x performance improvement** over the standard MCP implementation
//! - **Type-safe tool handlers** with compile-time validation
//! - **Native async/await** support with tokio
//! - **Built-in transport support** for stdio, WebSocket, and HTTP/SSE
//!
//! # Usage
//!
//! The server is activated by setting the `MCP_VERSION` environment variable
//! (which is what MCP hosts such as Claude Desktop set). That is the only
//! trigger: `detect_execution_mode` in `src/bin/pmat.rs` reads `MCP_VERSION`
//! and nothing else.
//!
//! Two other spellings have been documented here over time and neither works.
//! `PMAT_PMCP_MCP` is read by no code at all. `pmat agent mcp-server` runs a
//! *different* server — `ClaudeCodeAgentMcpServer`, which exposes four
//! agent-monitoring tools rather than these analysis tools — and it is
//! compiled out entirely unless `--features agent-daemon` is set, which is not
//! in `default`.
//!
//! ## Running the pmcp server
//!
//! ```bash
//! MCP_VERSION=1 pmat
//! ```
//!
//! # Example
//!
//! ```rust,no_run
//! use pmat::mcp_pmcp::PmcpServer;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a new pmcp server instance
//! let server = PmcpServer::new();
//!
//! // Run the server on stdio transport
//! server.run().await?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Available Tools
//!
//! The pmcp server implements 24 MCP tools across different categories:
//!
//! ## Analysis Tools
//! - `analyze_complexity` - Analyze code complexity metrics
//! - `analyze_satd` - Detect self-admitted technical debt
//! - `analyze_dead_code` - Find unused code
//! - `analyze_dag` - Generate dependency graphs
//! - `analyze_deep_context` - Comprehensive code analysis
//! - `analyze_big_o` - Big-O complexity analysis
//!
//! ## Refactoring Tools
//! - `refactor.start` - Start a refactoring session
//! - `refactor.nextIteration` - Advance refactoring state
//! - `refactor.getState` - Get current refactoring state
//! - `refactor.stop` - Stop refactoring session
//!
//! ## Quality Tools
//! - `quality_gate` - Run comprehensive quality checks
//! - `quality_proxy` - Proxy code changes through quality gates
//!
//! ## Git Tools
//! - `git_operation` - Perform git operations
//!
//! ## Context Tools
//! - `generate_context` - Generate project context
//! - `generate_template` - Generate file from template
//! - `scaffold_project` - Create project structure
//!
//! ## TDG System Tools (Sprint 31)
//! - `tdg_system_diagnostics` - Comprehensive TDG system diagnostics
//! - `tdg_storage_management` - Manage TDG storage operations
//! - `tdg_analyze_with_storage` - Analyze files with transactional storage
//! - `tdg_performance_metrics` - Real-time performance metrics
//! - `tdg_configure_storage` - Configure and validate storage backends
//! - `tdg_health_check` - Comprehensive system health check
//!
//! # Performance
//!
//! The pmcp implementation provides significant performance benefits:
//!
//! ```rust,ignore
//! // Standard MCP server
//! // Average response time: 50ms
//! // Memory usage: 100MB
//!
//! // pmcp-based server
//! // Average response time: 5ms (10x faster)
//! // Memory usage: 50MB (50% reduction)
//! ```
// Phase 4: Organizational Intelligence Integration
// #648: raw-line stdio transport with honest JSON-RPC errors
// R13/R17/R18 drift guards
// MACS F6 (Component 32): canonical mcp.json source
// KAIZEN-0178: build.rs-generated tool schema registry
// Sprint 65 Phase 2B: MCP git-context integration
// Export the simple unified server as the primary interface
pub use SimpleUnifiedServer as UnifiedServer;
/// Serve MCP on stdio. This is the crate's ONLY MCP stdio entry point.
///
/// Every route that claims to "start the MCP server" goes through here:
/// `MCP_VERSION=1 pmat`, `pmat --mode mcp`, and [`crate::cli::run`] for library
/// embedders. They must serve the same tool inventory, and the only way to
/// guarantee that is for exactly one place to construct the server.
///
/// #696/#697: there used to be three answers to "which server does pmat
/// serve?". `src/bin/pmat.rs` and `cli::run` each built their own
/// [`UnifiedServer`] (same 20 tools, but two independent call sites free to
/// drift), and `pmat::run_mcp_server` — reachable from the library API and
/// exercised by its own test — ran a *different* server whose 21-tool
/// inventory shared only 7 names with this one's 20, took different arguments
/// for those 7 (`project_path` string vs `paths` array), and had 7 tools whose
/// own descriptions read "(unimplemented stub — KAIZEN-0200)" and which return
/// JSON-RPC -32001 when called. That server has been deleted; this is what
/// replaces it.
///
/// The `exactly_one_mcp_stdio_entry_point` test pins the property.
///
/// # Errors
///
/// Returns an error if the server cannot be constructed or the transport fails.
pub async
// Keep PmcpServer for backward compatibility (will be removed)
pub use PmcpServer;
// Export the discovery service for MCP optimization
pub use ;