@synapsor/runner 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +15 -13
  2. package/TRADEMARKS.md +23 -0
  3. package/dist/cli.js +15 -8723
  4. package/dist/runner.mjs +8767 -0
  5. package/docs/MCP_RUNNER_IMPLEMENTATION_PLAN.md +187 -0
  6. package/docs/README.md +56 -0
  7. package/docs/architecture.md +65 -0
  8. package/docs/capability-config.md +180 -0
  9. package/docs/cloud-mode.md +140 -0
  10. package/docs/config-migrations.md +67 -0
  11. package/docs/demo-transcript.md +73 -0
  12. package/docs/dependency-license-inventory.md +35 -0
  13. package/docs/first-10-minutes.md +147 -0
  14. package/docs/getting-started-own-database.md +367 -0
  15. package/docs/licensing.md +38 -0
  16. package/docs/limitations.md +75 -0
  17. package/docs/local-mode.md +246 -0
  18. package/docs/local-ui.md +163 -0
  19. package/docs/mcp-audit.md +135 -0
  20. package/docs/mcp-client-setup.md +155 -0
  21. package/docs/mcp-efficiency-benchmark.md +84 -0
  22. package/docs/operations.md +38 -0
  23. package/docs/own-db-20-minutes.md +185 -0
  24. package/docs/production-readiness.md +39 -0
  25. package/docs/protocol.md +90 -0
  26. package/docs/recipes.md +61 -0
  27. package/docs/roadmap.md +13 -0
  28. package/docs/schema-inspection.md +88 -0
  29. package/docs/security-boundary.md +70 -0
  30. package/docs/shadow-mode.md +67 -0
  31. package/docs/telemetry.md +28 -0
  32. package/docs/threat-model.md +25 -0
  33. package/docs/troubleshooting-first-run.md +248 -0
  34. package/docs/trusted-context.md +70 -0
  35. package/docs/writeback-executors.md +128 -0
  36. package/examples/dangerous-mcp-tools.json +88 -0
  37. package/examples/reference-support-billing-app/README.md +86 -0
  38. package/examples/reference-support-billing-app/docker-compose.yml +13 -0
  39. package/examples/reference-support-billing-app/mcp-client.generic.json +11 -0
  40. package/examples/reference-support-billing-app/schema.sql +55 -0
  41. package/examples/reference-support-billing-app/scripts/run-demo.sh +7 -0
  42. package/examples/reference-support-billing-app/seed.sql +26 -0
  43. package/examples/reference-support-billing-app/synapsor.runner.json +136 -0
  44. package/package.json +10 -4
  45. package/recipes/accounts.trial_extension.json +42 -0
  46. package/recipes/billing.late_fee_waiver.json +46 -0
  47. package/recipes/credits.account_credit.json +45 -0
  48. package/recipes/orders.refund_review.json +57 -0
  49. package/recipes/support.ticket_resolution.json +51 -0
  50. package/dist/bin.cjs +0 -13
