mcp-client-agent
by: shane-kercheval
CLI that uses DSPy to interact with MCP servers.
📌Overview
Purpose: The MCP-Agent CLI is designed to provide an interactive experience for users to engage with MCP servers, enabling autonomous task execution through DSPy framework integration.
Overview: The MCP-Agent is a command-line interface that utilizes the DSPy agent to interact with defined tools on MCP servers. Mimicking the functionality of Claude Desktop, it autonomously processes user requests using a configuration that lists available server tools, facilitating easy tool access across multiple servers.
Key Features:
-
Autonomous Communication: The agent can autonomously interact with multiple MCP servers based on the configurations provided, allowing it to solve tasks iteratively.
-
Tool Integration: Supports interaction with tools like
count_characters
andcalculator_multiply
, enabling complex operations with minimal user input. -
Simple Setup: Set up is straightforward, requiring only a configuration file and an API key, making it accessible for users to start quickly.
-
CLI Commands: Includes essential commands in a Makefile to build and start the server, streamlining the execution process for users.
MCP-Agent
./clients/mcp_client.py
is a CLI that uses DSPy to interact with MCP servers. It aims to provide a similar experience to Claude Desktop. The DSPy agent uses tool definitions from MCP server(s) to autonomously and iteratively use tools to fulfill user requests.
The CLI accepts a configuration file in the same format as Claude Desktop and loads all servers listed in the config. Tools from all servers become available for the agent.
Running the Project
Useful commands for running the project can be found in the Makefile
.
Quickstart
- Create a
.env
file in the project directory and add yourOPENAI_API_KEY
. - Adjust the path
/Users/shanekercheval/repos/mcp-client-agent/servers
in./servers/mcp_fake_server_config.json
as needed. - Run
make build
. - Run
make chat
:- Starts the
chat
CLI command using./servers/mcp_fake_server_config.json
config to start the MCP Server./servers/mcp_fake_server.py
. - This MCP server contains simple tools such as
count_characters
andcalculator_multiply
. - The command uses
openai/gpt-4o-mini
as the model and requiresOPENAI_API_KEY
to be set in.env
.
- Starts the
Example
Using the make chat
command with mcp_fake_server.py
:
Multiply the number of characters in the following two texts:
"Lorem ipsum odor amet, consectetuer adipiscing elit. Nisl ligula molestie nec a sodales morbi vel. Diam interdum metus ante semper, lorem ornare massa. Accumsan dapibus lacus venenatis; elementum varius nascetur nibh sodales ipsum. Suspendisse mauris cubilia sit elit netus mattis. Rhoncus vivamus ridiculus nostra sociosqu bibendum. Eleifend ultricies orci proin maecenas justo felis sagittis. Elit blandit mattis dis consectetur morbi quisque penatibus."
and
"Lorem ipsum odor amet, consectetuer adipiscing elit. Proin maximus condimentum fusce nam, dictum adipiscing maximus. Lacinia pellentesque magna senectus adipiscing massa cras elementum tortor. Habitant hendrerit sodales, consectetur amet conubia ullamcorper. Suscipit aliquet curae lobortis imperdiet, montes lectus. Hendrerit penatibus commodo semper laoreet viverra eu elit nisl."
The tools count_characters
and calculator_multiply
will be used, resulting in 455 * 381 = 173,355
.
Error When Starting Claude
When starting Claude after installing the server with uv run mcp install ./servers/mcp_fake_server.py
, errors may occur:
Error in MCP connection to server Demo: Error: spawn uv ENOENT
[error] Could not start MCP server Demo: Error: spawn uv ENOENT
These errors do not occur when using Docker containers. One issue is that the uv
command is not found unless the full path is specified. Another issue is the MCP server cannot find files from different directories during import.
Solution
Add the full path to the command
and include the --directory
flag referencing the project directory where the server source files reside:
{
"mcpServers": {
"fake-server": {
"command": "/Users/shanekercheval/.local/bin/uv",
"args": [
"run",
"--directory",
"/Users/shanekercheval/repos/mcp-client-agent",
"--with",
"mcp",
"mcp",
"run",
"servers/mcp_fake_server.py"
]
}
}
}
There is no way to set this directly using the install command.