Skip to content

Commit 4776f71

Browse files
atesgoralclaude
andcommitted
Add client conformance tests and fix SSE parser require
Add conformance/client.rb for running MCP client conformance scenarios (initialize, tools_call). Require event_stream_parser in http.rb so SSE responses from the conformance server are parsed correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ae64c6a commit 4776f71

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

conformance/client.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
# Conformance test client for MCP client testing.
4+
#
5+
# Usage: ruby conformance/client.rb <server-url>
6+
#
7+
# The scenario name is read from the MCP_CONFORMANCE_SCENARIO environment variable,
8+
# which is set by the conformance test runner.
9+
10+
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
11+
require "mcp"
12+
require "mcp/client"
13+
require "mcp/client/http"
14+
15+
server_url = ARGV[0]
16+
scenario = ENV["MCP_CONFORMANCE_SCENARIO"]
17+
18+
unless server_url && scenario
19+
warn "Usage: MCP_CONFORMANCE_SCENARIO=<scenario> ruby conformance/client.rb <server-url>"
20+
exit 1
21+
end
22+
23+
transport = MCP::Client::HTTP.new(url: server_url)
24+
client = MCP::Client.new(transport: transport)
25+
26+
case scenario
27+
when "initialize"
28+
client.connect(client_info: { name: "ruby-conformance-client", version: "1.0.0" })
29+
client.tools
30+
client.close
31+
when "tools_call"
32+
client.connect(client_info: { name: "ruby-conformance-client", version: "1.0.0" })
33+
tools = client.tools
34+
tool = tools.find { |t| t.name == "add_numbers" }
35+
if tool
36+
client.call_tool(tool: tool, arguments: { a: 1, b: 2 })
37+
end
38+
client.close
39+
else
40+
warn "Unknown scenario: #{scenario}"
41+
exit 1
42+
end

lib/mcp/client/http.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "event_stream_parser"
4+
35
module MCP
46
class Client
57
# TODO: HTTP GET for SSE streaming is not yet implemented.

0 commit comments

Comments
 (0)