Skip to content

harshbmehta/mcp-agent-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

#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

  1. 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
  1. 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.

  1. 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

This should return 403 Forbidden

curl http://localhost:8000/items

This should return the inventory list

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?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages