Skip to content

Commit 72f6bfb

Browse files
Kenoclaude
andcommitted
Fix stdio mode: write responses to stdout, not stdin
In stdio mode, the server should read from stdin and write to stdout. Previously, we were passing stdin as the client and writing to it, which doesn't work. Now we detect when client is stdin and write responses to stdout instead. This fixes the issue where the server would close immediately after sending the first response. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 52eaaa8 commit 72f6bfb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/server.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ function handle_client_connection(client::IO, server::ClaudeMCPTools.MCPServer;
122122
end
123123

124124
# Send response
125-
println(client, json_response)
126-
flush(client)
125+
# In stdio mode, read from stdin but write to stdout
126+
output_stream = (client === stdin) ? stdout : client
127+
println(output_stream, json_response)
128+
flush(output_stream)
127129
catch e
128130
# Only send error response if it's not a notification
129131
if request !== nothing && haskey(request, "id")
@@ -135,8 +137,10 @@ function handle_client_connection(client::IO, server::ClaudeMCPTools.MCPServer;
135137
),
136138
"id" => request["id"]
137139
)
138-
println(client, JSON.json(error_response))
139-
flush(client)
140+
# In stdio mode, read from stdin but write to stdout
141+
output_stream = (client === stdin) ? stdout : client
142+
println(output_stream, JSON.json(error_response))
143+
flush(output_stream)
140144
end
141145
end
142146
end

0 commit comments

Comments
 (0)