This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build all packages
go build -v ./...
# Build the main binary
go build -o osmmcp ./cmd/osmmcp
# Build with version information
VERSION=$(git describe --tags --always)
COMMIT=$(git rev-parse --short HEAD)
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
go build -ldflags="-X main.buildVersion=$VERSION -X main.buildCommit=$COMMIT -X main.buildDate=$BUILD_DATE" -o osmmcp ./cmd/osmmcp# Run with stdio transport for Claude Desktop integration
./osmmcp
# Run with debug logging
./osmmcp --debug# Enable HTTP+SSE dual transport for remote MCP clients
./osmmcp --enable-http --http-addr :7082
# With authentication
./osmmcp --enable-http --http-addr :7082 --http-auth-type bearer --http-auth-token your-secret
# With custom base URL for external access
./osmmcp --enable-http --http-addr :7082 --http-base-url https://your-domain.com# Enable monitoring server (enabled by default)
./osmmcp --enable-monitoring --monitoring-addr :9090
# Disable monitoring
./osmmcp --enable-monitoring=false
# Run with both HTTP transport and monitoring
./osmmcp --enable-http --http-addr :7082 --enable-monitoring --monitoring-addr :9090--enable-http: Enable HTTP+SSE transport (disabled by default)--http-addr: HTTP server address (default: ":7082")--http-base-url: Base URL for service discovery (auto-detected if empty)--http-auth-type: Authentication type - "none", "bearer", or "basic" (default: "none")--http-auth-token: Authentication token/credentials
--enable-monitoring: Enable Prometheus metrics and health endpoints (default: true)--monitoring-addr: Monitoring server address (default: ":9090")
When HTTP transport is enabled, the following endpoints are available on port 7082:
GET /: Service discovery with transport capabilitiesGET /health: Comprehensive health check with connection statusGET /ready: Kubernetes-style readiness probeGET /live: Kubernetes-style liveness probeGET /sse: Server-Sent Events endpoint for MCP communicationPOST /message: JSON-RPC message endpoint (requires sessionId from SSE)GET /sse/debug: Debug information for SSE endpointGET /message/debug: Debug information for message endpoint
When monitoring is enabled, Prometheus metrics are available on port 9090:
GET /metrics: Prometheus metrics endpoint (port 9090)
# Run all tests
go test -v ./...
# Run tests for a specific package
go test -v ./pkg/cache/...
# Run a single test
go test -v -run TestFunctionName ./pkg/tools/...
# Test HTTP transport functionality
go test -v ./pkg/server/ -run TestHTTPTransport
# Run comprehensive dual transport integration test
./test_dual_transport.sh# Format code
go fmt ./...
# Check for issues
go vet ./...
# Run linting (if golangci-lint is installed)
golangci-lint run ./...This is a Go implementation of the Model Context Protocol (MCP) server providing OpenStreetMap capabilities to LLMs. The architecture follows a layered approach with clear separation of concerns:
- MCP Server Layer (
pkg/server/) - Handles MCP protocol communication and request routing - Tools Layer (
pkg/tools/) - Implements 25 OSM-specific tools using a registry pattern - Core Utilities (
pkg/core/) - Shared functionality including HTTP retry logic, validation, error handling, and service clients - OSM Integration (
pkg/osm/) - OpenStreetMap API client with rate limiting and caching - Caching Layer (
pkg/cache/) - LRU caching for API responses and tile resources - Monitoring Layer (
pkg/monitoring/) - Prometheus metrics, health checking, and observability
- Registry Pattern: All tools are registered centrally in
pkg/tools/registry.gofor maintainability - Composable Tools: Tools are designed as primitives that can be combined for complex workflows
- Fluent Builders: Query builders (e.g., Overpass) use fluent interfaces for readability
- Service Pattern: External APIs (OSRM, Nominatim, Overpass) are wrapped in service objects with consistent interfaces
- Implement the tool handler function in
pkg/tools/ - Add the tool definition to the registry in
pkg/tools/registry.go - Follow the existing patterns for parameter validation and error handling using
pkg/core/utilities
The server integrates with several OpenStreetMap services, all with built-in rate limiting:
- Nominatim: Geocoding and reverse geocoding (default: 1 RPS)
- Overpass API: OSM data queries (default: 1 RPS)
- OSRM: Routing calculations (default: 1 RPS)
- OSM Tiles: Map image generation
The codebase uses structured error responses with error codes and user guidance. All errors should use the core.MCPError type for consistency. See pkg/core/errors.go for standard error types.
Uses log/slog with structured logging:
- Debug: Verbose diagnostic messages (enabled with --debug flag)
- Info: Routine operational messages
- Warn: Unexpected but non-critical conditions
- Error: Critical problems or failures
The server includes comprehensive monitoring capabilities built on Prometheus:
MCP Request Metrics:
osmmcp_mcp_requests_total: Total MCP requests by tool and statusosmmcp_mcp_request_duration_seconds: Request duration histograms by tool
External Service Metrics:
osmmcp_external_service_requests_total: External API requests by service/operation/statusosmmcp_external_service_request_duration_seconds: External API request duration histograms
Rate Limiting Metrics:
osmmcp_rate_limit_exceeded_total: Rate limit violations by serviceosmmcp_rate_limit_wait_duration_seconds: Time spent waiting for rate limits
Cache Metrics:
osmmcp_cache_hits_total: Cache hits by cache typeosmmcp_cache_misses_total: Cache misses by cache typeosmmcp_cache_size: Current cache size by cache type
System Metrics:
osmmcp_active_connections: Active connections by transport typeosmmcp_errors_total: Errors by component and typeosmmcp_goroutines: Current goroutine countosmmcp_memory_usage_bytes: Memory usage in bytesosmmcp_system_info: Build and system information
The monitoring system tracks health of external services:
- Nominatim: Geocoding service health
- Overpass: OSM query service health
- OSRM: Routing service health
Health status is calculated as:
healthy: All services operationaldegraded: Some services have issues but majority operationalunhealthy: Majority of services are failing
The Prometheus metrics can be integrated with:
- Grafana: For visualization and alerting
- Alertmanager: For alert routing and management
- Kubernetes: Health endpoints work with liveness/readiness probes
The server supports distributed tracing via OpenTelemetry (OTLP) for enhanced observability and debugging.
Enable tracing by setting the OTLP endpoint:
export OTLP_ENDPOINT=localhost:4317
./osmmcpMCP Tool Execution
- Each tool call creates a span with tool name, duration, status, and result size
- Errors are automatically recorded with stack traces
External Service Calls
- HTTP requests to Nominatim, Overpass, and OSRM
- Retry attempts and delays
- Rate limiting wait times
- Response status and size
Cache Operations
- Cache hits/misses for OSM and tile caches
- Cache key and type information
- Eviction events
HTTP Transport (when enabled)
- All HTTP requests with method, path, status
- Session ID correlation
- Request/response sizes
Jaeger
docker run -d --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
jaegertracing/all-in-one:latestGrafana Tempo
docker run -d --name tempo \
-p 3200:3200 \
-p 4317:4317 \
grafana/tempo:latestSee TRACING.md for detailed tracing documentation.