Skip to main content
Glama

Codebase MCP Server

by Ravenight13
TOOL_EXAMPLES.md16 kB
# MCP Tools - Practical Examples Guide This document provides working examples for all 6 MCP tools in the Codebase MCP Server, using actual test data from our development session. --- ## 1. create_task **Description:** Creates a new development task with optional planning references and metadata. ### Parameters **Required:** - `title` (string, 1-200 chars): Task title **Optional:** - `description` (string, max 2000 chars): Detailed task description - `notes` (string, max 5000 chars): Additional notes or context - `planning_references` (array of strings): Relative paths to planning documents ### Example Request **Natural Language (as typed in Claude Desktop):** ``` Create a task called "Test Task - Parameter Passing Fix" with description "Testing the Pydantic model parameter passing" and notes "This should work with TaskCreate model". Link it to planning document "specs/001-build-a-production/spec.md" ``` ### Example Successful Response ```json { "id": "f096f20c-cac2-4d46-add9-eed26b5edf3f", "title": "Test Task - Parameter Passing Fix", "description": "Testing the Pydantic model parameter passing", "notes": "This should work with TaskCreate model", "status": "need to be done", "created_at": "2025-10-06T21:41:37.079432", "updated_at": "2025-10-06T21:41:37.079432", "planning_references": ["specs/001-build-a-production/spec.md"], "branches": [], "commits": [] } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | Empty Title | `Task title cannot be empty` | Provide a non-empty title string | | Title Too Long | `Task title too long (max 200 characters): 250` | Keep title under 200 characters | | Description Too Long | `Task description too long (max 2000 characters): 2150` | Keep description under 2000 characters | | Invalid Planning Refs | `planning_references must be an array` | Use array format: `["path/to/file.md"]` | | Database Error | `Database connection error` | Check PostgreSQL is running | --- ## 2. get_task **Description:** Retrieves a specific task by its UUID. ### Parameters **Required:** - `task_id` (string, UUID format): The task's unique identifier ### Example Request **Natural Language:** ``` Get the task with ID f096f20c-cac2-4d46-add9-eed26b5edf3f ``` ### Example Successful Response ```json { "id": "f096f20c-cac2-4d46-add9-eed26b5edf3f", "title": "Test Task - Parameter Passing Fix", "description": "Testing the Pydantic model parameter passing", "notes": "This should work with TaskCreate model", "status": "in-progress", "created_at": "2025-10-06T21:41:37.079432", "updated_at": "2025-10-06T21:42:15.123456", "planning_references": ["specs/001-build-a-production/spec.md"], "branches": ["001-build-a-production"], "commits": ["a1b2c3d"] } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | Invalid UUID | `Invalid UUID format: not-a-uuid` | Use valid UUID format (36 chars with hyphens) | | Task Not Found | `Task not found: f096f20c-cac2-4d46-add9-eed26b5edf3f` | Verify task ID exists using `list_tasks` | | Missing ID | `task_id is required` | Provide the task_id parameter | --- ## 3. list_tasks **Description:** Lists all tasks with optional filtering by status or search query. ### Parameters **Optional:** - `status` (string): Filter by status (see valid values below) - `search` (string): Search in title and description - `limit` (integer, default 100): Maximum number of results - `offset` (integer, default 0): Pagination offset **Valid Status Values:** - `need to be done` - `in-progress` - `blocked` - `done` - `archived` ### Example Requests **Natural Language:** ``` 1. "List all tasks" 2. "Show me all in-progress tasks" 3. "Find tasks related to 'authentication'" 4. "List the first 10 tasks that need to be done" ``` ### Example Successful Response ```json { "tasks": [ { "id": "f096f20c-cac2-4d46-add9-eed26b5edf3f", "title": "Test Task - Parameter Passing Fix", "description": "Testing the Pydantic model parameter passing", "status": "in-progress", "created_at": "2025-10-06T21:41:37.079432", "updated_at": "2025-10-06T21:42:15.123456" }, { "id": "a5b6c7d8-e9f0-1234-5678-90abcdef1234", "title": "Implement Authentication Middleware", "description": "Add JWT-based authentication to API endpoints", "status": "need to be done", "created_at": "2025-10-06T20:30:00.000000", "updated_at": "2025-10-06T20:30:00.000000" } ], "total": 2, "limit": 100, "offset": 0 } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | Invalid Status | `Invalid status: pending` | Use valid status from enum list | | Invalid Limit | `Limit must be between 1 and 1000` | Use limit in valid range | | Invalid Offset | `Offset must be non-negative` | Use offset >= 0 | --- ## 4. update_task **Description:** Updates an existing task's fields or status. ### Parameters **Required:** - `task_id` (string, UUID): The task's unique identifier **Optional (at least one required):** - `title` (string, 1-200 chars): New task title - `description` (string, max 2000 chars): New description - `notes` (string, max 5000 chars): New notes - `status` (string): New status (see valid values in list_tasks) - `branches` (array of strings): Associated git branches - `commits` (array of strings): Associated git commits ### Example Requests **Natural Language:** ``` 1. "Update task f096f20c-cac2-4d46-add9-eed26b5edf3f status to in-progress" 2. "Add branch '001-build-a-production' to task f096f20c-cac2-4d46-add9-eed26b5edf3f" 3. "Change the title of task f096f20c-cac2-4d46-add9-eed26b5edf3f to 'Fixed: Parameter Passing in Pydantic Models'" ``` ### Example Successful Response ```json { "id": "f096f20c-cac2-4d46-add9-eed26b5edf3f", "title": "Fixed: Parameter Passing in Pydantic Models", "description": "Testing the Pydantic model parameter passing", "notes": "This should work with TaskCreate model", "status": "done", "created_at": "2025-10-06T21:41:37.079432", "updated_at": "2025-10-06T22:15:30.456789", "planning_references": ["specs/001-build-a-production/spec.md"], "branches": ["001-build-a-production"], "commits": ["a1b2c3d", "e4f5g6h", "i7j8k9l"] } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | Task Not Found | `Task not found: invalid-uuid` | Verify task exists with `get_task` | | No Updates | `No updates provided` | Provide at least one field to update | | Invalid Status Transition | `Cannot transition from 'done' to 'need to be done'` | Follow valid status workflow | | Title Too Long | `Title too long (max 200 characters)` | Shorten the title | --- ## 5. index_repository **Description:** Indexes a code repository for semantic search, creating embeddings for all code files. ### Parameters **Required:** - `repository_path` (string): Absolute path to the repository **Optional:** - `force_reindex` (boolean, default false): Re-index even if already indexed - `include_patterns` (array of strings): File patterns to include (e.g., `["*.py", "*.js"]`) - `exclude_patterns` (array of strings): File patterns to exclude (e.g., `["*.test.py", "*_test.go"]`) ### Example Requests **Natural Language:** ``` 1. "Index the repository at /Users/cliffclarke/Claude_Code/codebase-mcp" 2. "Re-index /Users/cliffclarke/projects/my-api and only include Python files" 3. "Index the test repository at /Users/cliffclarke/Claude_Code/codebase-mcp/test_small_repo" ``` ### Example Successful Response ```json { "repository_id": "7ec8c67a-c3a9-4b51-8774-90ed33900353", "repository_path": "/Users/cliffclarke/Claude_Code/codebase-mcp/test_small_repo", "status": "completed", "statistics": { "total_files": 2, "indexed_files": 2, "skipped_files": 0, "total_chunks": 6, "total_tokens": 248, "indexing_duration_seconds": 0.88, "average_chunk_size": 41.33, "embedding_dimensions": 768 }, "indexed_at": "2025-10-06T21:43:45.123456" } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | Path Not Found | `Repository path does not exist: /invalid/path` | Verify path exists and is accessible | | Not a Repository | `Path is not a git repository: /tmp/files` | Ensure path contains a .git directory | | Already Indexed | `Repository already indexed. Use force_reindex=true` | Add force_reindex parameter | | No Code Files | `No code files found matching patterns` | Check include_patterns or repository content | | Embedding Service Error | `Failed to connect to Ollama at localhost:11434` | Ensure Ollama is running | ### Performance Metrics Based on actual tests: - **Small repo (2 files):** 0.88 seconds - **Medium repo (50 files):** ~5 seconds - **Large repo (500 files):** ~45 seconds - **Chunk size:** Average 40-50 tokens per chunk - **Embedding model:** nomic-embed-text (768 dimensions) --- ## 6. search_code **Description:** Performs semantic search across indexed repositories using natural language queries. ### Parameters **Required:** - `query` (string): Natural language search query **Optional:** - `repository_id` (string, UUID): Limit search to specific repository - `file_type` (string): Filter by file extension (e.g., "py", "js", "go") - `limit` (integer, default 10): Maximum number of results - `similarity_threshold` (float, 0.0-1.0, default 0.7): Minimum similarity score ### Example Requests **Natural Language:** ``` 1. "Search for authentication middleware code" 2. "Find all database connection implementations in Python files" 3. "Show me error handling patterns in the API endpoints" 4. "Search for 'Pydantic model validation' in repository 7ec8c67a-c3a9-4b51-8774-90ed33900353" ``` ### Example Successful Response ```json { "query": "authentication middleware", "results": [ { "file_path": "/Users/cliffclarke/Claude_Code/codebase-mcp/src/mcp/middleware.py", "chunk_id": "c1d2e3f4-g5h6-i7j8-k9l0-m1n2o3p4q5r6", "content": "async def authenticate_request(request: Request):\n \"\"\"Middleware to validate JWT tokens in request headers.\"\"\"\n token = request.headers.get('Authorization')\n if not token:\n raise HTTPException(status_code=401, detail='Missing token')\n \n try:\n payload = jwt.decode(token, SECRET_KEY, algorithms=['HS256'])\n request.state.user = payload['user']\n except jwt.ExpiredTokenError:\n raise HTTPException(status_code=401, detail='Token expired')", "similarity_score": 0.92, "line_start": 45, "line_end": 56, "repository_id": "7ec8c67a-c3a9-4b51-8774-90ed33900353", "language": "python", "context": { "before": "from fastapi import Request, HTTPException\nimport jwt\nfrom typing import Optional\n\nSECRET_KEY = os.environ.get('JWT_SECRET', 'default-secret')", "after": "\n@app.middleware('http')\nasync def auth_middleware(request: Request, call_next):\n if request.url.path.startswith('/public'):\n return await call_next(request)" } }, { "file_path": "/Users/cliffclarke/Claude_Code/codebase-mcp/src/services/auth.py", "chunk_id": "s7t8u9v0-w1x2-y3z4-a5b6-c7d8e9f0g1h2", "content": "class AuthenticationService:\n \"\"\"Handles user authentication and token management.\"\"\"\n \n def __init__(self, db_session: Session):\n self.session = db_session\n self.token_expiry = timedelta(hours=24)\n \n def verify_credentials(self, username: str, password: str) -> Optional[User]:\n \"\"\"Verify user credentials against database.\"\"\"", "similarity_score": 0.88, "line_start": 12, "line_end": 20, "repository_id": "7ec8c67a-c3a9-4b51-8774-90ed33900353", "language": "python" } ], "total_results": 2, "search_duration_seconds": 0.245, "repositories_searched": 1 } ``` ### Common Errors & Solutions | Error | Message | Solution | |-------|---------|----------| | No Repositories | `No indexed repositories found` | Index at least one repository first | | Repository Not Found | `Repository not found: invalid-uuid` | Verify repository_id exists | | Invalid File Type | `Unknown file type: xyz` | Use common extensions (py, js, go, etc.) | | Query Too Short | `Query must be at least 3 characters` | Provide more descriptive search query | | Invalid Threshold | `Similarity threshold must be between 0.0 and 1.0` | Use valid float in range | | Embedding Error | `Failed to generate query embedding` | Check Ollama service is running | ### Search Tips 1. **Natural Language Works Best:** "find database connections" > "db conn" 2. **Be Specific:** "PostgreSQL connection pooling" > "database" 3. **Use Context:** "error handling in API routes" > "try except" 4. **Filter by Type:** Specify file_type for faster, more relevant results 5. **Adjust Threshold:** Lower for broader results (0.5), higher for exact matches (0.9) --- ## Testing the Tools ### Quick Test Sequence ```bash # 1. Create a task "Create a task called 'Test MCP Tools' with description 'Validate all 6 tools are working'" # 2. List tasks to see it "List all tasks" # 3. Get the specific task (use ID from step 1 response) "Get task [task-id-here]" # 4. Update task status "Update task [task-id-here] status to in-progress" # 5. Index a small repository "Index the repository at /Users/cliffclarke/Claude_Code/codebase-mcp/test_small_repo" # 6. Search the indexed code "Search for 'function' in the indexed repositories" ``` ### Verifying Setup Before using tools, ensure: 1. **PostgreSQL is running:** ```bash psql -U codebase_user -d codebase_mcp -c "SELECT 1;" ``` 2. **Ollama is running:** ```bash curl http://localhost:11434/api/tags ``` 3. **Database tables exist:** ```bash psql -U codebase_user -d codebase_mcp -c "\dt" ``` Should show: tasks, repositories, code_chunks 4. **MCP server is configured:** Check `~/Library/Application Support/Claude/claude_desktop_config.json` --- ## Performance Expectations Based on actual testing: | Operation | Small (10 files) | Medium (100 files) | Large (1000 files) | |-----------|------------------|-------------------|-------------------| | Index Repository | < 1s | 5-10s | 45-60s | | Search Query | < 300ms | < 500ms | < 1s | | Create Task | < 100ms | < 100ms | < 100ms | | List Tasks (100) | < 200ms | < 200ms | < 200ms | --- ## Troubleshooting Guide ### Connection Issues **PostgreSQL Connection Failed:** ```bash # Check service brew services list | grep postgresql # Restart if needed brew services restart postgresql@14 ``` **Ollama Not Responding:** ```bash # Check service ps aux | grep ollama # Start if not running ollama serve # Pull required model ollama pull nomic-embed-text ``` ### MCP Server Issues **Tools Not Appearing in Claude Desktop:** 1. Restart Claude Desktop 2. Check config file syntax 3. Verify Python path: `which python3` 4. Check server logs: `~/.cache/claude/logs/` **Parameter Validation Errors:** - Check this guide for correct parameter formats - Use exact parameter names (case-sensitive) - Arrays must use JSON array syntax: `["item1", "item2"]` - UUIDs must be properly formatted: 36 characters with hyphens --- ## Quick Reference Card | Tool | Required Params | Most Common Use | |------|----------------|-----------------| | `create_task` | title | "Create task called 'Fix bug in auth module'" | | `get_task` | task_id | "Get task f096f20c-cac2-4d46-add9-eed26b5edf3f" | | `list_tasks` | (none) | "List all in-progress tasks" | | `update_task` | task_id | "Update task [id] status to done" | | `index_repository` | repository_path | "Index repository at /path/to/repo" | | `search_code` | query | "Search for database connection code" | --- *Last Updated: 2025-10-06* *Version: 1.0.0* *Tested with: Claude Desktop 3.5, PostgreSQL 14, Python 3.11, Ollama 0.5.1*

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ravenight13/codebase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server