quickstart-resources/mcp-client-ruby/README.md
olaservo 4d79997120 Correct README claims that do not match the repo
The License section named MIT. LICENSE is a transition file: new code
contributions are Apache-2.0, documentation excluding specifications is
CC-BY-4.0, and only earlier contributions without relicensing consent
stay MIT.

"Rust (stable)" understates the floor. rmcp, darling and time declare
rust-version 1.88, and cargo metadata resolves both crates to 1.88.

The Ruby aside said 3.3 also satisfies the gems. anthropic requires
>= 3.2.0 and mcp >= 2.7.0, so the gem floor was 3.2, and 3.2 reached EOL
on 2026-03-31. CI runs 3.4, which is what the READMEs now state.

The Go and Rust clients take a command plus arguments, not a path to a
server script.

Removed the commit-message convention, which is attributed to the MCP
contributing guidelines but does not appear in them. Added the
AI_POLICY.md link that CONTRIBUTING.md points to.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GdvHa5MzDw33PEz3DbTaJD
2026-08-28 10:51:08 -07:00

2 KiB

An LLM-Powered Chatbot MCP Client written in Ruby

An interactive chatbot MCP client: it launches an MCP server over stdio, lists its tools, and hands them to Claude, which can call them while answering your questions.

This example accompanies the Build an MCP client tutorial.

Prerequisites

Setup

Install the gems, then put your API key in a .env file (or export ANTHROPIC_API_KEY in your shell):

bundle install
cp .env.example .env
# then edit .env and add your key

Run the client

Pass the path to a server script. .rb servers are launched with ruby, .py with python3, and .js with node:

bundle exec ruby client.rb ../weather-server-ruby/weather.rb

Type a question (for example, "What's the weather in Sacramento?") and Claude answers using the server's tools. Type quit to exit.

Without an ANTHROPIC_API_KEY, the client still connects, prints the server's tools, and exits — useful for verifying the MCP wiring without credentials.

Structured content

The spec says clients SHOULD validate structured results against the schema the tool declares, and this SDK's client does not do it for you — MCP::Client::Tool#output_schema hands back the raw schema from the wire and nothing checks results against it. So the client compiles each declared schema once at connect time with MCP::Tool::OutputSchema.new and validates every non-error result.

The two channels go to different readers: content is forwarded to the model, while structured_content is used as data — when a tool returns an array, the client counts its items rather than re-reading the prose. See Structured Content.

MCP::Client::Stdio offers 2026-07-28 by default, so no negotiation setup is needed here.