MCP::Client
Inherits Reference < Object
Main client class for communicating with MCP servers.
client = MCP::Client.new("npx", ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"])
client.connect
tools = client.list_tools
result = client.call_tool("read_file", {"path" => JSON::Any.new("/path/to/file.txt")})
client.disconnect
Constructors
new(command : String, args : Array(String) = [] of String, client_name : String = "mcp-crystal-client", client_version : String = MCP::VERSION)
Create a client with STDIO transport (convenience constructor).
Instance methods
call_tool(name : String, arguments : Hash(String, JSON::Any)) : ToolCallResult
Call a tool with the given arguments.
Arguments should be a Hash with JSON::Any values.
Raises MCPToolError if the tool call fails.
connect
Connect to the server and perform initialization handshake.
Returns the server's information.
list_tools
List available tools from the server.
Raises MCPProtocolError if the server doesn't support tools.
ping
Send a ping to the server to check connectivity.
Returns true if the server responds successfully.
server_capabilities
Get the server's capabilities.
Returns nil if not connected or capabilities not yet negotiated.
supports_logging?
Sourcesupports_prompts?
Sourcesupports_resources?
Source