Skip to content

Commit cd8c428

Browse files
authored
Merge pull request #14 from ayakut16/bugfix/proxy
Graceful handling of EOF in MCP proxy server
2 parents 6a4476f + ac4c43b commit cd8c428

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

cmd/mcptools/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ Available types:
850850
- prompt <name> <description> <template>
851851
- resource <uri> <description> <content>
852852
853-
Example:
853+
Example:
854854
mcp mock tool hello_world "when user says hello world, run this tool"
855855
mcp mock tool hello_world "A greeting tool" \
856856
prompt welcome "A welcome prompt" "Hello {{name}}, welcome to {{location}}!" \
@@ -1113,7 +1113,7 @@ Example:
11131113
}
11141114

11151115
// Run proxy server
1116-
fmt.Println("Starting proxy server...")
1116+
fmt.Fprintln(os.Stderr, "Starting proxy server...")
11171117
if err := proxy.RunProxyServer(config); err != nil {
11181118
log.Fatalf("Error running proxy server: %v", err)
11191119
}

pkg/proxy/proxy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ func (s *Server) Start() error {
319319
if err := decoder.Decode(&request); err != nil {
320320
if err == io.EOF {
321321
s.log("Client disconnected (EOF)")
322-
} else {
323-
s.log(fmt.Sprintf("Error decoding request: %v", err))
322+
return nil
324323
}
324+
s.log(fmt.Sprintf("Error decoding request: %v", err))
325325
fmt.Fprintf(os.Stderr, "Error decoding request: %v\n", err)
326326
return fmt.Errorf("error decoding request: %w", err)
327327
}
@@ -568,9 +568,9 @@ func RunProxyServer(toolConfigs map[string]map[string]string) error {
568568
}
569569

570570
// Print registered tools
571-
fmt.Println("Registered proxy tools:")
571+
fmt.Fprintln(os.Stderr, "Registered proxy tools:")
572572
for name, tool := range server.tools {
573-
fmt.Printf("- %s: %s (script: %s)\n", name, tool.Description, tool.ScriptPath)
573+
fmt.Fprintf(os.Stderr, "- %s: %s (script: %s)\n", name, tool.Description, tool.ScriptPath)
574574
paramStr := ""
575575
for i, param := range tool.Parameters {
576576
if i > 0 {
@@ -579,7 +579,7 @@ func RunProxyServer(toolConfigs map[string]map[string]string) error {
579579
paramStr += param.Name + ":" + param.Type
580580
}
581581
if paramStr != "" {
582-
fmt.Printf(" Parameters: %s\n", paramStr)
582+
fmt.Fprintf(os.Stderr, " Parameters: %s\n", paramStr)
583583
}
584584
}
585585

0 commit comments

Comments
 (0)