|
1 | 1 | # Repository Guidelines |
2 | 2 |
|
3 | | -These guidelines help contributors work effectively on the PostgreSQL MCP server in this repo. |
| 3 | +These guidelines help contributors work effectively on this repository. We gratefully acknowledge [mcp-postgres](https://github.com/gldc/mcp-postgres) as the chief inspiration for the MCP server function and this document. |
| 4 | + |
| 5 | +We also encourage reading [`docs/developer_guide.md`](/docs/developer_guide.md) for further useful information. |
| 6 | + |
| 7 | + |
| 8 | +## Project Structure & Module Organization |
| 9 | + |
| 10 | +- Entrypoint: [`stackql/main.go`](/stackql/main.go). |
| 11 | +- Ideally, foregin system semantics are dealt with in the `any-sdk` repository. |
| 12 | +- Loose adherence to popular idioms: |
| 13 | + - App internals in [`internal`](/internal). |
| 14 | + - Re-usable modules in [`pkg`](/pkg). |
| 15 | +— The MCP server function is built upon the golang MCP SDK. |
| 16 | +- CICD: please see [the github actions workflows](/.github/workflows). |
| 17 | +- Docs: `README.md`, this `AGENTS.md`. |
| 18 | + |
| 19 | +## Build, Test, and Development Commands |
| 20 | + |
| 21 | +- Create env: `python -m venv .venv && source .venv/bin/activate` |
| 22 | +- Install deps: `pip install -r requirements.txt` |
| 23 | +- Run server (no DB): `python postgres_server.py` |
| 24 | +- Run with DB: `POSTGRES_CONNECTION_STRING="postgresql://user:pass@host:5432/db" python postgres_server.py` |
| 25 | +- Docker build/run: `docker build -t mcp-postgres .` then `docker run -e POSTGRES_CONNECTION_STRING=... -p 8000:8000 mcp-postgres` |
| 26 | + |
| 27 | +## Coding Style & Naming Conventions |
| 28 | + |
| 29 | +- Publish and program to abstractions. |
| 30 | + |
| 31 | +## Testing Guidelines |
| 32 | + |
| 33 | +- Black box regression tests are effectively mandatory. The canaonical ones reside in [`test/robot/functional`](/test/robot/functional). |
| 34 | + |
| 35 | +## Tools & Resources |
| 36 | + |
| 37 | +- Please inspect using the API. |
| 38 | + |
| 39 | + |
| 40 | +## Commit & Pull Request Guidelines |
| 41 | + |
| 42 | +- Fork and pull model for general public; we **strongly** welcome public contributions, comment and issues. |
| 43 | + |
| 44 | +## Security & Configuration Tips |
| 45 | + |
| 46 | +- WIP. |
| 47 | + |
| 48 | +--- |
4 | 49 |
|
5 | 50 | ## StackQL Resource Key Encoding Quirk |
6 | 51 |
|
@@ -34,53 +79,3 @@ This ensures the backend treats the parameter as a literal string, not a path. |
34 | 79 | Many RESTful routing libraries (like gorilla/mux) treat slashes as path separators. Encoding slashes prevents misinterpretation and ensures correct resource access. |
35 | 80 |
|
36 | 81 | Refer to this section whenever you encounter issues with resource keys containing slashes or hierarchical identifiers. |
37 | | - |
38 | | - |
39 | | -## Project Structure & Module Organization |
40 | | -- Root module: `postgres_server.py` — FastMCP server exposing PostgreSQL tools. |
41 | | -- Config: `.env` (optional), `smithery.yaml` (publishing metadata). |
42 | | -- Packaging/infra: `requirements.txt`, `Dockerfile`. |
43 | | -- Docs: `README.md`, this `AGENTS.md`. |
44 | | -- No dedicated `src/` or `tests/` directories yet; keep server logic cohesive and small, or start a `src/` layout if adding modules. |
45 | | - |
46 | | -## Build, Test, and Development Commands |
47 | | -- Create env: `python -m venv .venv && source .venv/bin/activate` |
48 | | -- Install deps: `pip install -r requirements.txt` |
49 | | -- Run server (no DB): `python postgres_server.py` |
50 | | -- Run with DB: `POSTGRES_CONNECTION_STRING="postgresql://user:pass@host:5432/db" python postgres_server.py` |
51 | | -- Docker build/run: `docker build -t mcp-postgres .` then `docker run -e POSTGRES_CONNECTION_STRING=... -p 8000:8000 mcp-postgres` |
52 | | - |
53 | | -## Coding Style & Naming Conventions |
54 | | -- Python 3.10+, 4-space indentation, PEP 8. |
55 | | -- Use type hints (as in current code) and concise docstrings. |
56 | | -- Functions/variables: `snake_case`; classes: `PascalCase`; MCP tool names: short `snake_case`. |
57 | | -- Logging: use the existing `logger` instance; prefer informative, non-PII messages. |
58 | | -- Optional formatting/linting: `black` and `ruff` (not enforced in repo). Example: `pip install black ruff && ruff check . && black .`. |
59 | | - |
60 | | -## Testing Guidelines |
61 | | -- There is no test suite yet. Prefer adding `pytest` with tests under `tests/` named `test_*.py`. |
62 | | -- For DB behaviors, use a disposable PostgreSQL instance or mock `psycopg2` connections. |
63 | | -- Minimum smoke test: start server without DSN, verify each tool returns the friendly “connection string is not set” message. |
64 | | - |
65 | | -## Typed Tools & Resources |
66 | | -- Preferred tools: `run_query(QueryInput)` and `run_query_json(QueryJSONInput)` with validated inputs (via Pydantic) and `row_limit` safeguards. |
67 | | -- Legacy tools `query_v2`/`query_json` remain for backward compatibility. These return a json object with a property for rows. |
68 | | - - Note the `query_v2` requires input of the form `{ "tool": "query", "input": { "sql": "SELECT 1;", "row_limit": 1 } }` |
69 | | -- Table resources: `table://{schema}/{table}` (best-effort registration), with fallback tools `list_table_resources` and `read_table_resource`. |
70 | | -- Prompts available as MCP prompts and tools: `write_safe_select`, `explain_plan_tips`. |
71 | | - |
72 | | -## Tests |
73 | | -- Test deps: `dev-requirements.txt` (`pytest`, `pytest-cov`). |
74 | | -- Layout: `tests/test_server_tools.py` includes no-DSN smoke tests and prompt checks. |
75 | | -- Run: `pytest -q`. Ensure runtime deps installed from `requirements.txt`. |
76 | | - |
77 | | -## Commit & Pull Request Guidelines |
78 | | -- Commit style: conventional commits preferred (`feat:`, `fix:`, `chore:`, `docs:`). Keep subjects imperative and concise. |
79 | | -- PRs should include: purpose & scope, before/after behavior, example commands/queries, and any config changes (`POSTGRES_CONNECTION_STRING`, Docker, `mcp.json`). |
80 | | -- When adding tools, document them in `README.md` (name, args, example) and ensure safe output formatting. |
81 | | -- Never commit secrets. `.env`, `.venv`, and credentials are ignored by `.gitignore`. |
82 | | - |
83 | | -## Security & Configuration Tips |
84 | | -- Pass DB credentials via `POSTGRES_CONNECTION_STRING` env var; avoid hardcoding. |
85 | | -- Prefer least-privilege DB users and SSL options (e.g., add `?sslmode=require`). |
86 | | -- The server runs without a DSN for inspection; database-backed tools should fail gracefully (maintain this behavior). |
0 commit comments