#MCP Smart Inventory Agent This project implements a stateful AI agent using the Model Context Protocol (MCP). It bridges a local FastAPI REST service with an LLM (like Claude Desktop) using LangGraph for request validation and reasoning.
π Project Structure
my-mcp-agent/
βββ .env # API Keys and Secrets
βββ docker-compose.yml # Orchestrates the FastAPI container
βββ Dockerfile # Builds the API image
βββ requirements.txt # Project dependencies
βββ api/
β βββ app.py # FastAPI (REST Endpoints + Auth)
βββ mcp_agent/
βββ mcp_server.py # MCP Server (The Bridge)
βββ graph_logic.py # LangGraph (Validation & Logic)
π οΈ Setup Instructions
- Environment Configuration Create a .env file in the root directory:
INTERNAL_API_KEY=your_secure_token_here
OPENAI_API_KEY=your_openai_key_here # Required for LangGraph reasoning
- Launch the REST API Build and run the backend service using Docker:
Bash
docker-compose up -d --build The API will be available at http://localhost:8000. You can view the docs at /docs.
- Install MCP Dependencies Locally Since the MCP server needs to communicate with your desktop LLM app, install the requirements in a local virtual environment:
Bash
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt π Connecting to Claude Desktop To use this agent in the Claude Desktop interface, you must register the server in your configuration file.
Config Location:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Add this entry:
JSON
{ "mcpServers": { "inventory-agent": { "command": "python", "args": ["/absolute/path/to/my-mcp-agent/mcp_agent/mcp_server.py"], "env": { "INTERNAL_API_KEY": "your_secure_token_here", "OPENAI_API_KEY": "your_openai_key_here" } } } } π€ Usage & Features The Interface Once configured, restart Claude Desktop. You will see a π icon. You can now chat with your API:
Querying: "What is currently in my inventory?"
Smart Adding: "Add 'Industrial Drill' with the description 'High-powered 20V cordless tool'."
LangGraph Validation The agent includes a Validator Node. If you attempt to add an item with a description shorter than 10 characters, the agent will:
Catch the error in the graph_logic.py.
Prevent the API call.
Ask you for more details in the chat window.
π§ͺ Testing the API Manually If you need to verify the REST endpoints without the LLM:
Bash
curl http://localhost:8000/items
curl -H "X-API-Key: your_secure_token_here" http://localhost:8000/items Would you like me to help you write a Python test script that simulates a full LangGraph run without needing to open the Claude Desktop app?