This document describes the MCP client, which consists of a reusable library and a CLI.
The core of the MCP client is a reusable library located in mcp/client/lib
. This library provides a simple way to connect to an MCP server, discover its tools, and process queries using the Gemini API.
To use the library, import the MCPClient
class and create a new instance. Then, call the connectToServers
method with the server configurations.
import { MCPClient } from './lib/mcp-client'; import { readSettings } from './lib/settings'; const client = new MCPClient('YOUR_API_KEY_HERE'); const settings = await readSettings(); await client.connectToServers(settings.mcpServers); const response = await client.processQuery('What is the weather like in New York?'); console.log(response);
The CLI provides a simple REPL to interact with the MCP.
Install Dependencies: From the root of the repository, run the following command to install the required Node.js packages:
npm install
Configure API Key: Create a .env
file in the root of the repository. Add your Gemini API key to this file:
GEMINI_API_KEY="YOUR_API_KEY_HERE"
The client uses this file to load your API key securely.
Configure Servers: The client reads a list of MCP servers to connect to from ~/.hades/settings.json
. Create this file with the following format:
{ "mcpServers": { "weather": { "command": "node", "args": ["_bazel_bin/mcp/services/weather/index.js"] }, "mainServer": { "command": "bin/mcp_server.py" }, "anotherServer": { "url": "http://another-mcp-server.com" } } }
The mcpServers
object contains a map of server names to server configurations. Each server configuration can have one of the following forms:
url
for a remote server.command
for a local server.command
and args
for a local server with arguments.The client and any services it connects to must be compiled using Bazel.
Build the Client:
bazelisk build //mcp/client/cli:main_ts_lib
Build the Weather Service: To test the client, build the example weather service:
bazelisk build //mcp/services/weather:index_ts_lib
These commands compile the TypeScript code and place the output in the _bazel_bin
directory.
To run the client, you execute its compiled script with node
.
Start the Client: Use the following command from the repository root:
node _bazel_bin/mcp/client/cli/main.js
The client will prompt you to select a server if multiple servers are configured in your settings.json
file.
Interact with the Client: Once running, the client will display a list of tools available from the connected service. You can then type queries for the model to answer. For example:
Query: What is the weather like in New York?
The client will use the Gemini API and the connected service's tools to respond. To exit, type quit
.
Note: The get-forecast
tool requires latitude and longitude as input. For a more seamless experience, you can connect the client to a search MCP server that can provide these coordinates for a given location.