Building an MCP Client
The MCP::Client class provides an interface for interacting with MCP servers.
This class supports:
- Lifecycle negotiation and connection via
MCP::Client#connect, adopting the modern lifecycle when the server serves it; see Lifecycle - Server discovery via the
server/discovermethod (MCP::Client#discover); see Explicit Discovery - Liveness check via the
pingmethod (MCP::Client#ping), and automatic answers to server pings; see Answering Server Pings - Tool listing via the
tools/listmethod (MCP::Client#tools) - Tool invocation via the
tools/callmethod (MCP::Client#call_tool) - Resource listing via the
resources/listmethod (MCP::Client#resources) - Resource template listing via the
resources/templates/listmethod (MCP::Client#resource_templates) - Resource reading via the
resources/readmethod (MCP::Client#read_resource) - Skills (SEP-2640) via the
skills/listandskills/getmethods and digest-verified reads (MCP::Client#list_skills,#get_skill,#read_skill_resource), see Skills - Prompt listing via the
prompts/listmethod (MCP::Client#prompts) - Prompt retrieval via the
prompts/getmethod (MCP::Client#get_prompt) - Completion requests via the
completion/completemethod (MCP::Client#complete); see Completion - Automatic driving of multi round-trip
input_requiredresults onceon_elicitation,on_sampling, oron_rootshandlers are registered; see Multi Round-Trip Requests - Cancellation of in-flight requests via the
cancellation:keyword; see Cancellation - Cursor-based page iteration on the
list_*methods and whole-collection fetching with themax_pagesguard; see Pagination - Automatic JSON-RPC 2.0 message formatting
- UUID request ID generation
Clients are initialized with a transport layer instance that handles the low-level communication mechanics. Authorization is handled by the transport layer; see Authorization.
Tool Objects
The client provides a wrapper class for tools returned by the server:
MCP::Client::Tool- Represents a single tool with its metadata
This class provides easy access to tool properties like name, description, input schema, and output schema. title, annotations, icons, execution, and meta (the tool’s _meta) are kept as the server sent them, so what an extension puts under _meta is readable: an MCP Apps host finds a tool’s app under tool.meta&.dig("ui", "resourceUri"). These values are untrusted input from the server: the SDK passes them through without acting on them, and a host that renders icons or loads what _meta names treats them as it would any server-supplied URL or content.