@@ -3,8 +3,6 @@ package cli
33import (
44 "context"
55 "fmt"
6- "io"
7- "os"
86 "time"
97
108 "mcpproxy-go/internal/config"
@@ -20,26 +18,18 @@ const (
2018 transportStdio = "stdio"
2119)
2220
23- // CLIClient provides a simple interface for CLI operations with enhanced debugging
24- type CLIClient struct {
25- managedClient * managed.ManagedClient
21+ // Client provides a simple interface for CLI operations with enhanced debugging
22+ type Client struct {
23+ managedClient * managed.Client
2624 logger * zap.Logger
2725 config * config.ServerConfig
2826
2927 // Debug output settings
30- debugMode bool
31- stderrMonitor * StderrMonitor
28+ debugMode bool
3229}
3330
34- // StderrMonitor captures and outputs stderr for stdio processes
35- type StderrMonitor struct {
36- reader io.Reader
37- done chan struct {}
38- logger * zap.Logger
39- }
40-
41- // NewCLIClient creates a new CLI client for debugging and simple operations
42- func NewCLIClient (serverName string , globalConfig * config.Config , logLevel string ) (* CLIClient , error ) {
31+ // NewClient creates a new CLI client for debugging and simple operations
32+ func NewClient (serverName string , globalConfig * config.Config , logLevel string ) (* Client , error ) {
4333 // Find server config by name
4434 var serverConfig * config.ServerConfig
4535 for _ , server := range globalConfig .Servers {
@@ -67,12 +57,12 @@ func NewCLIClient(serverName string, globalConfig *config.Config, logLevel strin
6757 }
6858
6959 // Create managed client (which includes Docker-specific optimizations)
70- managedClient , err := managed .NewManagedClient (serverName , serverConfig , logger , logConfig , globalConfig )
60+ managedClient , err := managed .NewClient (serverName , serverConfig , logger , logConfig , globalConfig )
7161 if err != nil {
7262 return nil , fmt .Errorf ("failed to create managed client: %w" , err )
7363 }
7464
75- return & CLIClient {
65+ return & Client {
7666 managedClient : managedClient ,
7767 logger : logger ,
7868 config : serverConfig ,
@@ -81,7 +71,7 @@ func NewCLIClient(serverName string, globalConfig *config.Config, logLevel strin
8171}
8272
8373// Connect establishes connection with detailed progress output
84- func (c * CLIClient ) Connect (ctx context.Context ) error {
74+ func (c * Client ) Connect (ctx context.Context ) error {
8575 c .logger .Info ("🔗 Starting connection to upstream server" ,
8676 zap .String ("server" , c .config .Name ),
8777 zap .String ("transport" , c .getTransportType ()),
@@ -117,7 +107,7 @@ func (c *CLIClient) Connect(ctx context.Context) error {
117107}
118108
119109// ListTools executes tools/list with detailed output
120- func (c * CLIClient ) ListTools (ctx context.Context ) ([]* config.ToolMetadata , error ) {
110+ func (c * Client ) ListTools (ctx context.Context ) ([]* config.ToolMetadata , error ) {
121111 c .logger .Info ("🔍 Discovering tools from server..." )
122112
123113 // Docker containers now use stateless connections with caching in core client
@@ -142,7 +132,7 @@ func (c *CLIClient) ListTools(ctx context.Context) ([]*config.ToolMetadata, erro
142132}
143133
144134// Disconnect closes the connection
145- func (c * CLIClient ) Disconnect () error {
135+ func (c * Client ) Disconnect () error {
146136 c .logger .Info ("🔌 Disconnecting from server..." )
147137
148138 // Note: Stderr monitoring not used with ManagedClient
@@ -157,7 +147,7 @@ func (c *CLIClient) Disconnect() error {
157147}
158148
159149// displayServerInfo shows detailed server information
160- func (c * CLIClient ) displayServerInfo () {
150+ func (c * Client ) displayServerInfo () {
161151 // Get server info from managed client's state
162152 connectionInfo := c .managedClient .StateManager .GetConnectionInfo ()
163153 if connectionInfo .ServerName == "" {
@@ -180,7 +170,7 @@ func (c *CLIClient) displayServerInfo() {
180170}
181171
182172// displayTools shows the discovered tools in a formatted way
183- func (c * CLIClient ) displayTools (tools []* config.ToolMetadata ) {
173+ func (c * Client ) displayTools (tools []* config.ToolMetadata ) {
184174 if len (tools ) == 0 {
185175 c .logger .Warn ("⚠️ No tools discovered from server" )
186176 return
@@ -209,23 +199,8 @@ func (c *CLIClient) displayTools(tools []*config.ToolMetadata) {
209199 fmt .Printf ("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n \n " )
210200}
211201
212- // startStderrMonitoring starts monitoring stderr output for stdio processes
213- func (c * CLIClient ) startStderrMonitoring () {
214- // Note: Stderr monitoring not available with ManagedClient
215- // ManagedClient wraps CoreClient and doesn't expose stderr directly
216- return
217- }
218-
219- // stopStderrMonitoring stops stderr monitoring
220- func (c * CLIClient ) stopStderrMonitoring () {
221- if c .stderrMonitor != nil {
222- close (c .stderrMonitor .done )
223- c .stderrMonitor = nil
224- }
225- }
226-
227202// getTransportType returns the transport type for display
228- func (c * CLIClient ) getTransportType () string {
203+ func (c * Client ) getTransportType () string {
229204 if c .config .Protocol != "" && c .config .Protocol != "auto" {
230205 return c .config .Protocol
231206 }
@@ -241,44 +216,8 @@ func (c *CLIClient) getTransportType() string {
241216 return transportStdio
242217}
243218
244- // Monitor stderr output for stdio processes
245- func (m * StderrMonitor ) monitor () {
246- m .logger .Info ("📡 Starting stderr monitoring..." )
247-
248- buffer := make ([]byte , 4096 )
249- for {
250- select {
251- case <- m .done :
252- m .logger .Info ("🛑 Stderr monitoring stopped" )
253- return
254- default :
255- // Non-blocking read attempt
256- if m .reader != nil {
257- n , err := m .reader .Read (buffer )
258- if err != nil {
259- if err != io .EOF {
260- m .logger .Debug ("Stderr read error" , zap .Error (err ))
261- }
262- time .Sleep (100 * time .Millisecond )
263- continue
264- }
265-
266- if n > 0 {
267- output := string (buffer [:n ])
268- // Output stderr with clear marking
269- fmt .Fprintf (os .Stderr , "🔴 STDERR: %s" , output )
270-
271- // Also log it
272- m .logger .Debug ("Stderr output captured" , zap .String ("content" , output ))
273- }
274- }
275- time .Sleep (10 * time .Millisecond )
276- }
277- }
278- }
279-
280219// CallTool executes a tool (for future CLI extensions)
281- func (c * CLIClient ) CallTool (ctx context.Context , toolName string , args map [string ]interface {}) (* mcp.CallToolResult , error ) {
220+ func (c * Client ) CallTool (ctx context.Context , toolName string , args map [string ]interface {}) (* mcp.CallToolResult , error ) {
282221 c .logger .Info ("🛠️ Calling tool" ,
283222 zap .String ("tool" , toolName ),
284223 zap .Any ("args" , args ))
@@ -299,17 +238,17 @@ func (c *CLIClient) CallTool(ctx context.Context, toolName string, args map[stri
299238}
300239
301240// IsConnected returns connection status
302- func (c * CLIClient ) IsConnected () bool {
241+ func (c * Client ) IsConnected () bool {
303242 return c .managedClient .IsConnected ()
304243}
305244
306245// GetConnectionInfo returns connection information
307- func (c * CLIClient ) GetConnectionInfo () types.ConnectionInfo {
246+ func (c * Client ) GetConnectionInfo () types.ConnectionInfo {
308247 return c .managedClient .StateManager .GetConnectionInfo ()
309248}
310249
311250// GetServerInfo returns server information
312- func (c * CLIClient ) GetServerInfo () * mcp.InitializeResult {
251+ func (c * Client ) GetServerInfo () * mcp.InitializeResult {
313252 // ManagedClient doesn't expose server info directly
314253 // Return nil for now as this isn't used in CLI operations
315254 return nil
0 commit comments