ExMCP.Client (ex_mcp v0.1.0)
View SourceMCP client for connecting to Model Context Protocol servers.
The client handles:
- Connection management with automatic reconnection
- Request/response correlation
- Protocol message encoding/decoding
- Concurrent request handling
Example
# Connect to a filesystem server
{:ok, client} = ExMCP.Client.start_link(
transport: :stdio,
command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
name: :fs_client
)
# List available tools
{:ok, tools} = ExMCP.Client.list_tools(client)
# Call a tool
{:ok, result} = ExMCP.Client.call_tool(client, "read_file", %{
"path" => "/tmp/example.txt"
})
Summary
Functions
Calls a tool with the given arguments.
Returns a specification to start this module under a supervisor.
Gets a prompt with the given arguments.
Lists available prompts from the server.
Lists available resources from the server.
Lists available tools from the server.
Reads a resource by URI.
Gets server capabilities.
Gets server information.
Starts an MCP client.
Functions
@spec call_tool(GenServer.server(), String.t(), map(), timeout()) :: {:ok, ExMCP.Types.tool_result()} | {:error, any()}
Calls a tool with the given arguments.
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec get_prompt(GenServer.server(), String.t(), map(), timeout()) :: {:ok, ExMCP.Types.prompt_message()} | {:error, any()}
Gets a prompt with the given arguments.
@spec list_prompts(GenServer.server(), timeout()) :: {:ok, [ExMCP.Types.prompt()]} | {:error, any()}
Lists available prompts from the server.
@spec list_resources(GenServer.server(), timeout()) :: {:ok, [ExMCP.Types.resource()]} | {:error, any()}
Lists available resources from the server.
@spec list_tools(GenServer.server(), timeout()) :: {:ok, [ExMCP.Types.tool()]} | {:error, any()}
Lists available tools from the server.
@spec read_resource(GenServer.server(), String.t(), timeout()) :: {:ok, ExMCP.Types.resource_content()} | {:error, any()}
Reads a resource by URI.
@spec server_capabilities(GenServer.server()) :: {:ok, ExMCP.Types.capabilities()} | {:error, :not_initialized}
Gets server capabilities.
@spec server_info(GenServer.server()) :: {:ok, ExMCP.Types.server_info()} | {:error, :not_initialized}
Gets server information.
Starts an MCP client.
Options
:transport
- Transport type (:stdio, :sse, or module):name
- GenServer name (optional):client_info
- Client information map with :name and :version
Transport-specific options are passed through.