Skip to content

Wire the postgres store into the runtime, CLI, and MCP server - #710

Merged
arrry-hydraDB merged 1 commit into
adityamishra/oss-136-pg-walk-cachefrom
adityamishra/oss-136-pg-wiring
Dec 4, 2026
Merged

arrry-hydraDB merged 1 commit into
adityamishra/oss-136-pg-walk-cachefrom
adityamishra/oss-136-pg-wiring

Conversation

@adityamishra-hydradb

@adityamishra-hydradb adityamishra-hydradb commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

5/5 of #706. Adds store=postgres to the runtime, CLI, and MCP server of both SDKs: --uri takes the postgresql:// login and --database names the pg_hydradb graph.
Adds the docs page for the store, and the secret-echo probe now covers it.

Implementation details

Door: one-way
New store value and new settings errors, shared by the CLI, SELFGRAPH_*, and MCP in both SDKs.

Cleanup: none

What to delete:

Decisions

  • No new setting. database already names the graph for FalkorDB, so it names the pg_hydradb graph here. The login lives in the URI, so auth is ignored with the usual warning.
  • store=postgres needs a postgres:// or postgresql:// URI and a graph name; each missing piece is invalid_setting with its field. The message does not echo the URI, since a query string can hold a password.
  • A URI without store still means HydraDB, as before. The store gets the settings namespace, since it serves only one.
  • scripts/probes/secret_echo.py --store postgres checks the API, settings, CLI, and MCP paths with marker passwords in the URI. Side fix in the same file: the CLI path ran main() inside the probe's event loop, so it only ever saw an internal_error from asyncio.run; it now runs in a worker thread and reaches the real connection error, for the Bolt stores too.
  • The conformance pair checks the postgres errors (write, scan, bad URI, missing graph) byte for byte. The unreachable-server text is checked by hand: it needs the optional driver, which CI's Python does not install.
  • CI (decided by the maintainers on 2026-12-05): #729 adds the CI job postgres. It builds pg_hydradb from a pinned hydradb commit and runs these gated tests of both SDKs on Postgres 16 and 17. No image goes to a registry.
  • docs/backends.md gets the Postgres section (setup in Docker, Python, TypeScript, CLI, MCP, the statements the store runs, the trigram index, and the limits); docs/cli.md lists the new store.

Validation

  • tests/test_runtime.py and test/pgHydradbStore.test.ts: settings errors and the store the settings build. Gated tests drive the CLI (path) and a read-only MCP server (retrieve) against Postgres 16, 17, and 18.
  • Smoke: selfgraph --store postgres --uri ... --database work retrieve "who works at Acme" prints the Acme employees; mcp --read-only starts and serves; SyncSelfGraph(PgHydraDBStore(...)).neighbors(...) returns the right rows.
  • Dogfood: the public repos, contributors, issues, and labels of the hydra-db GitHub org (pulled with gh) went into Postgres tables and a pg_hydradb graph. An agent asked 5 questions through the MCP tools; all 5 answers matched the GitHub data. This found that check_readiness called the graph unreachable; 1/5 now fixes that.
  • Docs repro: a clean venv with the built wheel and an empty npm folder with the packed package followed the new section block by block (Docker build, SQL, Python, TypeScript, CLI, MCP); every step passed. Earlier runs found two docs bugs, now fixed: the example printed a path that does not exist, and selfgraph mcp needs the mcp extra.
  • secret_echo.py for neo4j, hydradb, cypher, and postgres: clean.
  • precheck --base 4/5: all checks passed.
  • Python suite on embedded Kuzu: main 1743 passed, 39 skipped; branch 1750 passed, 48 skipped, 0 failed.
  • TypeScript lint (Biome), typecheck, build, and test with the conformance pair: main 1420 passed, 27 skipped; branch 1427 passed, 36 skipped, 0 failed; CI runs the same suites green on every PR. One earlier run of main timed out in conformanceGraph while Docker builds loaded the machine; the rerun passed.
  • make probes: plan_apply, secret_echo, and unmerge_order pass; parity_table fails the same way on main and on the branch (vitest cannot parse a .scm query file in this environment). ruff check and ruff format --check: clean.
  • The statement log of a final run on Postgres 16, 17, and 18 (tests, E2E, security, MCP, CLI) holds only the registry reads, the walk, the key lookups, and the name lookup.

Limits

Same as 2/5. The MCP server's check_answerable still raises unsupported_read for this store; agents can go on to retrieve, as its instructions say. The maintainers decided on 2026-12-05 to keep this limit (see 2/5).

Linked issue

Closes #706

AI Assistance

