|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +## Project Structure & Module Organization |
| 4 | +- `mcpgateway/`: FastAPI gateway source (entry `main.py`, `cli.py`, services, transports, templates/static, Alembic). |
| 5 | +- Services: `mcpgateway/services/` (gateway, server, tool, resource, prompt logic). |
| 6 | +- Transports: `mcpgateway/transports/` (SSE, WebSocket, stdio, streamable HTTP). |
| 7 | +- Plugins: `plugins/` (`framework/`, plugin configs in `plugins/config.yaml`). |
| 8 | +- Plugins: `plugins/` (built-in filters and utilities like `pii_filter/`, `deny_filter/`, `regex_filter/`, `resource_filter/`; main configuration in `plugins/config.yaml`). |
| 9 | +- Tests: `tests/unit`, `tests/integration`, `tests/e2e`, `tests/playwright`. |
| 10 | +- Docs & ops: `docs/`, `deployment/`, `charts/`, `examples/`. Build artefacts: `build/`, `dist/`. |
| 11 | + |
| 12 | +## Build, Test, and Development Commands |
| 13 | +- Pre-commit: `make autoflake isort black pre-commit` |
| 14 | +- Setup: `make venv`, `make install-dev`. |
| 15 | +- Run: `make dev` (hot reload on :8000), `make serve` (gunicorn), or `mcpgateway --host 0.0.0.0 --port 4444`. |
| 16 | +- Quality: `make lint`, `make lint-web`, `make check-manifest`. |
| 17 | +- Tests: `make test`, `make doctest`, `make htmlcov` (HTML to `docs/docs/coverage/index.html`). |
| 18 | +- Final check: `make doctest test htmlcov smoketest lint-web flake8 bandit interrogate pylint verify` |
| 19 | + |
| 20 | +## Makefile Quick Reference |
| 21 | +- `make dev`: Run fast-reload dev server on `:8000`. |
| 22 | +- `make serve`: Run production Gunicorn server on `:4444`. |
| 23 | +- `make certs`: Generate self-signed TLS certs in `./certs/`. |
| 24 | +- `make serve-ssl`: Run Gunicorn behind HTTPS on `:4444` (uses `./certs`). |
| 25 | +- `make lint`: Run full lint suite; `make install-web-linters` once before `make lint-web`. |
| 26 | +- `make test`: Run unit tests; `make coverage` writes HTML to `docs/docs/coverage/`. |
| 27 | +- `make doctest`: Run doctests across `mcpgateway/` modules. |
| 28 | +- `make check-env`: Verify `.env` keys match `.env.example`. |
| 29 | +- `make clean`: Remove caches, build artefacts, venv, coverage, docs, certs. |
| 30 | + |
| 31 | +MCP helpers |
| 32 | +- JWT token: `python -m mcpgateway.utils.create_jwt_token --username admin --exp 10080 --secret KEY`. |
| 33 | +- Expose stdio server: `python -m mcpgateway.translate --stdio "uvx mcp-server-git" --port 9000`. |
| 34 | + |
| 35 | +## Coding Style & Naming Conventions |
| 36 | +- Python >= 3.11. Type hints required; strict `mypy` settings. |
| 37 | +- Formatters/linters: Black (line length 200), isort (profile=black), Ruff (F,E,W,B,ASYNC), Pylint as configured in `pyproject.toml` and dotfiles. |
| 38 | +- Naming: `snake_case` for modules/functions, `PascalCase` for classes, `UPPER_CASE` for constants. |
| 39 | +- Group imports per isort sections (stdlib, third-party, first-party `mcpgateway`, local). |
| 40 | + |
| 41 | +## Testing Guidelines |
| 42 | +- Pytest with async; discovery configured in `pyproject.toml`. |
| 43 | +- Layout: unit (`tests/unit`), integration (`tests/integration`), e2e (`tests/e2e`), UI (`tests/playwright`). |
| 44 | +- Naming: files `test_*.py`, classes `Test*`, functions `test_*`; marks: `slow`, `ui`, `api`, `smoke`, `e2e`. |
| 45 | +- Commands: `make test`, `pytest -k "name"`, `pytest -m "not slow"`. Use `make coverage` for reports. |
| 46 | +- Keep tests deterministic, isolated, and fast by default. |
| 47 | + |
| 48 | +## Commit & Pull Request Guidelines |
| 49 | +- Conventional Commits (`feat:`, `fix:`, `docs:`, `refactor:`, `chore:`). Link issues (e.g., `Closes #123`). |
| 50 | +- Sign every commit with DCO: `git commit -s`. |
| 51 | +- Do not mention Claude or Claude Code in PRs/diffs. Do not include effort estimates or "phases". |
| 52 | +- Include tests and docs for behavior changes; attach screenshots for UI changes when relevant. |
| 53 | +- Require green lint and tests locally before opening a PR. |
| 54 | + |
| 55 | +## Architecture Overview |
| 56 | +- Core: FastAPI + Pydantic with SQLAlchemy. Architectural decisions live under `docs/docs/architecture/adr/`. |
| 57 | +- Data: SQLite by default; PostgreSQL via extras. Migrations managed with Alembic in `mcpgateway/alembic/`. |
| 58 | +- Caching & Federation: Optional Redis, mDNS/Zeroconf discovery, peer registration, health checks and failover. |
| 59 | +- Virtual Servers: Compose tools, prompts, and resources across multiple MCP servers; control tool visibility per server. |
| 60 | +- Transports: SSE, WebSocket, stdio wrapper, and streamable HTTP endpoints. |
| 61 | + |
| 62 | +## Security & Configuration Tips |
| 63 | +- Copy `.env.example` → `.env`; verify with `make check-env`. Never commit secrets. |
| 64 | +- Auth: set `JWT_SECRET_KEY`; export `MCPGATEWAY_BEARER_TOKEN` using the token utility for API calls. |
| 65 | +- Wrapper: set `MCP_SERVER_CATALOG_URLS` and `MCP_AUTH_TOKEN` when using `mcpgateway.wrapper`. |
| 66 | +- TLS: `make certs` → `make serve-ssl`. Prefer environment variables for config; see `README.md`. |
0 commit comments