|
| 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 | +OBP-MCP is a Model Context Protocol (MCP) server for the Open Bank Project API, built with `fastmcp`. It exposes 600+ OBP API endpoints to AI assistants through a hybrid tag-based routing system with OAuth 2.1 authentication. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +All commands use `uv` as the package manager: |
| 12 | + |
| 13 | +```bash |
| 14 | +# Install/sync dependencies |
| 15 | +uv sync |
| 16 | + |
| 17 | +# Run the server |
| 18 | +./run_server.sh # normal mode |
| 19 | +./run_server.sh --watch # auto-reload on file changes |
| 20 | +uv run python src/mcp_server_obp/server.py # direct |
| 21 | + |
| 22 | +# Run tests |
| 23 | +uv run pytest # all tests |
| 24 | +uv run pytest tests/test_auth.py # single file |
| 25 | +uv run pytest -v # verbose |
| 26 | + |
| 27 | +# Generate data indexes (requires OBP_BASE_URL in .env) |
| 28 | +uv run python scripts/generate_endpoint_index.py |
| 29 | +uv run python scripts/generate_glossary_index.py |
| 30 | + |
| 31 | +# Add a dependency |
| 32 | +uv add <package> |
| 33 | +``` |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +### Three-Step Endpoint Discovery (not RAG) |
| 38 | + |
| 39 | +The server avoids vector databases. Instead it uses a tag-based discovery pattern: |
| 40 | + |
| 41 | +1. **`list_endpoints_by_tag(tags)`** — returns lightweight summaries (~50-100 tokens each) from `endpoint_index.json` (250KB) |
| 42 | +2. **`get_endpoint_schema(endpoint_id)`** — lazy-loads full OpenAPI schema from `endpoint_schemas.json` (4.3MB) |
| 43 | +3. **`call_obp_api(endpoint_id, ...)`** — executes the actual HTTP request against OBP-API |
| 44 | + |
| 45 | +Additional tools: `list_glossary_terms(search_query)` and `get_glossary_term(term_id)` for 800+ banking terms. |
| 46 | + |
| 47 | +### Key Modules |
| 48 | + |
| 49 | +- **`src/mcp_server_obp/server.py`** — FastMCP server definition, all tool/resource registrations |
| 50 | +- **`src/mcp_server_obp/auth.py`** — Multi-provider auth: `bearer-only`, `obp-oidc`, `keycloak`, `none` |
| 51 | +- **`src/mcp_server_obp/lifespan.py`** — Server lifecycle, startup index updates, periodic refresh |
| 52 | +- **`src/tools/endpoint_index.py`** — `EndpointIndex` class with strict Pydantic types, tag filtering, lazy schema loading |
| 53 | +- **`src/tools/glossary_index.py`** — `GlossaryIndex` class for term search/retrieval |
| 54 | +- **`database/`** — JSON index files, `startup_updater.py` for auto-refresh, `data_hash_manager.py` for change detection |
| 55 | +- **`scripts/`** — Standalone generators that fetch from OBP resource-docs/swagger API |
| 56 | + |
| 57 | +### Authentication Modes (`AUTH_PROVIDER` env var) |
| 58 | + |
| 59 | +| Mode | Use Case | Notes | |
| 60 | +|------|----------|-------| |
| 61 | +| `bearer-only` | Internal agents (e.g., Opey) | JWT validation only, multi-issuer support | |
| 62 | +| `obp-oidc` | External MCP clients | Full OAuth 2.1 + Dynamic Client Registration | |
| 63 | +| `keycloak` | External MCP clients | OAuth 2.1 + minimal DCR proxy workaround | |
| 64 | +| `none` | Development/testing | No auth required | |
| 65 | + |
| 66 | +### Data Flow |
| 67 | + |
| 68 | +- JSON indexes stored in `database/` — no external database needed |
| 69 | +- `DataHashManager` compares hashes to detect upstream changes |
| 70 | +- `IndexStartupUpdater` refreshes on startup if `UPDATE_INDEX_ON_STARTUP=true` |
| 71 | +- Periodic refresh configurable via `REFRESH_INTERVAL_MINUTES` |
| 72 | + |
| 73 | +## Configuration |
| 74 | + |
| 75 | +All config via environment variables. Copy `.env.example` to `.env`. Key variables: |
| 76 | + |
| 77 | +- `OBP_BASE_URL` — OBP API instance URL |
| 78 | +- `OBP_API_VERSION` — API version (e.g., `v6.0.0`) |
| 79 | +- `AUTH_PROVIDER` — Authentication mode (see table above) |
| 80 | +- `OBP_AUTHORIZATION_VIA` — How API calls are authorized: `oauth`, `consent`, or `none` |
| 81 | +- `LOG_LEVEL` — `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL` |
| 82 | +- `FASTMCP_HOST` / `FASTMCP_PORT` — Server bind address |
| 83 | + |
| 84 | +## Testing Conventions |
| 85 | + |
| 86 | +- Tests live in `tests/` using pytest |
| 87 | +- `conftest.py` provides shared fixtures (auth URLs, JWT payloads, `clean_env` for env isolation) |
| 88 | +- Test files: `test_auth.py` (auth providers), `test_endpoint_index.py` (endpoint index) |
| 89 | +- Tests use `pytest-asyncio` for async code |
0 commit comments