Spaces:
Sleeping
Sleeping
File size: 3,744 Bytes
c86be6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | # Development Commands
## π Quick Start Commands
### 1. Install Dependencies
```bash
uv sync
```
### 2. Setup Environment
```bash
# Create .env file from template
cp .env.example .env
# Edit .env file and add your Anthropic API key
ANTHROPIC_API_KEY=your_actual_api_key_here
```
### 3. Run FastAPI Server
```bash
# Standard uvicorn command with auto-reload
uvicorn main:app --reload
# Or with custom host/port
uvicorn main:app --reload --host 0.0.0.0 --port 8000
```
### 4. Install MCP Server
```bash
# Install the MCP server for Claude Desktop
uv run mcp install mcp_main.py
# Or install from current directory
uv run mcp install .
```
### 5. Test MCP Server Locally
```bash
# Test the MCP server directly
python mcp_main.py
# Or using uv
uv run mcp_main.py
```
## π API Testing
### Test FastAPI Endpoints
```bash
# Health check
curl http://localhost:8000/health
# Upload PDF
curl -X POST "http://localhost:8000/upload-pdf/" -F "file=@sample.pdf"
# List documents
curl http://localhost:8000/documents/
# Get document status
curl http://localhost:8000/status/{file_id}
```
## π§ Claude Desktop Configuration
### Manual Configuration
1. Open Claude Desktop configuration:
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Linux**: `~/.config/claude/claude_desktop_config.json`
2. Add the server configuration:
```json
{
"mcpServers": {
"pdf-parser": {
"command": "uv",
"args": ["--directory", "C:\\path\\to\\your\\pdf-parser", "run", "mcp_main.py"],
"cwd": "C:\\path\\to\\your\\pdf-parser"
}
}
}
```
3. Restart Claude Desktop
## π οΈ Development Tools
### Code Quality
```bash
# Format code
uv run ruff format .
# Lint code
uv run ruff check .
# Type checking
uv run mypy .
```
### Testing
```bash
# Run tests
uv run pytest
# Run with coverage
uv run pytest --cov=. --cov-report=html
```
## π Debugging
### Check Dependencies
```bash
python -c "import fitz, tiktoken, anthropic, fastapi, uvicorn, mcp; print('All dependencies OK')"
```
### Verbose Logging
```bash
# Run FastAPI with debug logging
uvicorn main:app --reload --log-level debug
# Run MCP server with debug
python mcp_main.py --verbose
```
### Environment Variables
```bash
# Check environment variables
python -c "import os; print('ANTHROPIC_API_KEY:', 'SET' if os.getenv('ANTHROPIC_API_KEY') else 'NOT SET')"
```
## π Common Workflows
### Development Workflow
1. `uv sync` - Install dependencies
2. `cp .env.example .env` - Setup environment
3. `uvicorn main:app --reload` - Start FastAPI server
4. `uv run mcp install mcp_main.py` - Install MCP server
5. Configure Claude Desktop
6. Test with PDF uploads
### Production Deployment
1. `uv sync --frozen` - Install exact dependencies
2. `uvicorn main:app --host 0.0.0.0 --port 8000` - Start production server
3. Configure reverse proxy (nginx/apache)
4. Setup SSL certificates
5. Configure Claude Desktop for production
## π File Structure
```
pdf-parser/
βββ main.py # FastAPI server (uvicorn main:app)
βββ mcp_main.py # MCP server entry point (uv run mcp install)
βββ mcp_server.py # MCP server implementation
βββ pdf_processor.py # PDF processing logic
βββ anthropic_client.py # Anthropic API client
βββ pyproject.toml # Project configuration
βββ .env.example # Environment template
βββ dev_commands.md # This file
βββ README.md # Documentation
``` |