Skip to main content
Glama
README.md
# MCPServer — Python MCP Server with JSON Data Store

A complete, production-ready **MCP (Model Context Protocol) Server** built with Python.

- **REST API** (FastAPI) backed by **JSON files** — zero DB setup
- **17 MCP Tools** that wrap every API endpoint
- **Mock OAuth** for development → swap to real OAuth with one config flag
- Ready for **Claude Desktop**, **MCP Inspector**, and any MCP client

---

## Project Structure

```
MCPServer/
├── data/                     ← JSON "database" files (users, products, orders)
├── app/
│   ├── auth/                 ← Mock OAuth + real OAuth placeholder
│   ├── db/json_store.py      ← Thread-safe CRUD over JSON files
│   ├── routers/              ← FastAPI routes (users, products, orders)
│   ├── schemas/              ← Pydantic request/response models
│   ├── config.py             ← Settings (loaded from .env)
│   └── main.py               ← FastAPI entry point
├── mcp_server/
│   ├── tools/
│   │   ├── api_client.py     ← HTTP client calling the FastAPI backend
│   │   ├── user_tools.py     ← MCP tools for Users
│   │   ├── product_tools.py  ← MCP tools for Products
│   │   └── order_tools.py    ← MCP tools for Orders
│   └── server.py             ← MCP server entry point (stdio)
├── .env.example
└── requirements.txt
```

---

## Quick Start

### 1. Install dependencies

```powershell
cd MCPServer
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt
```

### 2. Configure environment

```powershell
Copy-Item .env.example .env
# Edit .env if needed (defaults work out of the box)
```

### 3. Start the REST API

```powershell
uvicorn app.main:app --reload --port 8000
```

- **Swagger UI** → http://localhost:8000/docs
- **Health check** → http://localhost:8000/health

> Click **Authorize** in Swagger UI and enter: `dev-secret-key-change-me`

### 4. Start the MCP Server

```powershell
python -m mcp_server.server
```

---

## Available MCP Tools (17 total)

### Users
| Tool | Description |
|------|-------------|
| `list_users` | List users (filter by active/role) |
| `get_user` | Get user by ID |
| `create_user` | Create a new user |
| `update_user` | Update user fields |
| `delete_user` | Delete a user |

### Products
| Tool | Description |
|------|-------------|
| `list_products` | List products (filter by category/price/active) |
| `get_product` | Get product by ID |
| `create_product` | Create a new product |
| `update_product` | Update product fields |
| `update_product_stock` | Update stock level only |
| `delete_product` | Delete a product |

### Orders
| Tool | Description |
|------|-------------|
| `list_orders` | List orders (filter by user/status) |
| `get_order` | Get order by ID |
| `create_order` | Place an order (total auto-computed) |
| `update_order` | Update status or shipping address |
| `cancel_order` | Cancel pending/processing order |
| `get_user_order_summary` | Spending summary for a user |

---

## Connect to Claude Desktop

Add to `%APPDATA%\Claude\claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mock-api": {
      "command": "python",
      "args": ["-m", "mcp_server.server"],
      "cwd": "C:/path/to/MCPServer",
      "env": {
        "API_BASE_URL": "http://localhost:8000",
        "MOCK_API_KEY": "dev-secret-key-change-me"
      }
    }
  }
}
```

---

## Switching to Real OAuth

1. Set `USE_MOCK_AUTH=false` in `.env`
2. Fill `OAUTH_ISSUER`, `OAUTH_AUDIENCE`, `OAUTH_JWKS_URI` in `.env`
3. Implement `validate_token()` in [`app/auth/oauth.py`](app/auth/oauth.py)
4. Uncomment `python-jose` in `requirements.txt` and reinstall
5. Update `api_client.py` to fetch a real access token instead of the API key

No other files need to change.

---

## API Authentication (Development)

All endpoints require a Bearer token:

```
Authorization: Bearer dev-secret-key-change-me
git clone https://github.com/Bhanuprakashdadi145/Mcp-Server.git
cd MCPServer
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
Copy-Item .env.example .env
uvicorn app.main:app --reload --port 8000
python -m mcp_server.server
```

Change `MOCK_API_KEY` in `.env` to any value you prefer.