@@ -0,0 +1,187 @@
1
+ # MCP runner implementation plan
2
+
3
+ Branch: `mcp-commit-safe-runtime`
4
+
5
+ This plan maps the existing open-source runner repository to the commit-safe database MCP goal. The runner is a local-first MCP and database safety runtime, not a copy of the Synapsor C++ DBMS.
6
+
7
+ ## Current inventory
8
+
9
+ ### Existing package structure
10
+
11
+ - `packages/protocol`
12
+ - Zod schemas for the current `protocol_version: "1.0"` writeback job/result shape.
13
+ - `packages/worker-core`
14
+ - Runner config, env loading, redaction, doctor checks, polling loop, job validation.
15
+ - `packages/control-plane-client`
16
+ - Runner-token HTTP client for registration, heartbeat, adapter catalog/call, claim, lease renewal, result, and doctor.
17
+ - `packages/postgres`
18
+ - Parameterized single-row Postgres update adapter, identifier validation, receipt table, idempotency, tenant guard, version conflict guard.
19
+ - `packages/mysql`
20
+ - Parameterized single-row MySQL update adapter with equivalent safety checks.
21
+ - `apps/runner`
22
+ - CLI entrypoint with `doctor`, `validate`, `apply`, and `start`.
23
+ - `examples/postgres-support`
24
+ - Local approved writeback fixture for support tickets.
25
+ - `examples/mysql-orders`
26
+ - Local approved writeback fixture for orders/refund review.
27
+ - `scripts/smoke-local-examples.mjs`
28
+ - Docker-backed local smoke for Postgres/MySQL apply, idempotent retry, stale conflict, tenant mismatch, and disallowed column behavior.
29
+
30
+ ### Baseline behavior
31
+
32
+ - Existing test baseline before edits: `corepack pnpm test` passed 5 files / 13 tests.
33
+ - Current worker already rejects arbitrary identifiers, patch columns outside allowlist, primary/tenant patch allowlisting, and missing approval id.
34
+ - Current job protocol is useful but not yet the required public protocol names:
35
+ - existing: `protocol_version: "1.0"`
36
+ - required: `synapsor.change-set.v1`, `synapsor.writeback-job.v1`, `synapsor.execution-receipt.v1`, `synapsor.runner-registration.v1`
37
+
38
+ ## Implementation phases
39
+
40
+ ### Phase 1: shared public protocol
41
+
42
+ - Add `schemas/*.schema.json`.
43
+ - Add `fixtures/protocol/*.json`.
44
+ - Add a shared checksum manifest.
45
+ - Current status: `fixtures/protocol/MANIFEST.json` records the schema/fixture SHA-256 set mirrored into the main Synapsor repository as `protocol/MANIFEST.json`; protocol tests verify all listed hashes.
46
+ - Extend `packages/protocol` to parse:
47
+ - current legacy `protocol_version: "1.0"` jobs/results
48
+ - public `schema_version: "synapsor.writeback-job.v1"` jobs
49
+ - public `schema_version: "synapsor.execution-receipt.v1"` receipts
50
+ - public `schema_version: "synapsor.change-set.v1"` proposals
51
+ - public `schema_version: "synapsor.runner-registration.v1"` runner registration
52
+ - Normalize public writeback jobs into the existing worker shape so the current Postgres/MySQL adapters remain stable.
53
+ - Add tests proving protocol fixtures parse and no credentials/unrestricted SQL are present.
54
+
55
+ ### Phase 2: local capability runtime and store
56
+
57
+ - Add a strict YAML/JSON config loader for semantic capabilities.
58
+ - Current status: JSON validator implemented in `packages/config`.
59
+ - Reject arbitrary SQL, model-controlled table/schema/column names, missing tenant/primary guards, and proposal capabilities without allowlisted columns.
60
+ - Current status: implemented in `packages/config` unit tests.
61
+ - Add local SQLite migrations for proposals, events, evidence, query audit, approvals, jobs, receipts, replay, and runner state.
62
+ - Current status: proposal/event/approval/evidence/query-audit/writeback-job/idempotency-receipt/replay/runner-state foundation implemented in `packages/proposal-store`.
63
+ - Add proposal immutability and approval-by-hash/version.
64
+ - Current status: implemented for proposal creation and approval in `packages/proposal-store`.
65
+ - Add approved proposal to public writeback job generation.
66
+ - Current status: implemented through `ProposalStore.createWritebackJobFromProposal` and `synapsor proposals writeback-job`.
67
+
68
+ ### Phase 3: MCP stdio server
69
+
70
+ - Add official MCP TypeScript SDK pinned to a stable version.
71
+ - Current status: implemented in `packages/mcp-server` with `@modelcontextprotocol/sdk@1.29.0`.
72
+ - Implement stdio transport first.
73
+ - Current status: `corepack pnpm runner mcp serve --config ./synapsor.runner.json --store ./.synapsor/local.db`.
74
+ - Expose semantic tools only:
75
+ - `billing.inspect_invoice`
76
+ - `billing.propose_late_fee_waiver`
77
+ - `support.inspect_ticket`
78
+ - `support.propose_ticket_resolution`
79
+ - `orders.inspect_order`
80
+ - `orders.propose_refund_review`
81
+ - Do not expose `execute_sql`, generic query tools, approval tools, or commit tools to the model.
82
+ - Current status: enforced by config/runtime shape and covered by `packages/mcp-server/src/index.test.ts`.
83
+ - Add read-only resources:
84
+ - `synapsor://proposals/{proposal_id}`
85
+ - `synapsor://evidence/{evidence_bundle_id}`
86
+ - `synapsor://replay/{replay_id}`
87
+ - Current status: implemented in the local stdio server and direct runtime resource reader.
88
+
89
+ ### Phase 4: local CLI approval and replay
90
+
91
+ - Add:
92
+ - `synapsor proposals list`
93
+ - `synapsor proposals show`
94
+ - `synapsor proposals approve`
95
+ - `synapsor proposals reject`
96
+ - `synapsor replay show`
97
+ - `synapsor replay export`
98
+ - `synapsor mcp serve`
99
+ - Add `synapsor mcp audit`
100
+ - Current status:
101
+ - `synapsor proposals list/show/approve/reject` implemented against `packages/proposal-store`.
102
+ - `synapsor replay show/export` implemented against `packages/proposal-store`.
103
+ - `synapsor mcp audit` implemented.
104
+ - `synapsor mcp serve` implemented for local stdio mode.
105
+ - `synapsor init`, `synapsor runner start`, `synapsor runner doctor`, and `synapsor cloud connect` implemented as CLI entrypoints for starter config, runner aliases, and Cloud token/config validation.
106
+ - Approval must show exact diff, evidence summary, conflict guard, tenant/object scope, source mutation state, and proposal hash/version.
107
+ - Current status: `proposals show` and non-JSON `proposals approve` / `proposals reject` print trusted principal, tenant, target row, primary key, required role, proposal hash/version, allowed columns, conflict guard, evidence bundle/query fingerprint/item count, writeback boundary, source-mutation state, and exact before/after diff before local approval/rejection.
108
+
109
+ ### Phase 5: demos
110
+
111
+ - Add real disposable MCP demos:
112
+ - `examples/mcp-postgres-billing`
113
+ - `examples/mcp-postgres-support`
114
+ - `examples/mcp-mysql-orders`
115
+ - Each demo needs Docker Compose, schema, seed data, read/write users where practical, config, client snippets, happy path, conflict path, cleanup, and expected output.
116
+ - The stale-row conflict demo must show:
117
+ - proposal created
118
+ - source unchanged
119
+ - out-of-band row change
120
+ - approval
121
+ - guarded worker returns conflict
122
+ - no write applied
123
+ - Current status: `examples/mcp-postgres-billing` plus `corepack pnpm test:mcp-local` covers MCP stdio `tools/list`, tool calls, evidence resource read, source unchanged before approval, approval, generated `synapsor.writeback-job.v1`, guarded apply, idempotent retry, and stale-row conflict.
124
+ - Current status: equivalent first-class MCP example directories exist for support-ticket and MySQL orders. `corepack pnpm test:mcp-local` exercises Postgres billing, Postgres support, and MySQL orders through stdio MCP plus guarded writeback.
125
+ - Current status: public local entrypoint added as `./scripts/demo-docker.sh` and `corepack pnpm demo:docker`; it requires Docker only on the host, runs the TypeScript runner inside a local demo image, runs the Docker-backed stdio MCP proof, and tears down containers/volumes. The contributor path remains `./scripts/demo-local.sh` and `corepack pnpm demo:local`.
126
+
127
+ ### Phase 6: Cloud-linked mode
128
+
129
+ - Add Cloud client registration/heartbeat/tool catalog/tool call/claim/lease/result support.
130
+ - Current status: `packages/control-plane-client` exposes runner registration, runner heartbeat, adapter tool catalog, adapter tool call, writeback claim, lease renewal through heartbeat, and receipt submission helpers with transient retry/backoff.
131
+ - Current status: `synapsor cloud connect --config ./synapsor.cloud.json` now verifies the scoped runner token, registers runner id/version/source/engine/capability metadata, and sends an initial heartbeat.
132
+ - Do not send DB credentials to Cloud.
133
+ - Current status: client tests assert runner registration/heartbeat payloads do not include DB URLs or obvious secrets.
134
+ - Current status: runner CLI tests assert `cloud connect` does not print or send runner tokens, database URLs, or credential-shaped values.
135
+ - Keep write credentials local.
136
+ - Keep local and Cloud histories separate unless explicit import is later implemented.
137
+ - Current status: `mode: "cloud"` delegates adapter tool catalog and tool calls through `ControlPlaneClient`. The main repository now exposes the compatible `/v1/agent/adapters/tools` and `/v1/agent/adapters/call-tool` runner-token bridge with `adapter:read` / `adapter:invoke` permissions.
138
+ - Current status: `corepack pnpm test:mcp-cloud-linked` exercises a hosted-compatible Cloud-linked lifecycle against a mock Cloud API and disposable Postgres billing fixture: runner-token doctor, runner registration, heartbeat, Cloud-mode MCP `tools/list`, Cloud adapter tool call, trusted session binding, source unchanged before approval, approved job claim/lease, real guarded Postgres writeback, and terminal receipt submission.
139
+
140
+ ## Current next edits
141
+
142
+ - Phase 1 protocol schemas/fixtures are implemented locally and covered by protocol tests.
143
+ - `synapsor mcp audit <target>` is implemented as a static MCP database risk review for exported manifests/tools-list payloads.
144
+ - Validated capability config and the local store are wired into a real MCP stdio server/runtime.
145
+ - Public local demo entrypoint is implemented as `./scripts/demo-docker.sh` / `corepack pnpm demo:docker`; it requires Docker only, builds a small local runner image, starts Docker fixture databases, runs the stdio MCP proof, proves guarded writeback/stale-row conflict, and tears down disposable resources. The contributor path remains `./scripts/demo-local.sh` / `corepack pnpm demo:local` for environments that already have Node/Corepack installed.
146
+ - Runtime modes are enforced in the store/CLI/runtime layers: `read_only` exposes read tools only and direct proposal calls fail closed, `shadow` stores proposals/evidence/query-audit/replay but rejects approval and writeback-job creation, and `review` enables local approval plus guarded writeback.
147
+ - Local `apply --store` records a public `synapsor.execution-receipt.v1` into the SQLite proposal store, so replay includes applied/conflict terminal writeback receipts instead of only pre-write proposal history.
148
+ - Next code-only work is broader release hardening: optional localhost approval UI, main-repo Cloud/UI gaps, and live hosted Cloud E2E once a compatible Cloud workspace/adapter/token is available.
149
+ - Preserve existing worker behavior while adding local MCP/runtime layers.
150
+ - Keep the existing Docker smoke path working.
151
+
152
+ ## Release blockers
153
+
154
+ - Live hosted Cloud-linked E2E still requires a compatible Synapsor Cloud workspace, adapter, and scoped runner token. A local hosted-compatible Cloud-linked smoke now covers the protocol/API lifecycle against a mock Cloud API and real disposable Postgres writeback.
155
+ - `packages/proposal-store` currently uses Node 22 `node:sqlite`, which is still marked experimental by Node. Before a public runner release, either pin/support that runtime explicitly or replace it with a stable SQLite dependency.
156
+ - Release docs present: `LICENSE` is Apache License 2.0, and `CONTRIBUTING.md` / `CODE_OF_CONDUCT.md` exist with project-specific safety guidance.
157
+
158
+ ## Verification log
159
+
160
+ - `corepack pnpm --filter @synapsor-runner/mcp-server test` passed after read-only catalog enforcement: read-only mode now lists only inspect/read tools while direct proposal calls still return `PROPOSALS_DISABLED`.
161
+ - `corepack pnpm test` passed after read-only catalog enforcement: 9 test files, 48 tests.
162
+ - `corepack pnpm test` passed after shadow/read-only mode enforcement: 9 test files, 47 tests.
163
+ - `corepack pnpm test:mcp-local` passed: Postgres billing, Postgres support, and MySQL orders stdio MCP flows all completed local approval, guarded writeback, idempotent retry, and stale-row conflict proof.
164
+ - `corepack pnpm --filter @synapsor-runner/control-plane-client test` passed after main-repo runner adapter bridge verification: 1 test file, 3 tests.
165
+ - `./scripts/demo-docker.sh` passed after adding the Docker-only wrapper, temporary dependency volumes, and `host.docker.internal` fixture routing. The command required only Docker on the host, ran the TypeScript runner inside a local image, started disposable Postgres/MySQL Docker containers, exercised semantic MCP tools, verified source unchanged before approval, applied guarded writeback, retried idempotently, proved stale-row conflict, and tore down containers/volumes/local demo files.
166
+ - `./scripts/demo-local.sh` passed earlier as the contributor path for machines that already have Node/Corepack installed.
167
+ - `corepack pnpm test:mcp-local` passed after the Docker-only host-routing change and disallowed-column tamper proof. The MCP smoke now validates Postgres billing, Postgres support, and MySQL orders across semantic tool listing/calls, tenant spoof rejection, source unchanged before approval, disallowed-column job rejection, guarded writeback, idempotent retry, stale-row conflict, and replay export.
168
+ - `corepack pnpm test` passed after adding `demo:docker`: 9 test files, 48 tests.
169
+ - `corepack pnpm test` passed after the CLI init/runner/cloud command additions: 9 test files, 42 tests.
170
+ - `corepack pnpm --filter @synapsor-runner/protocol test` passed after adding manifest checksum verification.
171
+ - `corepack pnpm test:mcp-client-configs` passed for `generic-stdio.json`, `claude-desktop.json`, `cursor.json`, and `vscode.json`: each config started stdio, returned semantic billing tools, and exposed no raw SQL/approval/commit tool.
172
+ - `corepack pnpm test` passed after adding the MCP client config verifier script: 9 test files, 47 tests.
173
+ - `corepack pnpm --filter ./apps/runner test` passed after enriching local approval display: 1 test file, 4 tests.
174
+ - `corepack pnpm test` passed after enriching local approval display: 9 test files, 47 tests.
175
+ - `corepack pnpm --filter ./apps/runner test` passed after adding local `apply --store` receipt recording and replay assertions: 1 test file, 4 tests.
176
+ - `corepack pnpm test` passed after adding local `apply --store` receipt recording: 9 test files, 47 tests.
177
+ - `corepack pnpm test:mcp-local` passed after recording apply/conflict receipts into replay for Postgres billing, Postgres support, and MySQL orders.
178
+ - `corepack pnpm demo:local` passed after receipt/replay updates: the public one-command demo ran disposable Postgres billing, Postgres support, and MySQL orders MCP scenarios, proved guarded writeback/idempotency/stale-row conflict, and tore down containers/volumes/temp demo files.
179
+ - `corepack pnpm test` passed after Docker-first demo and adapter hardening updates: 9 test files, 50 tests.
180
+ - `corepack pnpm test:mcp-local` passed after disallowed-column tamper proof across Postgres billing, Postgres support, and MySQL orders.
181
+ - `./scripts/demo-docker.sh` passed as the exact Docker-only first-run path: built the local runner image, ran the stdio MCP proof inside Docker, started disposable Postgres/MySQL fixtures, proved source unchanged before approval, guarded writeback, idempotent retry, disallowed-column rejection, stale-row conflict, and teardown. No demo containers or generated `.pnpm-store` cache remain.
182
+ - `corepack pnpm test:mcp-cloud-linked` passed after adding the hosted-compatible Cloud-linked smoke with mock Cloud API plus real guarded Postgres writeback and terminal receipt submission.
183
+ - `corepack pnpm --filter ./apps/runner test` passed after wiring `cloud connect` runner registration/heartbeat: 1 test file, 5 tests.
184
+ - `corepack pnpm --filter @synapsor-runner/control-plane-client test` passed after the same change: 1 test file, 3 tests.
185
+ - `corepack pnpm test` passed after `cloud connect` registration/heartbeat docs and tests: 9 test files, 48 tests.
186
+ - `corepack pnpm --filter @synapsor-runner/config test`, `corepack pnpm --filter @synapsor-runner/mcp-server test`, and `corepack pnpm --filter ./apps/runner test` passed after allowing the generated Cloud config registration fields (`runner_id`, `runner_version`, `project_id`, `engines`, `capabilities`) in strict config validation.
187
+ - `corepack pnpm test` passed after the same strict Cloud config fix: 9 test files, 48 tests.
package/docs/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Synapsor Runner Docs
2
+
3
+ Start with the practical paths, not the internals.
4
+
5
+ ## Try The Local Trust Loop
6
+
7
+ ```bash
8
+ ./scripts/try-synapsor.sh
9
+ ```
10
+
11
+ This runs disposable Postgres/MySQL fixtures and proves the core loop:
12
+
13
+ ```text
14
+ MCP tool call
15
+ -> trusted context
16
+ -> scoped read
17
+ -> evidence
18
+ -> proposal diff
19
+ -> approval outside MCP
20
+ -> guarded commit or stale-row conflict
21
+ -> receipt/replay
22
+ ```
23
+
24
+ Read: [First 10 Minutes](first-10-minutes.md).
25
+
26
+ ## Use Your Own Staging Postgres/MySQL
27
+
28
+ ```bash
29
+ export DATABASE_URL="<postgres-or-mysql-read-url>"
30
+ ./scripts/use-your-db.sh
31
+ ```
32
+
33
+ This inspects your schema, opens the guided setup, generates
34
+ `synapsor.runner.json`, previews the semantic MCP tools, and prints the
35
+ `mcp serve` and local UI commands.
36
+
37
+ For disposable dev RDS databases with local CA issues:
38
+
39
+ ```bash
40
+ ./scripts/use-your-db.sh --allow-insecure-ssl
41
+ ```
42
+
43
+ Use certificate verification with the database CA bundle for real staging or
44
+ production-like databases.
45
+
46
+ Read: [Connect Your Own Database](getting-started-own-database.md).
47
+
48
+ ## Important References
49
+
50
+ - [Schema Inspection](schema-inspection.md)
51
+ - [MCP Client Setup](mcp-client-setup.md)
52
+ - [Capability Config](capability-config.md)
53
+ - [Local UI](local-ui.md)
54
+ - [Writeback Executors](writeback-executors.md)
55
+ - [Security Boundary](security-boundary.md)
56
+ - [Current Scope And Limitations](limitations.md)
@@ -0,0 +1,65 @@
1
+ # Architecture
2
+
3
+ Synapsor Runner is the local commit-safety loop for database MCP. It gives developers
4
+ the smallest useful version of Synapsor's commit-safety boundary on their own
5
+ machine: semantic tools, trusted context, evidence, proposals, approval,
6
+ guarded writeback, receipts, and replay.
7
+
8
+ It is not the Synapsor C++ DBMS, not a self-hosted Synapsor Cloud, and it does
9
+ not physically branch Postgres or MySQL.
10
+
11
+ The product boundary is:
12
+
13
+ ```text
14
+ MCP connects the agent. Synapsor controls the commit.
15
+ ```
16
+
17
+ The local proof should make one thing obvious:
18
+
19
+ ```text
20
+ The agent can request a database change, but the runner commits only an
21
+ approved, scoped, conflict-checked job. If the row changed after the agent saw
22
+ it, the runner returns conflict with no write.
23
+ ```
24
+
25
+ ## Local mode
26
+
27
+ The target architecture for local mode is:
28
+
29
+ ```text
30
+ MCP client
31
+ -> local Synapsor MCP server
32
+ -> reviewed capability config
33
+ -> trusted local context provider
34
+ -> read-only Postgres/MySQL connection
35
+ -> local evidence and exact proposal diff
36
+ -> local proposal/event store
37
+ -> CLI or localhost approval
38
+ -> guarded worker with separate write credential
39
+ -> local receipt and replay
40
+ ```
41
+
42
+ Current implementation status: the guarded worker, protocol validation, Postgres/MySQL adapters, receipt table, Docker smoke fixtures, stdio MCP server, local proposal/event/evidence/query-audit store, approval CLI, writeback-job generation, replay CLI, and MCP resources are implemented in the current branch.
43
+
44
+ ## Cloud-linked mode
45
+
46
+ Synapsor Cloud owns proposal, evidence, approval, replay, and job lease state. Synapsor Runner runs in the customer environment and owns the write credential, transaction, receipt table, and result callback.
47
+
48
+ ```text
49
+ Synapsor Cloud -> approved structured job -> local runner -> Postgres/MySQL
50
+ ^ |
51
+ |---------------- result/replay callback ------------|
52
+ ```
53
+
54
+ The runner does not receive arbitrary SQL. It receives target schema/table, primary key, tenant guard, allowed columns, patch values, conflict guard, idempotency key, and lease expiry.
55
+
56
+ Current implementation status: the control-plane client supports runner registration, heartbeat, adapter tool catalog fetch, adapter tool calls, writeback claim, lease renewal through heartbeat, and result/receipt submission. The MCP runtime can operate in `mode: "cloud"` by delegating tool calls to the Cloud adapter APIs. A full Cloud E2E still requires a compatible Synapsor Cloud workspace, adapter, and scoped runner token.
57
+
58
+ ## Execution authority split
59
+
60
+ ```text
61
+ MCP tool call = request/proposal authority
62
+ Trusted runner = execution authority
63
+ ```
64
+
65
+ The model-facing path can request an inspect/proposal tool. It cannot call approval or commit tools by default. The runner only applies an already-approved, scoped, conflict-checked job.
@@ -0,0 +1,180 @@
1
+ # Local capability config
2
+
3
+ Synapsor Runner uses a strict JSON capability config for local MCP/database safety work.
4
+
5
+ YAML can be added later, but the first supported format is JSON so the runtime can validate untrusted config without adding a parser dependency.
6
+
7
+ Capabilities are not hardcoded into the runtime. The MCP server exposes only
8
+ the reviewed `capabilities` listed in `synapsor.runner.json`, or the tool
9
+ catalog returned by Synapsor Cloud in `cloud` mode. The billing examples in
10
+ this document are examples only; use your own namespace, object names, tables,
11
+ columns, patch mappings, and approval roles.
12
+
13
+ Synapsor Runner does not implement full Synapsor workflows or
14
+ `CREATE AGENT WORKFLOW` in v0.1. It models the local commit-safety loop for
15
+ reviewed read/proposal capabilities.
16
+
17
+ ## Goals
18
+
19
+ The config defines reviewed semantic capabilities. It must not define arbitrary SQL tools.
20
+
21
+ The validator rejects:
22
+
23
+ - raw SQL fields such as `sql`, `raw_sql`, `statement`, or `query_sql`;
24
+ - inline database URLs or connection strings;
25
+ - model-facing args named like `tenant_id`, `principal`, `source_id`, `allowed_columns`, `row_version`, `schema`, `table`, or `column`;
26
+ - missing primary-key target;
27
+ - missing tenant guard unless `target.single_tenant_dev` is explicitly true;
28
+ - proposal capabilities with no `allowed_columns`;
29
+ - proposal capabilities with no fixed patch mapping;
30
+ - proposal capabilities with no conflict guard unless a weak-guard exception is explicitly acknowledged;
31
+ - unknown fields when strict mode is enabled.
32
+
33
+ ## Example
34
+
35
+ ```json
36
+ {
37
+ "version": 1,
38
+ "mode": "review",
39
+ "storage": {
40
+ "sqlite_path": "./.synapsor/local.db"
41
+ },
42
+ "sources": {
43
+ "app_postgres": {
44
+ "engine": "postgres",
45
+ "read_url_env": "APP_POSTGRES_READ_URL",
46
+ "write_url_env": "APP_POSTGRES_WRITE_URL",
47
+ "statement_timeout_ms": 3000
48
+ }
49
+ },
50
+ "trusted_context": {
51
+ "provider": "environment",
52
+ "values": {
53
+ "tenant_id_env": "SYNAPSOR_TENANT_ID",
54
+ "principal_env": "SYNAPSOR_PRINCIPAL"
55
+ }
56
+ },
57
+ "contexts": {
58
+ "local_billing_operator": {
59
+ "provider": "environment",
60
+ "values": {
61
+ "tenant_id_env": "SYNAPSOR_TENANT_ID",
62
+ "principal_env": "SYNAPSOR_PRINCIPAL"
63
+ }
64
+ }
65
+ },
66
+ "executors": {
67
+ "billing_api": {
68
+ "type": "http_handler",
69
+ "url_env": "SYNAPSOR_BILLING_HANDLER_URL",
70
+ "method": "POST",
71
+ "auth": {
72
+ "type": "bearer_env",
73
+ "token_env": "SYNAPSOR_BILLING_HANDLER_TOKEN"
74
+ },
75
+ "timeout_ms": 5000
76
+ }
77
+ },
78
+ "capabilities": [
79
+ {
80
+ "name": "billing.inspect_invoice",
81
+ "kind": "read",
82
+ "source": "app_postgres",
83
+ "context": "local_billing_operator",
84
+ "target": {
85
+ "schema": "public",
86
+ "table": "invoices",
87
+ "primary_key": "id",
88
+ "tenant_key": "tenant_id"
89
+ },
90
+ "args": {
91
+ "invoice_id": {
92
+ "type": "string",
93
+ "required": true,
94
+ "max_length": 128
95
+ }
96
+ },
97
+ "lookup": {
98
+ "id_from_arg": "invoice_id"
99
+ },
100
+ "visible_columns": ["id", "late_fee_cents", "waiver_reason", "updated_at"],
101
+ "evidence": "required",
102
+ "max_rows": 1
103
+ },
104
+ {
105
+ "name": "billing.propose_late_fee_waiver",
106
+ "kind": "proposal",
107
+ "source": "app_postgres",
108
+ "context": "local_billing_operator",
109
+ "executor": "billing_api",
110
+ "target": {
111
+ "schema": "public",
112
+ "table": "invoices",
113
+ "primary_key": "id",
114
+ "tenant_key": "tenant_id"
115
+ },
116
+ "args": {
117
+ "invoice_id": {
118
+ "type": "string",
119
+ "required": true,
120
+ "max_length": 128
121
+ },
122
+ "reason": {
123
+ "type": "string",
124
+ "required": true,
125
+ "max_length": 500
126
+ }
127
+ },
128
+ "lookup": {
129
+ "id_from_arg": "invoice_id"
130
+ },
131
+ "visible_columns": ["id", "late_fee_cents", "waiver_reason", "updated_at"],
132
+ "evidence": "required",
133
+ "max_rows": 1,
134
+ "patch": {
135
+ "late_fee_cents": {
136
+ "fixed": 0
137
+ },
138
+ "waiver_reason": {
139
+ "from_arg": "reason"
140
+ }
141
+ },
142
+ "allowed_columns": ["late_fee_cents", "waiver_reason"],
143
+ "conflict_guard": {
144
+ "column": "updated_at"
145
+ },
146
+ "approval": {
147
+ "mode": "human",
148
+ "required_role": "support_lead"
149
+ }
150
+ }
151
+ ]
152
+ }
153
+ ```
154
+
155
+ ## Trusted context
156
+
157
+ Supported providers:
158
+
159
+ - `static_dev`: local/demo only; validator emits a warning.
160
+ - `environment`: reads trusted values from environment variables owned by the launching process.
161
+ - `http_claims`: reserved for authenticated HTTP deployments that verify claims before binding context.
162
+ - `cloud_session`: reserved for Cloud-linked mode with scoped runner/session context.
163
+
164
+ Model-facing tool arguments cannot override trusted context.
165
+
166
+ `contexts` is the preferred shape for larger configs. A capability with
167
+ `context: "local_billing_operator"` uses that named context. A capability
168
+ without `context` falls back to the global `trusted_context` for backward
169
+ compatibility. A missing named context fails validation.
170
+
171
+ ## Writeback executors
172
+
173
+ Proposal capabilities default to `sql_update`, which means the trusted runner
174
+ applies one guarded single-row `UPDATE` after approval. Set
175
+ `executor: "billing_api"` to route approved proposals to a configured
176
+ `http_handler` or `command_handler` instead.
177
+
178
+ Executor URLs, commands, bearer tokens, and database credentials must be
179
+ environment-variable references. They are never model-facing MCP arguments and
180
+ are redacted from CLI/UI output. See `docs/writeback-executors.md`.
@@ -0,0 +1,140 @@
1
+ # Cloud Mode
2
+
3
+ Cloud mode connects the local Synapsor Runner to Synapsor Cloud without sending database credentials to Cloud.
4
+
5
+ Command examples use the public `synapsor ...` runner CLI. From a source
6
+ checkout, use `./bin/synapsor ...` if the global binary is not linked yet. Do
7
+ not use the separate hosted Synapsor Cloud CLI for these local runner commands.
8
+
9
+ ```text
10
+ MCP client
11
+ -> local Synapsor Runner MCP server
12
+ -> Synapsor Cloud adapter/capability API
13
+ -> Cloud evidence/proposal/approval/replay
14
+ -> approved writeback job
15
+ -> local guarded runner
16
+ -> Postgres/MySQL
17
+ ```
18
+
19
+ ## What Cloud Owns
20
+
21
+ - Reviewed adapter tool catalog.
22
+ - Capability invocation envelope.
23
+ - Evidence handles.
24
+ - Proposal state.
25
+ - Approval queue.
26
+ - Writeback job leases.
27
+ - Hosted replay and activity search.
28
+ - Runner status, scopes, and receipts.
29
+
30
+ ## What Stays Local
31
+
32
+ - Postgres/MySQL read and write credentials.
33
+ - Database network access.
34
+ - Guarded writeback transaction.
35
+ - Receipt table in the target database.
36
+ - Local runner process logs and diagnostics.
37
+
38
+ ## Config Shape
39
+
40
+ Cloud mode uses the same MCP server command with a `mode: "cloud"` config:
41
+
42
+ ```json
43
+ {
44
+ "version": 1,
45
+ "mode": "cloud",
46
+ "storage": {
47
+ "sqlite_path": "./.synapsor/local.db"
48
+ },
49
+ "trusted_context": {
50
+ "provider": "cloud_session"
51
+ },
52
+ "cloud": {
53
+ "base_url_env": "SYNAPSOR_CLOUD_BASE_URL",
54
+ "runner_token_env": "SYNAPSOR_RUNNER_TOKEN",
55
+ "runner_id": "synapsor_runner_local",
56
+ "runner_version": "0.1.0-alpha.2",
57
+ "project_id": "token_scope",
58
+ "adapter_id": "mcp.your_adapter",
59
+ "source_id": "src_replace_me",
60
+ "engines": ["postgres"],
61
+ "capabilities": ["adapter:read", "adapter:invoke", "writeback:claim", "writeback:complete"],
62
+ "session": {
63
+ "tenant_id": "acme"
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Run:
70
+
71
+ ```bash
72
+ SYNAPSOR_CLOUD_BASE_URL="https://api.synapsor.ai" \
73
+ SYNAPSOR_RUNNER_TOKEN="syn_wbr_..." \
74
+ npx -y -p @synapsor/runner@alpha synapsor-runner mcp serve --config ./synapsor.cloud.json
75
+ ```
76
+
77
+ Validate the Cloud runner token and source scope before serving tools:
78
+
79
+ ```bash
80
+ SYNAPSOR_CLOUD_BASE_URL="https://api.synapsor.ai" \
81
+ SYNAPSOR_RUNNER_TOKEN="syn_wbr_..." \
82
+ npx -y -p @synapsor/runner@alpha synapsor-runner cloud connect --config ./synapsor.cloud.json
83
+ ```
84
+
85
+ `cloud connect` verifies the runner token, registers the runner id/version, sends engine/capability/source metadata, and posts an initial heartbeat. It does not send Postgres/MySQL URLs, passwords, write credentials, prompts, or table data. The `project_id` field may be the literal `token_scope` because Synapsor Cloud validates the real project/source from the scoped runner token.
86
+
87
+ The runner token should be scoped to adapter read/invoke and writeback claim/result reporting for the intended source. It should not grant proposal approval permission.
88
+
89
+ ## Tool Calls
90
+
91
+ In Cloud mode, the local MCP server fetches the adapter tool catalog from Synapsor Cloud and delegates tool calls to Cloud adapter APIs. The returned result remains structured and must not expose raw SQL or database credentials.
92
+
93
+ ## Hosted Compatibility Check
94
+
95
+ After you have a compatible Cloud workspace, external source, MCP adapter, and
96
+ scoped runner token, verify the hosted adapter/tool path:
97
+
98
+ ```bash
99
+ SYNAPSOR_CLOUD_BASE_URL="https://synapsor.ai" \
100
+ SYNAPSOR_RUNNER_TOKEN="syn_wbr_..." \
101
+ SYNAPSOR_SOURCE_ID="src_..." \
102
+ SYNAPSOR_ADAPTER_ID="mcp.your_adapter" \
103
+ SYNAPSOR_MCP_TOOL_NAME="your_namespace.propose_your_object_update" \
104
+ SYNAPSOR_MCP_TOOL_INPUT_JSON='{"object_id":"replace-me","reason":"reviewed change"}' \
105
+ corepack pnpm verify:hosted-cloud-linked
106
+ ```
107
+
108
+ That command checks runner-token auth, runner registration, heartbeat, adapter
109
+ `tools/list`, semantic tool invocation, proposal/evidence/replay linkage, and
110
+ that the tool response does not report source mutation before trusted
111
+ writeback. It never creates runner tokens and never prints token values.
112
+
113
+ To claim and apply one already approved writeback job through the guarded local
114
+ adapter, add:
115
+
116
+ ```bash
117
+ SYNAPSOR_HOSTED_E2E_APPLY_JOB=1
118
+ SYNAPSOR_ENGINE="postgres|mysql"
119
+ SYNAPSOR_DATABASE_URL="postgresql://..."
120
+ ```
121
+
122
+ Use the trusted worker credential in `SYNAPSOR_DATABASE_URL`. Do not put that
123
+ credential in an MCP client config or model-facing tool definition.
124
+
125
+ ## Writeback
126
+
127
+ The model-facing tool call creates or returns Cloud-managed proposal state. The external database is unchanged until:
128
+
129
+ 1. a human or deterministic Cloud policy approves the exact proposal version/hash;
130
+ 2. Cloud creates an approved writeback job;
131
+ 3. the scoped runner claims the job;
132
+ 4. the local worker applies a guarded single-row update;
133
+ 5. the runner returns an applied/conflict/failed receipt.
134
+
135
+ ## Current Limits
136
+
137
+ - Cloud mode requires a compatible Synapsor Cloud deployment and runner token.
138
+ - Local and Cloud histories are separate unless an explicit import feature is added later.
139
+ - Streamable HTTP transport is not enabled by default; stdio is the primary local MCP transport.
140
+ - Approval remains outside model-callable MCP tools.