Model Effort
Claude Opus 5.5 High

Checklist

  • Implements an issue a maintainer has /approved.
  • Small and scoped to that issue.
  • New errors have a code and hint, the same on API, CLI, and MCP in both SDKs (see AGENTS.md).
  • Breaking changes described below, or none.

Breaking changes

None.

🤖 Generated with Claude Code

@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@hydra-mira-review

hydra-mira-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Mira score 5/5 · 🟢 Good to merge

  • No findings in the code.
  • Ship with or after: pg_hydradb extension, registered graph, and reader permissions.

Users can select PostgreSQL storage through the runtime, command line, and MCP server in both SDKs. Shared settings require a PostgreSQL URI and graph name. Documentation, tests, and probes cover setup, matching errors, and password redaction.

Before this ships · 1 with another PR, 1 in place
  • ⏳ pg_hydradb extension, registered graph, and reader permissions (schema), needed in The selected Postgres server. The backend remains off unless store=postgres is selected; initialization requires pg_hydradb registry tables, an available graph, and readable registered tables. Install pg_hydradb, register the graph, and grant the login SELECT access before selecting store=postgres.
  • ✅ Optional Postgres drivers (config), needed in Python and TypeScript package dependencies. pyproject.toml already declares the postgres extra with asyncpg; typescript/package.json already declares optional peer dependency pg.
How this PR works · 5 changes, 2 medium risk, 3 low risk

Postgres tables can already be read through the store, but settings cannot select it. This final layer wires that store into both SDKs, their CLIs, and MCP servers. It reuses existing connection settings and adds validation, credential probes, documentation, and integration coverage.

1. Validate Postgres addresses and require a graph name · 🟠 medium risk · src/selfgraph/runtime.py +1

Users now receive specific errors for invalid Postgres settings instead of an unknown-store error. Both validators accept postgres:// or postgresql:// and require a nonempty database.

Risk: Incorrect validation prevents Postgres users from connecting or lets invalid settings fail later during initialization.

Check:

  • Check both accepted schemes, a missing URI, a Bolt URI, and a missing graph name in both SDKs.
  • Check that a rejected address containing a query-string password never appears in the error.

In runtime.py:456-473, runtime.py:692-702, runtime.ts:668-680 and 1 more.

2. Build the Postgres store from shared connection settings · 🟠 medium risk · src/selfgraph/runtime.py +1

Users can now select the existing read-only Postgres backend through settings in either SDK. The factories pass database as the graph name and preserve the configured namespace.

Risk: Incorrect factory arguments make SDK reads, CLI commands, or MCP tools use the wrong graph or fail namespace validation.

Check:

  • Read the same registered graph through SDK settings, CLI path, and MCP retrieve.
  • Connect with a nondefault namespace and separate auth; confirm reads succeed and the ignored-setting warning contains no credential.

In runtime.py:99-101, runtime.py:555-558, runtime.ts:61 and 3 more.

3. Probe Postgres credentials across four entry points · 🟢 low risk · scripts/probes/secret_echo.py

Credential probes now cover Postgres connection failures. _postgres puts encoded marker passwords in a URI and captures direct API, settings, CLI, and MCP output.

Risk: An incomplete capture lets credential leaks pass the probe unnoticed.

Check:

  • Confirm each Postgres entry point reaches a connection failure and captures its error text or MCP payload.

In secret_echo.py:148-217, secret_echo.py:227-229, secret_echo.py:250-255.

4. Let CLI credential probes reach the connection attempt · 🟢 low risk · scripts/probes/secret_echo.py

CLI probes now reach backend connection errors instead of failing because an event loop is already running. Both probe paths invoke the synchronous CLI through asyncio.to_thread.

Risk: A regression makes CLI probes inspect an event-loop error instead of the connection error that might expose credentials.

Check:

  • Check that a Bolt CLI probe reports a connection failure rather than an asyncio.run error.

In secret_echo.py:168, secret_echo.py:230-235.

5. Supporting changes · 🟢 low risk · tests/test_runtime.py +6

Tests cover settings construction, CLI and MCP reads, and matching error payloads across SDKs. Documentation adds setup instructions, connection examples, supported reads, SQL statements, and limits.

Risk: Incorrect examples misconfigure deployments, while incomplete assertions let settings or error-contract regressions escape.

Check:

  • Check the documented registration and reader grants against the store's registry checks.

In test_runtime.py:858-868, test_pg_hydradb_store.py:209-222, pgHydradbStore.test.ts:53-72 and 8 more.

