Spaces:
Sleeping
Sleeping
Peter Michael Gits Claude commited on
Commit ·
450ae85
1
Parent(s): 795ea6f
Add CLAUDE.md documentation and update version to 0.1.1
Browse files- Added comprehensive CLAUDE.md with project architecture and development commands
- Updated semantic version from 0.1.0 to 0.1.1
- Added app.py with FastAPI and HuggingFace transformers integration
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- CLAUDE.md +90 -0
- app.py +16 -0
- pyproject.toml +1 -1
CLAUDE.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CLAUDE.md
|
| 2 |
+
|
| 3 |
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
| 4 |
+
|
| 5 |
+
## Project Overview
|
| 6 |
+
|
| 7 |
+
This is a Docker-based Model Context Protocol (MCP) server designed for deployment on Hugging Face Spaces. The project implements a custom MCP server with HTTP wrapper functionality and includes both FastAPI applications and MCP protocol handlers.
|
| 8 |
+
|
| 9 |
+
## Architecture
|
| 10 |
+
|
| 11 |
+
### Core Components
|
| 12 |
+
|
| 13 |
+
- **mcp_server.py**: Core MCP server implementation with JSON-RPC 2.0 protocol handling
|
| 14 |
+
- Implements MCP protocol methods (initialize, tools/list, tools/call, resources/list, resources/read)
|
| 15 |
+
- Includes sample tools (echo, current_time, calculate, word_count, reverse_text)
|
| 16 |
+
- Contains decorator-based tool and resource registration system
|
| 17 |
+
|
| 18 |
+
- **http_wrapper.py**: FastAPI HTTP wrapper that exposes MCP server over HTTP (main entry point)
|
| 19 |
+
- Converts HTTP requests to MCP protocol calls
|
| 20 |
+
- Provides web interface and API documentation
|
| 21 |
+
- Health check endpoint at `/health`
|
| 22 |
+
|
| 23 |
+
- **proxy_script.py**: Local proxy for connecting Claude Desktop to remote HTTP MCP server
|
| 24 |
+
- Bridges stdio-based MCP protocol to HTTP endpoints
|
| 25 |
+
- Configured for Hugging Face Spaces deployment
|
| 26 |
+
|
| 27 |
+
- **app.py**: Alternative FastAPI app with HuggingFace transformers integration (T5 model)
|
| 28 |
+
|
| 29 |
+
- **main.py**: Simple hello world script
|
| 30 |
+
|
| 31 |
+
## Development Commands
|
| 32 |
+
|
| 33 |
+
### Running Locally
|
| 34 |
+
```bash
|
| 35 |
+
# Install dependencies
|
| 36 |
+
pip install -r requirements.txt
|
| 37 |
+
|
| 38 |
+
# Run the main HTTP server (recommended)
|
| 39 |
+
python3 http_wrapper.py
|
| 40 |
+
|
| 41 |
+
# Run MCP server in stdio mode
|
| 42 |
+
python3 mcp_server.py
|
| 43 |
+
|
| 44 |
+
# Run alternative app with transformers
|
| 45 |
+
python3 app.py
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### Docker Deployment
|
| 49 |
+
```bash
|
| 50 |
+
# Build container
|
| 51 |
+
docker build -t mcp-server .
|
| 52 |
+
|
| 53 |
+
# Run container
|
| 54 |
+
docker run -p 7860:7860 mcp-server
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Testing
|
| 58 |
+
- Health check: `curl http://localhost:7860/health`
|
| 59 |
+
- List tools: `curl http://localhost:7860/tools`
|
| 60 |
+
- API docs available at: `http://localhost:7860/docs`
|
| 61 |
+
|
| 62 |
+
## Key Technical Details
|
| 63 |
+
|
| 64 |
+
### MCP Protocol Implementation
|
| 65 |
+
- Uses JSON-RPC 2.0 for all communications
|
| 66 |
+
- Protocol version: 2024-11-05
|
| 67 |
+
- Supports both stdio and HTTP transport modes
|
| 68 |
+
|
| 69 |
+
### Tool Registration
|
| 70 |
+
Tools are registered using the `@server.tool()` decorator with:
|
| 71 |
+
- Name and description
|
| 72 |
+
- Parameter schema definitions
|
| 73 |
+
- Async function implementations
|
| 74 |
+
|
| 75 |
+
### Resource System
|
| 76 |
+
Resources use the `@server.resource()` decorator for URI-based content access.
|
| 77 |
+
|
| 78 |
+
### Deployment Environment
|
| 79 |
+
- Designed for Hugging Face Spaces with Docker SDK
|
| 80 |
+
- Default port: 7860
|
| 81 |
+
- Health checks configured for container orchestration
|
| 82 |
+
- Non-root user execution for security
|
| 83 |
+
|
| 84 |
+
## Container Configuration
|
| 85 |
+
|
| 86 |
+
- Base image: python:3.11-slim
|
| 87 |
+
- Exposed port: 7860
|
| 88 |
+
- Entry point: `http_wrapper.py`
|
| 89 |
+
- Health check endpoint: `/health`
|
| 90 |
+
- Working directory: `/app`
|
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 6 |
+
|
| 7 |
+
@app.get("/")
|
| 8 |
+
def greet_json():
|
| 9 |
+
return {"Hello": "World!"}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@app.get("/infer_t5")
|
| 14 |
+
def t5(input):
|
| 15 |
+
output = pipe_flan(input)
|
| 16 |
+
return {"output": output[0]["generated_text"]}
|
pyproject.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
[project]
|
| 2 |
name = "docker-mcp-server"
|
| 3 |
-
version = "0.1.
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13.5"
|
|
|
|
| 1 |
[project]
|
| 2 |
name = "docker-mcp-server"
|
| 3 |
+
version = "0.1.1"
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13.5"
|