A powerful, decoupled coding assistant built with the Model Context Protocol (MCP) and uv. This project demonstrates how to separate an AI agent's reasoning capabilities (the client) from its practical tools (the server), allowing for flexible, scalable, and maintainable agentic systems.
The primary goal of this project is to showcase the power of the Model Context Protocol (MCP). Instead of building a monolithic agent where the tools are tightly coupled with the agent's code, we use MCP to create two distinct services:
- The MCP Server: A standalone service that hosts a suite of "tools" (e.g., file I/O, code execution, package management). It knows nothing about the agent that will use it.
- The Client: An intelligent agent that connects to the MCP server, discovers the available tools, and uses them to accomplish tasks given by a user.
This architecture reduces complexity from ( M * N ) (M agents needing N tools) to ( M + N ) (M agents and N tools connect to a common protocol), making it easy to add new tools or agents without modifying the other components.
The agent is equipped with the following tools, served via the MCP server:
- File Management: Create, read, and list files in the project directory.
- Code Execution: Safely execute Python code within a
uvenvironment. - Package Management: Add and remove Python packages using
uv. - Project Inspection: Initialize
uvprojects and view dependency information.
This project supports two different usage modes:
- Standalone Mode: Run with the included LangGraph client
- Cursor IDE Integration: Use as an MCP server within Cursor IDE
- Protocol: Model Context Protocol (MCP)
- Agent Framework: LangGraph (standalone mode)
- LLM: OpenAI
gpt-4o-mini(standalone mode) / Claude (Cursor mode) - Tool Server:
mcp.server.fastmcp(built on FastAPI/Uvicorn) - Package & Environment Manager: uv
- Python Version: 3.12+
The project uses a standard src layout for clean, installable packaging.
mcp-coding-tool/
├── .venv/ # Virtual environment managed by uv
├── pyproject.toml # Project configuration and dependencies
├── .env # For storing API keys (standalone mode)
└── src/
└── coding_agent/
├── __init__.py # Makes this a Python package
├── server.py # MCP server for standalone mode
├── server_for_cursor.py # MCP server for Cursor IDE
└── client.py # The LangGraph agent client
Follow these steps to get the agent running on your local machine.
Ensure you have uv installed.
# On macOS, Linux, or Windows (WSL)
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"git clone <your-repo-url>
cd mcp-coding-tooluv will create a virtual environment and install all packages defined in pyproject.toml.
# Create the virtual environment in ./.venv
uv venv
# Install all dependencies
uv syncCreate a .env file in the root of the project directory to store your OpenAI API key.
# Create the file
touch .env
# Add your key to the file
echo 'OPENAI_API_KEY="sk-..."' > .envThis mode runs the agent with its own LangGraph client interface.
uv run src/coding_agent/server.pyYou should see output indicating the Uvicorn server is running on http://127.0.0.1:8092.
uv run src/coding_agent/client.pyYou can now chat with the agent and ask it to perform coding-related tasks.
This mode integrates the MCP server directly with Cursor IDE, allowing you to use the tools within Cursor's AI assistant.
Create or update your mcp.json file in your Cursor settings directory with the following configuration:
{
"mcpServers": {
"CodingAgent": {
"command": "path/to/your/directory/.venv/bin/python",
"args": [
"path/to/your/directory/src/coding_agent/server_for_cursor.py"
],
"transport": "stdio",
"url": "http://localhost:8092"
}
}
}Note: Update the paths to match your actual project location.
- Open Cursor IDE
- The MCP server will automatically start when Cursor launches
- You can now use the coding tools directly in Cursor's chat interface
Once configured, you can ask Cursor to:
execute_python_code: Run Python code snippetscreate_file: Create new files with contentread_file: Read existing fileslist_files: List directory contentsadd_package: Add Python packages using uvremove_package: Remove Python packages using uv
Example Cursor prompts:
- "Create a new Python file called
main.pywith a hello world function" - "Execute this Python code and show me the output:
print('Hello, World!')" - "Add the requests package to this project"
- "List all files in the current directory"
- The MCP Server starts up, exposing functions like
create_fileandexecute_python_codeas tools available over the network. - The LangGraph Client starts and establishes a session with the MCP server.
- The user provides a prompt, and the agent uses a ReAct (Reasoning and Acting) loop to determine which tools to use.
- The agent calls the appropriate tools via JSON-RPC requests to the MCP server.
- Cursor IDE launches the MCP Server as a subprocess using stdio transport.
- The server registers its tools with Cursor's MCP client.
- When you chat with Cursor, it can automatically discover and use these tools.
- Cursor sends tool requests via the MCP protocol to execute actions like file operations or code execution.
🤖 Coding Agent Initialized!
Available commands:
- Type your coding task
- Type 'quit' to exit
--------------------------------------------------
💭 Enter your coding task: create a file called tmp.txt with the content "# My Project"
🔄 Processing your request...
✅ Loaded 6 tools for this task.
--- AGENT WORKFLOW STARTED ---
--- AGENT WORKFLOW FINISHED ---
🤖 Agent's Final Response:
I have successfully created the file `tmp.txt` with the content "# My Project".
Simply chat with Cursor and ask it to perform coding tasks:
User: Create a Python script that calculates fibonacci numbers
Cursor: I'll create a Python script for calculating Fibonacci numbers for you.
[Uses create_file tool to create fibonacci.py]
[Uses execute_python_code tool to test the script]
I've created a fibonacci.py file with a function to calculate Fibonacci numbers...
-
Server not connecting: Ensure the paths in
mcp.jsonare correct and point to your actual project location. -
Transport errors: Make sure you're using
"transport": "stdio"in yourmcp.jsonconfiguration. -
Permission errors: Ensure the Python executable and script files have proper permissions.
-
uv not found: Make sure
uvis installed and available in your system PATH.
You can test the Cursor server independently:
# Test the server manually
uv run src/coding_agent/server_for_cursor.py