Requirement check · 10 met · from the PR description
  • ✅ Expose store=postgres through runtime settings, CLI, environment variables, and MCP in both SDKs (met). Both runtime registries add postgres; CLI choices use those registries, and both MCP servers construct graphs through the shared settings path.
  • ✅ Use the URI for the login and database for the pg_hydradb graph without adding settings (met). _build_store and SERVER_STORES.postgres pass the existing URI and database to the store constructor.
  • ✅ Ignore separate auth with the existing warning behavior (met). Both ignored-setting maps add Postgres auth; existing CLI and factory paths emit warnings and omit it from construction.
  • ✅ Require a Postgres URI and graph name with field-specific invalid_setting errors (met). check_settings and checkSettings enforce URI presence; the new helpers validate the scheme and graph name.
  • ✅ Avoid echoing the URI in the new Postgres validation message (met). _require_postgres and requirePostgres use a fixed scheme-error message without interpolating the URI.
  • ✅ Keep HydraDB as the default when a URI is supplied without a store (met). store_kind and storeKind still resolve an unnamed URI to hydradb.
  • ✅ Pass the configured namespace to the single-namespace Postgres store (met). Both Postgres factory branches pass the settings namespace, defaulting to default.
  • ✅ Cover Postgres credentials through API, settings, CLI, and MCP, and fix nested event-loop execution (met). _postgres captures all four paths; both CLI probe paths use asyncio.to_thread.
  • ✅ Compare Postgres write, scan, bad-URI, and missing-graph errors across SDKs (met). Both conformance implementations add matching postgres_write, postgres_scan, postgres_uri, and postgres_graph cases.
  • ✅ Document backend setup, SDK and CLI usage, MCP, statements, indexing, and limits (met). docs/backends.md adds the Postgres section, and docs/cli.md describes the new store and connection flags.
Diagram of the changed files
graph LR
  pytests["tests/test_runtime.py"] --> pyruntime["src/selfgraph/runtime.py"]
  tstests["typescript/test/pgHydradbStore.test.ts"] --> tsruntime["typescript/src/runtime.ts"]
  pyconformance["typescript/test/conformance/py_side.py"] --> pyruntime
  tsconformance["typescript/test/conformance/ts_side.ts"] --> tsruntime
Loading

Comment @hydra-mira-review help for commands.

@hydra-mira-review hydra-mira-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mira Review Summary

The conformance job fails because its Python environment lacks the Postgres driver. The new connection error comparison in typescript/test/conformance/py_side.py:2216 also fails in CI because asyncpg is excluded.

Key Issues

Issue Location
🔴 The new connection-error comparison fails in CI because its Python installation excludes asyncpg. typescript/test/conformance/py_side.py:2216

Comment thread typescript/test/conformance/py_side.py Resolved
@adityamishra-hydradb
adityamishra-hydradb removed this pull request from stack #711 December 4, 2026 20:47
@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from 7ddd586 to 8614e29 Compare December 4, 2026 20:47
@adityamishra-hydradb
adityamishra-hydradb changed the base branch from adityamishra/oss-136-pg-store-ts to adityamishra/oss-136-pg-walk-cache December 4, 2026 20:47
@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from 8614e29 to 8d982bd Compare December 4, 2026 20:49
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from 8d982bd to 898ff57 Compare December 4, 2026 20:56

@hydra-mira-review hydra-mira-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mira Review Summary

An invalid Postgres URI can expose its database password in error output from src/selfgraph/runtime.py:464.

Comment thread src/selfgraph/runtime.py Resolved
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@hydra-mira-review hydra-mira-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mira Review Summary

A mistyped database URI can expose its query-string password in validation errors from typescript/src/runtime.ts:670. This should be addressed to prevent credentials from appearing in error messages.

Comment thread typescript/src/runtime.ts Resolved
@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from 898ff57 to d05a593 Compare December 4, 2026 21:19
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from d05a593 to e695e8b Compare December 4, 2026 21:37
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from e695e8b to 07ab813 Compare December 4, 2026 21:49
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from 07ab813 to a52ff47 Compare December 4, 2026 22:00
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

Signed-off-by: adityamishra-hydradb <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@adityamishra-hydradb
adityamishra-hydradb force-pushed the adityamishra/oss-136-pg-wiring branch from a52ff47 to a86fa49 Compare December 4, 2026 22:11
@adityamishra-hydradb

Copy link
Copy Markdown
Collaborator Author

@hydra-mira-review review

@arrry-hydraDB arrry-hydraDB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arrry-hydraDB
arrry-hydraDB merged commit 73946bf into main Dec 4, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read Postgres tables through pg_hydradb with a read-only store

2 participants