|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | +MCP Registry is a community-driven registry service for Model Context Protocol (MCP) servers. It provides a centralized repository for discovering and managing MCP implementations. |
| 7 | + |
| 8 | +## Common Development Commands |
| 9 | + |
| 10 | +### Build |
| 11 | +```bash |
| 12 | +# Build the registry application |
| 13 | +go build ./cmd/registry |
| 14 | + |
| 15 | +# Build with Docker |
| 16 | +docker build -t registry . |
| 17 | + |
| 18 | +# Build the publisher tool |
| 19 | +cd tools/publisher && ./build.sh |
| 20 | +``` |
| 21 | + |
| 22 | +### Run |
| 23 | +```bash |
| 24 | +# Development with Docker Compose (recommended) |
| 25 | +docker compose up |
| 26 | + |
| 27 | +# Direct execution |
| 28 | +go run cmd/registry/main.go |
| 29 | +``` |
| 30 | + |
| 31 | +### Test |
| 32 | +```bash |
| 33 | +# Unit tests |
| 34 | +go test -v -race -coverprofile=coverage.out -covermode=atomic ./internal/... |
| 35 | + |
| 36 | +# Integration tests |
| 37 | +./integrationtests/run_tests.sh |
| 38 | + |
| 39 | +# Test API endpoints |
| 40 | +./scripts/test_endpoints.sh |
| 41 | + |
| 42 | +# Test publish endpoint (requires GitHub token) |
| 43 | +export BEARER_TOKEN=your_github_token_here |
| 44 | +./scripts/test_publish.sh |
| 45 | +``` |
| 46 | + |
| 47 | +### Lint |
| 48 | +```bash |
| 49 | +# Install golangci-lint if needed |
| 50 | +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 |
| 51 | + |
| 52 | +# Run linting |
| 53 | +golangci-lint run --timeout=5m |
| 54 | + |
| 55 | +# Check formatting |
| 56 | +gofmt -s -l . |
| 57 | +``` |
| 58 | + |
| 59 | +## Architecture Overview |
| 60 | + |
| 61 | +The codebase follows a clean architecture pattern: |
| 62 | + |
| 63 | +### Core Layers |
| 64 | +- **API Layer** (`internal/api/`) - HTTP handlers and routing |
| 65 | +- **Service Layer** (`internal/service/`) - Business logic implementation |
| 66 | +- **Database Layer** (`internal/database/`) - Data persistence abstraction with MongoDB and in-memory implementations |
| 67 | +- **Domain Models** (`internal/model/`) - Core data structures |
| 68 | +- **Authentication** (`internal/auth/`) - GitHub OAuth integration |
| 69 | + |
| 70 | +### Request Flow |
| 71 | +1. HTTP requests enter through router (`internal/api/router/`) |
| 72 | +2. Handlers in `internal/api/handlers/v0/` validate and process requests |
| 73 | +3. Service layer executes business logic |
| 74 | +4. Database interface handles persistence |
| 75 | +5. JSON responses returned to clients |
| 76 | + |
| 77 | +### Key Interfaces |
| 78 | +- **Database Interface** (`internal/database/database.go`) - Abstracts data persistence with MongoDB and memory implementations |
| 79 | +- **RegistryService** (`internal/service/service.go`) - Business logic abstraction over database |
| 80 | +- **Auth Service** (`internal/auth/auth.go`) - GitHub OAuth token validation |
| 81 | + |
| 82 | +### Authentication Flow |
| 83 | +Publishing requires GitHub OAuth validation: |
| 84 | +1. Extract bearer token from Authorization header |
| 85 | +2. Validate token with GitHub API |
| 86 | +3. Verify repository ownership matches token owner |
| 87 | +4. Check organization membership if applicable |
| 88 | + |
| 89 | +### Design Patterns |
| 90 | +- **Factory Pattern** for service creation with dependency injection |
| 91 | +- **Repository Pattern** for database abstraction |
| 92 | +- **Context Pattern** for timeout management (5-second DB operations) |
| 93 | +- **Cursor-based Pagination** using UUIDs for stateless pagination |
| 94 | + |
| 95 | +## Environment Variables |
| 96 | +Key configuration for development: |
| 97 | +- `MCP_REGISTRY_DATABASE_URL` (default: `mongodb://localhost:27017`) |
| 98 | +- `MCP_REGISTRY_GITHUB_CLIENT_ID` |
| 99 | +- `MCP_REGISTRY_GITHUB_CLIENT_SECRET` |
| 100 | +- `MCP_REGISTRY_LOG_LEVEL` (default: `info`) |
| 101 | +- `MCP_REGISTRY_SERVER_ADDRESS` (default: `:8080`) |
| 102 | +- `MCP_REGISTRY_SEED_IMPORT` (default: `true`) |
| 103 | +- `MCP_REGISTRY_SEED_FILE_PATH` (default: `data/seed.json`) |
0 commit comments