@@ -193,6 +193,10 @@ mcpproxy implements comprehensive per-upstream-server logging to facilitate debu
193193- Main application log: ` main.log `
194194- Per-server logs: ` server-{name}.log `
195195
196+ ** Debug Commands:**
197+ - ` mcpproxy tools list --server=NAME --log-level=trace ` : Debug individual server connections
198+ - Enhanced trace logging shows all JSON-RPC frames and transport details
199+
196200** Log Rotation:**
197201- Automatic rotation based on file size (10MB default)
198202- Configurable retention (5 backup files, 30 days default)
@@ -212,6 +216,136 @@ mcpproxy implements comprehensive per-upstream-server logging to facilitate debu
212216* Auto‑update channel.
213217* GUI front‑end built with Wails.
214218
219+ ## 12 Client Architecture (Refactored)
220+
221+ ### 12.1 Modular Client Design
222+
223+ The upstream client architecture has been refactored into three distinct layers for better separation of concerns, testability, and reusability:
224+
225+ ```
226+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
227+ │ CLI Client │ │ Managed Client │ │ Core Client │
228+ │ │ │ │ │ │
229+ │ • CLI-specific │ ──▶│ • State mgmt │ ──▶│ • Basic MCP │
230+ │ • Debug output │ │ • Concurrency │ │ • Connection │
231+ │ • Tool display │ │ • Background │ │ • Auth fallback │
232+ │ • Stderr monitor│ │ recovery │ │ • No state │
233+ └─────────────────┘ └─────────────────┘ └─────────────────┘
234+ ```
235+
236+ ** Core Interfaces:**
237+ ``` go
238+ // MCPClient - Basic MCP operations
239+ type MCPClient interface {
240+ Connect (ctx context.Context ) error
241+ Disconnect () error
242+ IsConnected () bool
243+ ListTools (ctx context.Context ) ([]*config.ToolMetadata , error )
244+ CallTool (ctx context.Context , toolName string , args map [string ]interface {}) (*mcp.CallToolResult , error )
245+ GetConnectionInfo () types.ConnectionInfo
246+ GetServerInfo () *mcp.InitializeResult
247+ }
248+
249+ // StatefulClient - Adds state management
250+ type StatefulClient interface {
251+ MCPClient
252+ GetState () types.ConnectionState
253+ IsConnecting () bool
254+ ShouldRetry () bool
255+ SetStateChangeCallback (callback func (oldState, newState types.ConnectionState , info *types.ConnectionInfo ))
256+ }
257+ ```
258+
259+ ### 12.2 Core Client (` internal/upstream/core/ ` )
260+
261+ ** Purpose:** Minimal, stateless MCP client implementation
262+ - ** Responsibility:** Direct MCP protocol communication
263+ - ** Features:**
264+ - Transport-agnostic (HTTP, SSE, stdio)
265+ - Authentication fallback (headers → no-auth → OAuth)
266+ - Environment variable filtering for stdio processes
267+ - No background processes or state management
268+
269+ ** Key Components:**
270+ - ` client.go ` : Main client implementation
271+ - ` auth.go ` : Authentication strategies and fallback logic
272+
273+ ### 12.3 Managed Client (` internal/upstream/managed/ ` )
274+
275+ ** Purpose:** Stateful wrapper for daemon/long-running use
276+ - ** Responsibility:** Production-ready client for ` mcpproxy serve `
277+ - ** Features:**
278+ - Connection state machine with retry logic
279+ - Background health monitoring and recovery
280+ - Concurrency control for ListTools operations
281+ - Exponential backoff for failed connections
282+ - State change notifications
283+
284+ ** Key Features:**
285+ ``` go
286+ type ManagedClient struct {
287+ coreClient *core.CoreClient
288+ StateManager *types.StateManager
289+ // Concurrency control
290+ listToolsMu sync.Mutex
291+ // Background monitoring
292+ stopMonitoring chan struct {}
293+ }
294+ ```
295+
296+ ### 12.4 CLI Client (` internal/upstream/cli/ ` )
297+
298+ ** Purpose:** Specialized client for CLI debugging operations
299+ - ** Responsibility:** Enhanced debugging for ` mcpproxy tools list `
300+ - ** Features:**
301+ - Detailed output formatting with emojis
302+ - JSON-RPC frame logging at trace level
303+ - Stderr monitoring for stdio processes
304+ - Single-shot operations (connect → list → disconnect)
305+
306+ ** Debug Output Features:**
307+ - ** Transport Details:** All JSON-RPC request/response frames
308+ - ** Stderr Capture:** Real-time stderr output from stdio processes
309+ - ** Connection Events:** Detailed state transitions and timing
310+ - ** Error Context:** Enhanced error messages with troubleshooting hints
311+
312+ ### 12.5 Shared Types (` internal/upstream/types/ ` )
313+
314+ ** Purpose:** Common data structures to break import cycles
315+ - ** Connection States:** ` Disconnected ` , ` Connecting ` , ` Authenticating ` , ` Discovering ` , ` Ready ` , ` Error `
316+ - ** State Manager:** Handles state transitions, retry logic, and callbacks
317+ - ** Connection Info:** Detailed connection metadata and error tracking
318+
319+ ** State Machine:**
320+ ```
321+ Disconnected ──▶ Connecting ──▶ Authenticating ──▶ Discovering ──▶ Ready
322+ ▲ │ │ │ │
323+ └────────────────┴───────────────┴───────────────┴────────────┘
324+ Error
325+ ```
326+
327+ ### 12.6 Benefits of Refactored Architecture
328+
329+ 1 . ** Separation of Concerns:**
330+ - Core: Pure MCP protocol implementation
331+ - Managed: Production state management
332+ - CLI: Debug-focused single operations
333+
334+ 2 . ** Reusability:**
335+ - Core client shared between managed and CLI variants
336+ - State management logic isolated and testable
337+ - Transport logic decoupled from application logic
338+
339+ 3 . ** Testability:**
340+ - Each layer can be unit tested independently
341+ - Mock interfaces for integration testing
342+ - Isolated state machine testing
343+
344+ 4 . ** Maintainability:**
345+ - Clear responsibilities and boundaries
346+ - Smaller, focused code files
347+ - Type-safe interfaces between layers
348+
215349## Upstream Server Management
216350
217351### Dynamic Server Configuration
0 commit comments