MCP-Agent
- agent-framework
CLI that uses DSPy to interact with MCP servers.
About
What is MCP-Agent?
MCP-Agent is a command-line interface (CLI) that uses DSPy to interact with MCP (Model Context Protocol) servers. It runs on any platform that supports Python and DSPy, and is designed for developers who want an autonomous agent experience similar to Claude Desktop but with full control over MCP server configuration and tool usage.
How to use MCP-Agent?
Create a .env file with OPENAI_API_KEY, adjust the server configuration path in the provided JSON config file, then run make build followed by make chat. The chat command loads all MCP servers defined in the configuration and makes their tools available to the DSPy agent, which autonomously uses them to fulfill user requests.
Key features of MCP-Agent
- Autonomous tool orchestration via DSPy agent
- Loads multiple MCP servers from a single Claude‑compatible config file
- Works with any MCP server providing tools
- CLI‑based, no GUI required
- Example includes simple tools like count_characters and calculator_multiply
- Uses openai/gpt-4o-mini as the default model
Use cases of MCP-Agent
- Perform multi‑step calculations on text data (e.g., count characters across texts and multiply results)
- Automate data extraction or transformation by chaining MCP tools
- Test and prototype MCP server integrations in a headless environment
- Trigger sequences of actions that require reasoning and tool selection
FAQ from MCP-Agent
How do I set up MCP-Agent?
Create a .env file in the project directory containing OPENAI_API_KEY, adjust the path in ./servers/mcp_fake_server_config.json to point to your project’s servers directory, then run make build and make chat.
What MCP servers can I use?
Any MCP server that defines tools compatible with the MCP protocol. The agent loads all servers listed in a configuration file (the same format used by Claude Desktop) and makes their combined tools available.
Does MCP-Agent support multiple servers simultaneously?
Yes. The CLI loads all servers defined in
Details
- Author
- shane-kercheval
- GitHub stars
- 17
- Category
- agent-framework
- Repository
- shane-kercheval/mcp-client-agent
MCP-Agent
./clients/mcp_client.py is a CLI that uses DSPy to interact with MCP servers. The goal is to provide a similar experience to Claude Desktop. In particular, the DSPy agent uses the tool definitions defined in the MCP server(s) to autonomously and iteratively use the tools to accomplish the user's request.
The CLI program takes a configuration file in the same format that Claude Desktop uses and loads all of the servers in the config. The tools across all servers are available for the agent to use.
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 OPENAI_API_KEY key and value.
- adjust this path /Users/shanekercheval/repos/mcp-client-agent/servers in ./servers/mcp_fake_server_config.json accordingly
- make build
- make chat
- starts the chat CLI command using the ./servers/mcp_fake_server_config.json config to start the MCP Server ./servers/mcp_fake_server.py
- This MCP server contains trivial tools like count_characters or calulator_multiply
- this command uses openai/gpt-4o-mini as the model (DSPy model path formatting) and requires OPENAI_API_KEY to be set in the .env file
Example using make chat command and mcp_fake_server.py:
> Multiply the number of characters in both 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 count_characters and calculator_multiply tools should be used and result should be 455 381 = 173,355.
Error When Starting Claude
I received these errors when starting Claude after installing the server via uv run mcp install ./servers/mcp_fake_server.py. These errors do not happen when using docker containers. One isue is that the uv command doesn't seem to be found unless I provide the path (found via which uv). Another issue is that the MCP server cannot find files from different directories that it attempts to import.
Here are the errors I get (tail -n 20 -F ~/Library/Logs/Claude/mcp.log helped me to debug):
Error in MCP connection to server Demo: Error: spawn uv ENOENT
[error] Could not start MCP server Demo: Error: spawn uv ENOENT
The solution was to add the full path to the command and add the --directory flag referencing the project directory of the source files that are imported by the server:
{
"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 doesn't appear to be a way to do this directly from the install command.