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
use crate;
use cratehandlers;
use crateStateManager;
use crate;
use json;
use DefaultHasher;
use ;
use Arc;
use Duration;
use ;
use Mutex;
use ;
/// Model Context Protocol (MCP) server for PMAT refactoring capabilities.
///
/// This server implements the MCP specification for AI-assisted refactoring,
/// providing a standardized interface for Claude and other AI models to interact
/// with PMAT's analysis and refactoring capabilities. Critical for maintaining
/// MCP protocol compliance and preventing API drift.
///
/// # MCP Protocol Support
///
/// - **Protocol Version**: 2024-11-05
/// - **Transport**: JSON-RPC 2.0 over stdin/stdout
/// - **Capabilities**: Refactoring state machine control
/// - **Error Handling**: Standard JSON-RPC error codes
///
/// # Supported Methods
///
/// ## Core Protocol Methods
/// - `initialize` - Initialize MCP session with capabilities
///
/// ## Refactoring Methods
/// - `refactor.start` - Start new refactoring session
/// - `refactor.nextIteration` - Advance refactoring state machine
/// - `refactor.getState` - Get current refactoring state
/// - `refactor.stop` - Stop current refactoring session
///
/// # State Management
///
/// The server maintains refactoring sessions with:
/// - Target files and configuration
/// - State machine progression (Scan -> Analyze -> Plan -> Refactor -> Complete)
/// - Session isolation and cleanup
/// - Error recovery and rollback
///
/// # Examples
///
/// ```rust,no_run
/// use pmat::mcp_server::server::McpServer;
///
/// # tokio_test::block_on(async {
/// // Create MCP server
/// let server = McpServer::new();
///
/// // Server is ready for MCP communication
/// // In real usage, server.run().await would handle stdin/stdout
/// # });
/// ```
///
/// # MCP Message Examples
///
/// ## Initialize Request
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "id": 1,
/// "method": "initialize",
/// "params": {
/// "protocolVersion": "2024-11-05",
/// "clientInfo": {
/// "name": "claude-desktop",
/// "version": "1.0.0"
/// }
/// }
/// }
/// ```ignore
///
/// ## Refactor Start Request
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "id": 2,
/// "method": "refactor.start",
/// "params": {
/// "targets": ["/path/to/file.rs"],
/// "config": {
/// "target_complexity": 15,
/// "remove_satd": true
/// }
/// }
/// }
/// ```ignore
///
/// ## State Query Request
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "id": 3,
/// "method": "refactor.getState"
/// }
/// ```ignore
// MCP protocol communication: run loop, request handling, and cache metrics
include!;
// Tests: property tests and coverage tests
include!;