proteum 2.3.0 → 2.4.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 (56) hide show
  1. package/AGENTS.md +8 -3
  2. package/README.md +20 -15
  3. package/agents/project/AGENTS.md +16 -10
  4. package/agents/project/DOCUMENTATION.md +1326 -0
  5. package/agents/project/app-root/AGENTS.md +2 -2
  6. package/agents/project/diagnostics.md +10 -9
  7. package/agents/project/optimizations.md +1 -1
  8. package/agents/project/root/AGENTS.md +15 -8
  9. package/agents/project/server/services/AGENTS.md +1 -0
  10. package/agents/project/tests/AGENTS.md +1 -0
  11. package/cli/commands/db.ts +160 -0
  12. package/cli/commands/dev.ts +148 -25
  13. package/cli/commands/diagnose.ts +2 -0
  14. package/cli/commands/explain.ts +38 -9
  15. package/cli/commands/mcp.ts +126 -9
  16. package/cli/commands/orient.ts +44 -17
  17. package/cli/commands/runtime.ts +100 -17
  18. package/cli/mcp/router.ts +1028 -0
  19. package/cli/presentation/commands.ts +56 -25
  20. package/cli/presentation/help.ts +1 -1
  21. package/cli/runtime/commands.ts +163 -21
  22. package/cli/runtime/devSessions.ts +328 -2
  23. package/cli/runtime/mcpDaemon.ts +288 -0
  24. package/cli/runtime/ports.ts +151 -0
  25. package/cli/utils/agents.ts +94 -17
  26. package/cli/utils/appRoots.ts +232 -0
  27. package/common/dev/database.ts +226 -0
  28. package/common/dev/diagnostics.ts +1 -1
  29. package/common/dev/inspection.ts +8 -1
  30. package/common/dev/mcpPayloads.ts +456 -17
  31. package/common/dev/mcpServer.ts +51 -0
  32. package/docs/agent-routing.md +32 -21
  33. package/docs/dev-commands.md +1 -1
  34. package/docs/dev-sessions.md +3 -1
  35. package/docs/diagnostics.md +21 -20
  36. package/docs/mcp.md +114 -50
  37. package/docs/migrate-from-2.1.3.md +3 -5
  38. package/docs/request-tracing.md +3 -3
  39. package/package.json +10 -3
  40. package/server/app/devDiagnostics.ts +92 -0
  41. package/server/app/devMcp.ts +55 -0
  42. package/server/services/prisma/mariadb.ts +7 -3
  43. package/server/services/router/http/index.ts +25 -0
  44. package/server/services/router/request/ip.test.cjs +0 -1
  45. package/tests/agents-utils.test.cjs +58 -3
  46. package/tests/cli-mcp-command.test.cjs +327 -0
  47. package/tests/codex-mcp-usage.test.cjs +307 -0
  48. package/tests/dev-sessions.test.cjs +113 -0
  49. package/tests/dev-transpile-watch.test.cjs +0 -1
  50. package/tests/eslint-rules.test.cjs +0 -1
  51. package/tests/inspection.test.cjs +0 -1
  52. package/tests/mcp.test.cjs +769 -2
  53. package/tests/router-cache-config.test.cjs +0 -1
  54. package/vitest.config.mjs +9 -0
  55. package/cli/mcp/provider.ts +0 -365
  56. package/cli/mcp/stdio.ts +0 -16
@@ -7,6 +7,7 @@ import { stringifyMcpPayload, type TProteumMcpPayload } from './mcpPayloads';
7
7
  export type TProteumMcpDetail = 'compact' | 'full';
8
8
 
9
9
  export type TProteumMcpProvider = {
10
+ dbQuery: (input: { limit?: number; sql: string; timeoutMs?: number }) => Promise<TProteumMcpPayload>;
10
11
  diagnose: (input: {
11
12
  logsLevel?: 'silly' | 'log' | 'info' | 'warn' | 'error';
12
13
  logsLimit?: number;
@@ -22,9 +23,11 @@ export type TProteumMcpProvider = {
22
23
  perfRequest: (input: { query: string }) => Promise<TProteumMcpPayload>;
23
24
  perfTop: (input: { groupBy?: 'path' | 'route' | 'controller'; limit?: number; since?: string }) => Promise<TProteumMcpPayload>;
24
25
  readResource: (uri: string) => Promise<TProteumMcpPayload>;
26
+ routeCandidates: (input: { limit?: number; query: string }) => Promise<TProteumMcpPayload>;
25
27
  runtimeStatus: (input: Record<string, never>) => Promise<TProteumMcpPayload>;
26
28
  traceLatest: (input: { detail?: TProteumMcpDetail; limit?: number; offset?: number }) => Promise<TProteumMcpPayload>;
27
29
  traceShow: (input: { detail?: TProteumMcpDetail; limit?: number; offset?: number; requestId: string }) => Promise<TProteumMcpPayload>;
30
+ workflowStart: (input: { file?: string; query?: string; route?: string; task?: string }) => Promise<TProteumMcpPayload>;
28
31
  };
29
32
 
30
33
  type TCreateProteumMcpServerArgs = {
@@ -62,6 +65,8 @@ const detailSchema = z.enum(['compact', 'full']).optional();
62
65
  const logsLevelSchema = z.enum(['silly', 'log', 'info', 'warn', 'error']).optional();
63
66
  const positiveLimitSchema = z.number().int().min(1).max(100).optional();
64
67
  const offsetSchema = z.number().int().min(0).max(10_000).optional();
68
+ const databaseLimitSchema = z.number().int().min(1).max(500).optional();
69
+ const databaseTimeoutSchema = z.number().int().min(100).max(30_000).optional();
65
70
 
66
71
  export const createProteumMcpServer = ({ provider, version }: TCreateProteumMcpServerArgs) => {
67
72
  const server = new McpServer(
@@ -76,6 +81,23 @@ export const createProteumMcpServer = ({ provider, version }: TCreateProteumMcpS
76
81
  },
77
82
  );
78
83
 
84
+ server.registerTool(
85
+ 'workflow_start',
86
+ {
87
+ annotations: readOnlyAnnotations,
88
+ description:
89
+ 'Bootstrap an agent workflow with compact runtime, instruction, owner, doctor, and next-action data in one read.',
90
+ inputSchema: {
91
+ file: z.string().optional().describe('Optional source file or generated artifact path in scope.'),
92
+ query: z.string().optional().describe('Optional task, route, controller, file, or owner query.'),
93
+ route: z.string().optional().describe('Optional route path in scope.'),
94
+ task: z.string().optional().describe('Optional short natural-language task description.'),
95
+ },
96
+ title: 'Proteum Workflow Start',
97
+ },
98
+ async ({ file, query, route, task }) => jsonToolResult(await provider.workflowStart({ file, query, route, task })),
99
+ );
100
+
79
101
  server.registerTool(
80
102
  'runtime_status',
81
103
  {
@@ -126,6 +148,20 @@ export const createProteumMcpServer = ({ provider, version }: TCreateProteumMcpS
126
148
  async ({ query }) => jsonToolResult(await provider.explainSummary({ query })),
127
149
  );
128
150
 
151
+ server.registerTool(
152
+ 'route_candidates',
153
+ {
154
+ annotations: readOnlyAnnotations,
155
+ description: 'Return compact route candidates for a query without dumping raw route arrays.',
156
+ inputSchema: {
157
+ limit: z.number().int().min(1).max(50).optional(),
158
+ query: z.string().min(1).describe('Route path or route-like search query.'),
159
+ },
160
+ title: 'Proteum Route Candidates',
161
+ },
162
+ async ({ limit, query }) => jsonToolResult(await provider.routeCandidates({ limit, query })),
163
+ );
164
+
129
165
  server.registerTool(
130
166
  'doctor',
131
167
  {
@@ -231,6 +267,21 @@ export const createProteumMcpServer = ({ provider, version }: TCreateProteumMcpS
231
267
  async ({ level, limit }) => jsonToolResult(await provider.logsTail({ level, limit })),
232
268
  );
233
269
 
270
+ server.registerTool(
271
+ 'db_query',
272
+ {
273
+ annotations: readOnlyAnnotations,
274
+ description: 'Run one capped read-only database diagnostic query. Only SELECT, SHOW, and EXPLAIN are allowed.',
275
+ inputSchema: {
276
+ limit: databaseLimitSchema,
277
+ sql: z.string().min(1).describe('One SELECT, SHOW, or EXPLAIN SQL statement.'),
278
+ timeoutMs: databaseTimeoutSchema,
279
+ },
280
+ title: 'Proteum Database Query',
281
+ },
282
+ async ({ limit, sql, timeoutMs }) => jsonToolResult(await provider.dbQuery({ limit, sql, timeoutMs })),
283
+ );
284
+
234
285
  for (const [name, uri, description] of [
235
286
  ['runtime-status', 'proteum://runtime/status', 'Current compact runtime status.'],
236
287
  ['instructions-router', 'proteum://instructions/router', 'Current instruction routing contract.'],
@@ -6,15 +6,17 @@ The optimized stack is:
6
6
 
7
7
  - routed agent instructions for stable policy
8
8
  - compact CLI for reproducible command-line checks
9
- - MCP for repeated reads of the same project/runtime state
9
+ - MCP for repeated reads of the same project/runtime state, routed by `projectId`
10
10
 
11
11
  The routing strategy is:
12
12
 
13
13
  1. Use instructions for hard safety rules and routing only.
14
- 2. Use MCP when available for repeated reads, runtime status, instruction routing, traces, perf, and logs.
15
- 3. Use `proteum orient <query>` or the MCP `orient` tool to resolve the task-specific owner, `mustRead` instruction files, and next command.
16
- 4. Use compact CLI output for reproducible terminal validation and CI-like checks.
17
- 5. Use `--full`, `--manifest`, `--events`, or MCP paginated `detail: "full"` only after compact output identifies the missing detail.
14
+ 2. Use MCP first when available for read-only runtime status, instruction routing, owner lookup, diagnosis, traces, perf, and logs.
15
+ 3. Start machine MCP sessions with `workflow_start { cwd, task, route?, file? }` when possible; use `project_resolve { cwd }` when the bootstrap is ambiguous, no `projectId` is known, or the app is offline.
16
+ 4. Pass the returned live stable `projectId` to every follow-up app-bound MCP call.
17
+ 5. Use MCP `orient { projectId, query }`, `instructions_resolve { projectId, query }`, `route_candidates { projectId, query }`, and `explain_summary { projectId, query }` only when `workflow_start` did not return enough owner or instruction detail.
18
+ 6. Use compact CLI output for reproducible terminal validation, CI-like checks, fallback repair, and final evidence.
19
+ 7. Use `--full`, `--manifest`, `--events`, or MCP paginated `detail: "full"` only after compact output identifies the missing detail.
18
20
 
19
21
  ## Problem Resolved
20
22
 
@@ -28,7 +30,7 @@ The measured Product diagnostic loop produced roughly tens of thousands of outpu
28
30
  - raw `trace latest`
29
31
  - `perf request`
30
32
  - `verify request`
31
- - sometimes full `explain --json`
33
+ - sometimes full manifest or explain section output
32
34
 
33
35
  Managed project instructions also embedded the same Proteum corpus into multiple generated files, so reading a handful of local docs could repeat the same contract many times.
34
36
 
@@ -48,7 +50,7 @@ Default CLI output for agent commands is compact `proteum-agent-v1` JSON:
48
50
  }
49
51
  ```
50
52
 
51
- Use the compact commands first:
53
+ Use compact CLI commands when MCP is unavailable, when a command must be reproducible in a shell, or when final terminal evidence is required:
52
54
 
53
55
  ```bash
54
56
  proteum orient <route|file|controller|error>
@@ -60,19 +62,15 @@ proteum trace latest
60
62
 
61
63
  Use MCP for repeated reads when a client is available:
62
64
 
63
- ```bash
65
+ ```text
64
66
  proteum mcp
65
- proteum mcp --url http://localhost:3101
66
- proteum mcp --session-file var/run/proteum/dev/agents/task.json
67
67
  ```
68
68
 
69
- During `proteum dev`, the same read-only tool contract is available at:
69
+ The machine router discovers live `proteum dev` sessions and offline Proteum app roots under a cwd. `proteum dev` ensures one managed machine MCP daemon is running; terminal `proteum mcp` starts or reuses that daemon, while MCP clients can use stdio. Agents should call MCP `workflow_start` with `cwd` or a known `projectId`, use `project_resolve { cwd }` when routing is ambiguous or offline, and pass the returned live `projectId` to every follow-up app-bound MCP tool. Offline candidates include port-inspected next actions, so agents should follow those instead of guessing the manifest default port. The router forwards to the selected dev-hosted `/__proteum/mcp` endpoint and strips routing fields before the app sees the call.
70
70
 
71
- ```text
72
- http://localhost:<port>/__proteum/mcp
73
- ```
71
+ If machine MCP routing returns offline candidates, choose the intended app root and follow that candidate's next action from the app root, not from the monorepo wrapper. If machine MCP routing fails, run `proteum mcp status` and `proteum runtime status` from the intended app root; if no live session exists, use the exact Start Dev next action from runtime status so occupied router/HMR ports are avoided. If the same app already responds on the configured port without live tracking, use or repair that runtime instead of starting another server. Do not `curl` normal page routes to identify which app owns a port; use runtime status or Proteum dev-only endpoints. If a live session exists but runtime/MCP is unreachable, stop the listed session file first, then start dev again. Do not run diagnose, trace, or perf reads while runtime health is unreachable. Do not start a second dev server in the same worktree, and do not start a second managed MCP daemon. Then retry MCP `workflow_start`.
74
72
 
75
- Prefer the dev-hosted MCP endpoint when the app is already running; prefer stdio `proteum mcp` when the agent environment launches MCP servers itself. Prefer CLI over MCP when the result must be reproducible as a shell command, part of verification, or copied into CI/debug instructions.
73
+ Prefer CLI over MCP when the result must be reproducible as a shell command, part of verification, or copied into CI/debug instructions.
76
74
 
77
75
  MCP output is compact `proteum-mcp-v1` JSON. It is intentionally single-line JSON, capped, and paginated for full trace detail. Do not expand MCP output just to make it look nicer for humans.
78
76
 
@@ -80,6 +78,7 @@ Use full-detail escape hatches only when needed:
80
78
 
81
79
  ```bash
82
80
  proteum explain --manifest
81
+ proteum explain --routes --controllers --full
83
82
  proteum orient <query> --full
84
83
  proteum diagnose <target> --full
85
84
  proteum trace show <requestId> --events
@@ -90,8 +89,21 @@ proteum perf request <requestId> --full
90
89
 
91
90
  Managed `AGENTS.md` files now carry a compact router instead of the full instruction corpus.
92
91
 
92
+ The router standard is trigger -> canonical instruction file, not trigger -> copied summary. Keep the compact root focused on hard safety rules, routing triggers, and source-map references. When a trigger needs a lifecycle or area contract, route agents to the full file that owns the rule.
93
+
94
+ Standard triggered reads:
95
+
96
+ - Git lifecycle (`commit`, `and commit`, `stage`, `push`, `PR`, pull request): root contract fallback.
97
+ - Before finishing production code changes: root contract fallback, `CODING_STYLE.md`, and touched area `AGENTS.md`.
98
+ - Runtime-visible, request-time, router, SSR, browser, or controller behavior: root contract fallback plus `diagnostics.md`.
99
+ - Non-trivial feature, product, business-rule, UX, copy, or docs changes: `DOCUMENTATION.md`.
100
+ - Implementation edits: `CODING_STYLE.md` plus the matching area file from the routing table.
101
+
102
+ `workflow_start`, `orient`, `route_candidates`, and MCP `instructions_resolve` should promote obvious triggered files into selected instruction previews; ambiguous conditional reads can remain in `readWhen`.
103
+
93
104
  Area files carry only their own source content:
94
105
 
106
+ - `DOCUMENTATION.md`: documentation-driven coding, `/docs` source-of-truth routing, and docs update expectations
95
107
  - `diagnostics.md`: raw errors, failing routes, traces, perf, reproduction
96
108
  - `optimizations.md`: package, runtime, build, and optimization decisions
97
109
  - `CODING_STYLE.md`: implementation style before editing
@@ -102,9 +114,9 @@ Area files carry only their own source content:
102
114
  - `tests/e2e/AGENTS.md`: E2E workflow
103
115
  - `tests/e2e/REAL_WORLD_JOURNEY_TESTS.md`: journey-test design
104
116
 
105
- Agents should not read broad folders or every managed instruction file. They should read only `mustRead` from `orient`, plus conditional docs that match the current task.
117
+ Agents should not read broad folders or every managed instruction file. They should use selected MCP previews for read-only discovery and diagnostics, then read full files only before edits or git writes, when returned `fullRead`/`fullReadPolicy` requires it, or when the preview is insufficient.
106
118
 
107
- The MCP `instructions_resolve` resource/tool exposes the same routing decision in compact JSON and is the lowest-token way to refresh instruction selection without rereading full docs.
119
+ MCP `workflow_start` exposes the first routing decision in compact JSON. MCP `instructions_resolve { projectId, query }` is the lowest-token way to refresh instruction selection without rereading full docs.
108
120
 
109
121
  ## Benchmark Result
110
122
 
@@ -114,13 +126,12 @@ The latest Product `/domains` benchmark used routed instructions plus the compac
114
126
  | --- | ---: | ---: |
115
127
  | Compact CLI single loop | 6,286 | 4,809 ms |
116
128
  | Dev-hosted HTTP MCP single loop | 5,211 | 232 ms |
117
- | Stdio MCP single loop | 5,526 | 900 ms |
118
129
  | Compact CLI repeated reads x3 | 11,660 | 9,572 ms |
119
130
  | Dev-hosted HTTP MCP repeated reads x3 | 10,537 | 214 ms |
120
131
 
121
132
  The result confirms the intended routing:
122
133
 
123
134
  - use CLI for reproducible verification and final command evidence
124
- - use dev-hosted MCP for repeated runtime reads against an already running app
125
- - use stdio MCP when the agent needs a launchable MCP server from an app/worktree
126
- - use `instructions_resolve` to refresh routing instead of rereading instruction files
135
+ - use `workflow_start` to collapse project resolution, runtime status, instruction previews, owner summary, and first next actions into one read
136
+ - use machine MCP with `projectId` for repeated runtime reads against an already running app
137
+ - use `instructions_resolve` to refresh routing instead of rereading full instruction files
@@ -79,7 +79,7 @@ The profiler also exposes the shared diagnostics surfaces for humans:
79
79
 
80
80
  For the shared diagnostics contract, trace-derived perf contract, and the corresponding dev HTTP endpoints, see [diagnostics.md](diagnostics.md) and [request-tracing.md](request-tracing.md).
81
81
 
82
- Command execution stays in the CLI, profiler, and dev command HTTP endpoints. The Proteum MCP surfaces are read-only; use MCP for repeated diagnostics, trace, perf, status, and log reads, not for running commands.
82
+ Command execution stays in the CLI, profiler, and dev command HTTP endpoints. The Proteum MCP surfaces are read-only; use MCP with the selected `projectId` for repeated diagnostics, trace, perf, status, and log reads, not for running commands.
83
83
 
84
84
  ### HTTP Endpoints
85
85
 
@@ -78,7 +78,7 @@ curl -H "$(jq -r '.curlCookieHeader' session.json)" http://localhost:3101/api/Au
78
78
  - Prefer `proteum session` over UI login automation when the goal is to test or debug protected application behavior.
79
79
  - Prefer `proteum verify browser` for focused browser-visible verification, and `proteum e2e --port <port>` for targeted or full Playwright suites. When lower-level control is required, use direct Playwright with a disposable profile.
80
80
  - Use UI login automation only when the auth UX itself is the feature under test.
81
- - Pair it with `proteum diagnose` for a fast protected-route summary, `proteum perf request` for a one-request timing breakdown, or MCP `diagnose`/`perf_request` for repeated reads against the same running app. Use `proteum trace show <requestId> --events` only when you need lower-level request events.
81
+ - Pair it with `proteum diagnose` for a fast protected-route summary, `proteum perf request` for a one-request timing breakdown, or MCP `diagnose`/`perf_request` with the selected `projectId` for repeated reads against the same running app. Use `proteum trace show <requestId> --events` only when you need lower-level request events.
82
82
  - Only the final verifier agent should usually run browser flows. Earlier agents should stay on `orient`, `verify owner`, `verify request`, and request-level diagnostics unless browser execution is required.
83
83
 
84
84
  Typical flow:
@@ -93,6 +93,8 @@ proteum perf request /dashboard --port 3101
93
93
  proteum trace latest --port 3101
94
94
  ```
95
95
 
96
+ Use the exact next action from `proteum runtime status` before starting a long-lived dev server. It inspects configured router/HMR ports without fetching normal page bodies, and it tells agents to use or repair an untracked same-app runtime instead of starting a second server.
97
+
96
98
  When `proteum verify browser <path>` is available in the target app, it uses the same fresh per-run browser workspace model under `var/proteum/browser/<run-id>` and should be preferred over ad hoc shared Playwright profile reuse.
97
99
 
98
100
  ## Dev HTTP Endpoint
@@ -13,7 +13,7 @@ Performance inspection is a sibling surface, not a separate instrumentation stac
13
13
 
14
14
  The diagnostics and routing CLI surfaces are optimized for agents by default. They return compact decision-ready output first and expose large raw detail only through explicit flags such as `--full`, `--manifest`, or `--events`.
15
15
 
16
- For repeated agent reads, Proteum also exposes the same compact diagnostic contract through MCP. Use `proteum mcp` for stdio clients and `/__proteum/mcp` from a running `proteum dev` server for runtime-adjacent data. See [mcp.md](mcp.md).
16
+ For repeated agent reads, Proteum also exposes the same compact diagnostic contract through `proteum mcp`, a machine-scope router that forwards `projectId`-scoped calls to the matching dev-hosted `/__proteum/mcp` endpoint. See [mcp.md](mcp.md).
17
17
 
18
18
  ## Shared Contract
19
19
 
@@ -22,12 +22,12 @@ The canonical snapshot lives in `./.proteum/manifest.json`.
22
22
  Proteum uses that same manifest in these places:
23
23
 
24
24
  - `proteum orient` for owner lookup, guidance resolution, connected-boundary summary, and next-step suggestions
25
- - `proteum explain` for human-readable and `--json` output
25
+ - `proteum explain` for compact manifest summaries and selected-section counts
26
26
  - `proteum doctor` for human-readable and `--json` output
27
27
  - `proteum explain owner <query>` for ownership lookup over the manifest index
28
28
  - `proteum doctor --contracts` for generated-artifact and manifest-owned source validation on disk
29
29
  - the dev-only `__proteum/explain*` and `__proteum/doctor*` HTTP endpoints
30
- - the dev-only `/__proteum/mcp` endpoint and `proteum mcp` stdio server
30
+ - the dev-only `/__proteum/mcp` endpoint
31
31
  - the `Explain`, `Doctor`, and `Diagnose` tabs in the bottom profiler during `proteum dev`
32
32
 
33
33
  This means the CLI, MCP, the dev HTTP endpoints, and the profiler all describe the same framework-owned snapshot before any live trace or log overlays are added.
@@ -44,6 +44,7 @@ proteum orient /api/Auth/CurrentUser
44
44
  proteum explain
45
45
  proteum explain owner /api/Auth/CurrentUser
46
46
  proteum explain --routes --controllers --commands
47
+ proteum explain --routes --controllers --commands --full
47
48
  proteum explain --manifest
48
49
 
49
50
  proteum doctor
@@ -66,9 +67,6 @@ proteum perf compare --baseline yesterday --target today --group-by route
66
67
  proteum perf memory --since 1h --group-by controller
67
68
 
68
69
  proteum runtime status
69
- proteum mcp
70
- proteum mcp --url http://localhost:3101
71
- proteum mcp --session-file var/run/proteum/dev/agents/task.json
72
70
  ```
73
71
 
74
72
  Default compact command output follows this shape:
@@ -98,7 +96,7 @@ Default compact command output follows this shape:
98
96
 
99
97
  `proteum orient --full` emits the full orientation payload.
100
98
 
101
- `proteum explain` emits a compact manifest summary. `proteum explain --manifest` emits the full generated manifest, and explicit section flags such as `--routes --controllers` emit those sections.
99
+ `proteum explain` emits a compact manifest summary. Explicit section flags such as `--routes --controllers` now summarize those sections by default to avoid route/controller dumps in agent context. Add `--full` to emit selected raw section arrays, or use `proteum explain --manifest` for the full generated manifest.
102
100
 
103
101
  `proteum explain owner <query>` emits compact owner ranking. `proteum explain owner <query> --full` keeps the existing full owner ranking shape and adds:
104
102
 
@@ -112,9 +110,9 @@ Default compact command output follows this shape:
112
110
  - `summary.strictFailed`
113
111
  - `diagnostics`
114
112
 
115
- `proteum runtime status` emits the current app manifest summary, tracked dev sessions, selected live session, health status, and a suggested next command. Use it before starting another dev server.
113
+ `proteum runtime status` emits the current app manifest summary, tracked dev sessions, selected live session, MCP URL, health status, configured router/HMR port inspection, and a suggested next command. Use it before starting another dev server, and use its Start Dev command instead of probing page bodies when the default port is occupied. If it reports that the same app already responds on the configured port without a live tracked session, use or repair that runtime instead of starting a second server.
116
114
 
117
- `proteum mcp` starts the read-only stdio MCP server. It exposes compact `runtime_status`, `orient`, `instructions_resolve`, `explain_summary`, `doctor`, `diagnose`, `trace_*`, `perf_*`, and `logs_tail` tools without spawning CLI commands for each read.
115
+ During `proteum dev`, `/__proteum/mcp` exposes compact `workflow_start`, `runtime_status`, `orient`, `instructions_resolve`, `route_candidates`, `explain_summary`, `doctor`, `diagnose`, `trace_*`, `perf_*`, and `logs_tail` tools without spawning CLI commands for each repeated read. `proteum dev` also ensures one managed machine `proteum mcp` daemon is running. Through the machine router, call `workflow_start` with `cwd` or a known `projectId`; if routing is ambiguous or returns offline app candidates, use `project_resolve { cwd }`, follow the selected app root's port-inspected next action when needed, then pass the selected live `projectId` to follow-up app-bound tools.
118
116
 
119
117
  MCP tool/resource output follows compact single-line `proteum-mcp-v1` JSON:
120
118
 
@@ -211,7 +209,7 @@ GET /__proteum/diagnose?query=/api/Auth/CurrentUser&logsLevel=warn&logsLimit=40
211
209
 
212
210
  These endpoints are intended for local tooling and are not available in production.
213
211
 
214
- `/__proteum/mcp` is the dev-hosted MCP transport. It exposes the same read-only tool/resource contract as `proteum mcp`, backed directly by the running app's diagnostics, trace, perf, and log stores. The `proteum dev` session UI and ready banner print this URL when the server is ready.
212
+ `/__proteum/mcp` is the dev-hosted MCP transport. It exposes the read-only tool/resource contract backed directly by the running app's diagnostics, trace, perf, and log stores. The `proteum dev` session UI and ready banner print this URL when the server is ready. The machine `proteum mcp` router discovers these live endpoints and routes app-bound calls by `projectId`.
215
213
 
216
214
  ## Profiler
217
215
 
@@ -251,13 +249,16 @@ Treat these as framework contract failures first. The fix usually belongs at the
251
249
 
252
250
  For AI coding agents or automation:
253
251
 
254
- 1. Start with `proteum orient <query>` or MCP `orient` when the target might be generated, connected, framework-owned, multi-repo, or instruction-ambiguous.
255
- 2. Read only `instructions.mustRead` from compact orientation output, or use MCP `instructions_resolve` to refresh the routed instruction set without rereading docs.
256
- 3. Run `proteum runtime status` before starting another dev server; use MCP `runtime_status` for repeated status reads.
257
- 4. Use `proteum diagnose <path> --port <port>` or MCP `diagnose` for the smallest trustworthy runtime surface before broad checks.
258
- 5. Use `proteum perf request <requestId|path>` or MCP `perf_request` for performance, CPU, SQL, render, cache, or connected-boundary questions.
259
- 6. Use `proteum trace show <requestId> --events` only when compact diagnose, perf, trace, or MCP output says lower-level event detail is needed.
260
- 7. Use `proteum explain --manifest` or read `./.proteum/manifest.json` only when compact `orient`/`explain`/MCP summary cannot answer the specific manifest question.
261
- 8. Use `proteum verify browser` for browser-visible verification, or `proteum e2e --port <port>` for targeted/full Playwright suites. Keep auth sourced from Proteum session helpers.
262
- 9. Run global checks second, not first. Unrelated diagnostics should remain visible but non-blocking during focused verification unless strict global mode is required.
263
- 10. Open the profiler only when a human-readable view helps; it should agree with the CLI and MCP after refresh.
252
+ 1. When MCP is available, call `workflow_start` with `cwd` or a known `projectId`; if routing is ambiguous or returns offline app candidates, call `project_resolve { cwd }`, select the intended app root, start dev from that app root when needed, then retry with the selected stable live `projectId`.
253
+ 2. Use the returned `projectId` for MCP `runtime_status`, `orient`, `instructions_resolve`, `route_candidates`, `explain_summary`, `doctor`, `diagnose`, `trace_show`, `perf_request`, and `logs_tail` read-only runtime, owner, route, instruction, trace, perf, and log reads.
254
+ 3. Do not run CLI equivalents after a successful MCP result for the same read, and do not run broad source searches for ownership MCP already returned. Use CLI for fallback, `dev`, `build`, `check`, `verify`, migrations, E2E, and final terminal evidence.
255
+ 4. Use selected instruction previews for read-only discovery and diagnostics; read full files only before edits or git writes, when returned `fullRead`/`fullReadPolicy` requires it, or when the preview is insufficient.
256
+ 5. Use `proteum orient <query>` only when MCP is unavailable or terminal evidence is required.
257
+ 6. If machine MCP routing fails, run `proteum mcp status` and `proteum runtime status` from the intended app root. If you are in a monorepo wrapper, use the returned app candidates and exact next action. If no live session exists, use the exact Start Dev next action returned by runtime status so occupied router/HMR ports are avoided. Do not `curl` normal page routes to identify a port owner. If a live session exists but runtime/MCP is unreachable, stop the listed session file first, then start dev again.
258
+ 7. Use MCP `diagnose { projectId, path }` for the smallest trustworthy runtime surface before broad checks only after runtime health is reachable; use `proteum diagnose <path> --port <port>` as fallback or terminal evidence.
259
+ 8. Use MCP `perf_request { projectId, query }` for performance, CPU, SQL, render, cache, or connected-boundary questions; use `proteum perf request <requestId|path>` as fallback or terminal evidence.
260
+ 9. Use `proteum trace show <requestId> --events` only when compact diagnose, perf, trace, or MCP output says lower-level event detail is needed.
261
+ 10. Use `proteum explain --manifest` or read `./.proteum/manifest.json` only when compact `workflow_start`/`orient`/`explain`/MCP summary cannot answer the specific manifest question.
262
+ 11. Use `proteum verify browser` for browser-visible verification, or `proteum e2e --port <port>` for targeted/full Playwright suites. Keep auth sourced from Proteum session helpers.
263
+ 12. Run global checks second, not first. Unrelated diagnostics should remain visible but non-blocking during focused verification unless strict global mode is required.
264
+ 13. Open the profiler only when a human-readable view helps; it should agree with the CLI and MCP after refresh.
package/docs/mcp.md CHANGED
@@ -1,37 +1,57 @@
1
1
  # Proteum MCP
2
2
 
3
- Proteum exposes read-only MCP surfaces for agents that need repeated, compact access to project and runtime state.
3
+ Proteum exposes MCP through two coordinated surfaces:
4
4
 
5
- There are two entrypoints:
5
+ - `proteum mcp`: one machine-scope router for live Proteum dev projects.
6
+ - `proteum dev`: one app-root runtime endpoint at `http://localhost:<port>/__proteum/mcp`.
6
7
 
7
- - `proteum mcp`: a stdio MCP server launched from an app or worktree.
8
- - `proteum dev`: a dev-hosted MCP endpoint at `/__proteum/mcp`.
8
+ Agents should normally connect to `proteum mcp`. The router discovers live `proteum dev` sessions from the machine registry, can resolve offline Proteum app roots from a supplied `cwd`, returns stable `projectId` values for live projects, and forwards app-bound reads to the selected dev-hosted endpoint.
9
9
 
10
- Both entrypoints expose the same tool/resource contract. The CLI remains the source of truth for `dev`, `build`, `check`, `refresh`, migrations, and reproducible terminal validation. MCP is for low-token reads, runtime snapshots, trace/perf/log summaries, and progressive detail loading.
10
+ ## Machine Router
11
11
 
12
- ## Stdio Server
13
-
14
- Configure an MCP client to launch the server from the app root:
12
+ Start the router from any directory:
15
13
 
16
14
  ```bash
17
15
  proteum mcp
18
16
  ```
19
17
 
20
- Useful options:
18
+ When run from a terminal, `proteum mcp` starts or reuses the managed local daemon at `http://127.0.0.1:3769/mcp`. When an MCP client launches it over pipes, use stdio:
21
19
 
22
20
  ```bash
23
- proteum mcp --cwd /path/to/app
24
- proteum mcp --url http://localhost:3101
25
- proteum mcp --session-file var/run/proteum/dev/agents/task.json
21
+ proteum mcp --stdio
26
22
  ```
27
23
 
28
- The stdio server reads manifest, instruction, and tracked-session data from disk. When a live dev server is known through `--url`, a tracked session file, or the manifest router port, runtime tools read the dev endpoints directly instead of spawning CLI commands.
24
+ `proteum dev` ensures the managed machine MCP daemon is running before the dev loop starts. Only one managed daemon may run at a time. Stale daemon records are cleaned automatically.
25
+
26
+ The router is read-only. It does not start or stop dev servers, mutate files, refresh generated code, run migrations, or execute commands.
27
+
28
+ Use this flow:
29
+
30
+ 1. Call MCP `workflow_start` with `cwd` or a known `projectId`.
31
+ 2. If the result is ambiguous or returns offline app candidates, call `project_resolve { cwd }`, pick the intended app root, start exactly one `proteum dev` server from that app root when needed, then retry `workflow_start`.
32
+ 3. Pass the returned live `projectId` to every follow-up app-bound MCP call.
33
+ 4. After an MCP read succeeds, do not run the equivalent CLI command or broad source search for the same state; keep CLI for fallback, validation, and final terminal evidence.
34
+
35
+ Example tool calls:
36
+
37
+ ```json
38
+ {"tool":"workflow_start","arguments":{"cwd":"/repo/apps/product","task":"read-only runtime health pass","route":"/dashboard"}}
39
+ {"tool":"projects_list","arguments":{}}
40
+ {"tool":"project_resolve","arguments":{"cwd":"/repo/apps/product/client/pages"}}
41
+ {"tool":"workflow_start","arguments":{"projectId":"prj_0123abcd4567","route":"/dashboard"}}
42
+ {"tool":"runtime_status","arguments":{"projectId":"prj_0123abcd4567"}}
43
+ {"tool":"orient","arguments":{"projectId":"prj_0123abcd4567","query":"/dashboard"}}
44
+ {"tool":"route_candidates","arguments":{"projectId":"prj_0123abcd4567","query":"dashboard","limit":8}}
45
+ {"tool":"explain_summary","arguments":{"projectId":"prj_0123abcd4567","query":"/dashboard"}}
46
+ {"tool":"diagnose","arguments":{"projectId":"prj_0123abcd4567","path":"/dashboard"}}
47
+ {"tool":"db_query","arguments":{"projectId":"prj_0123abcd4567","sql":"SELECT id, email FROM User LIMIT 5","limit":5}}
48
+ ```
29
49
 
30
- Use stdio MCP when the agent environment can launch a long-lived tool server but does not already have direct access to the running `proteum dev` HTTP transport.
50
+ `workflow_start` is the only app-bound bootstrap tool that may resolve from `cwd` when `projectId` is not known. It may return offline app candidates when no matching dev server is running yet. Other app-bound tools require a live `projectId`; if they omit it, the router returns a compact error that tells the agent to call `projects_list` or `project_resolve`. There is no single-project fallback, because wrong-project reads are worse than an explicit routing retry.
31
51
 
32
52
  ## Dev Runtime Endpoint
33
53
 
34
- During `proteum dev`, the app exposes the same MCP contract through the official streamable HTTP transport:
54
+ During `proteum dev`, the app exposes the same app-level MCP contract through the official streamable HTTP transport:
35
55
 
36
56
  ```text
37
57
  POST /__proteum/mcp
@@ -39,7 +59,7 @@ GET /__proteum/mcp
39
59
  DELETE /__proteum/mcp
40
60
  ```
41
61
 
42
- This endpoint is dev-only and local-tooling-only. It uses the running app's in-memory diagnostics, trace, perf, and log stores where possible, so runtime tools avoid process startup and avoid dumping full trace payloads by default.
62
+ This endpoint is dev-only and local-tooling-only. It is already rooted to the running app, so its tools do not require `projectId` or `cwd`. The machine router strips routing fields before forwarding a call here.
43
63
 
44
64
  The dev session UI and ready banner print:
45
65
 
@@ -48,11 +68,30 @@ mcp http://localhost:<port>/__proteum/mcp
48
68
  MCP: http://localhost:<port>/__proteum/mcp
49
69
  ```
50
70
 
51
- Use dev-hosted MCP when an agent is iterating against an already running app. It is the fastest path for repeated `runtime_status`, `orient`, `diagnose`, `trace_*`, `perf_*`, and `logs_tail` reads.
71
+ `proteum dev` also writes a machine registry record under `~/.proteum/dev-sessions/`. The stable `projectId` is derived from the canonical app root, so it remains stable across port or session-file changes.
72
+
73
+ ## Discovery And Recovery
74
+
75
+ If machine MCP routing fails:
76
+
77
+ 1. Run `proteum mcp status`.
78
+ 2. Run `proteum runtime status` from the intended app root. If you are in a monorepo wrapper, use the returned app candidates and exact next action instead of starting dev from the wrapper.
79
+ 3. If no live app session exists, use the exact Start Dev next action returned by runtime status. It checks the configured router/HMR ports and suggests an alternate free port when the manifest default is occupied.
80
+ 4. If a live session exists but runtime/MCP is unreachable, stop the listed session file with `proteum dev stop --session-file <path>`, then start dev again.
81
+ 5. Retry MCP `workflow_start` and use the returned `projectId`.
82
+
83
+ Offline `project_resolve` and `workflow_start` candidates also inspect configured router/HMR ports before returning `nextAction`. If the configured port already serves the same app but no live machine project is registered, the next action is runtime tracking repair, not starting a second dev server.
84
+
85
+ `proteum runtime status` refreshes the machine registry for live tracked sessions, so this recovery path also repairs missing router records after an upgrade.
86
+
87
+ Do not start a second `proteum dev` server in the same worktree. `proteum dev` fails fast when another live tracked session already exists for the same app root.
88
+ Do not start a second managed `proteum mcp` daemon. `proteum mcp` reuses the live daemon or reports its current URL.
89
+ Do not call `diagnose`, `trace_*`, or `perf_*` while runtime health is unreachable; repair or start dev first.
90
+ Do not `curl` normal page routes to identify port ownership; use `proteum runtime status` or Proteum dev-only `/__proteum/*` endpoints so wrong-app HTML is never dumped into agent context.
52
91
 
53
92
  ## Output Contract
54
93
 
55
- MCP tool and resource payloads are compact single-line JSON strings in this shape:
94
+ MCP tool payloads are compact single-line JSON strings in this shape:
56
95
 
57
96
  ```json
58
97
  {"ok":true,"format":"proteum-mcp-v1","summary":"...","data":{},"nextActions":[],"omitted":[]}
@@ -69,13 +108,22 @@ Do not make MCP tools return pretty-printed JSON or raw trace/log dumps by defau
69
108
 
70
109
  ## Tools
71
110
 
72
- The v1 tools are read-only:
111
+ Machine-only tools:
112
+
113
+ | Tool | Purpose |
114
+ | --- | --- |
115
+ | `projects_list` | List live Proteum dev projects and stable `projectId` values |
116
+ | `project_resolve` | Resolve a live project or offline app candidate by `projectId`, `cwd`, app root, or app-root substring |
117
+
118
+ App-bound tools require `projectId` when called through `proteum mcp`:
73
119
 
74
120
  | Tool | Purpose |
75
121
  | --- | --- |
122
+ | `workflow_start` | One-call bootstrap with resolved project, runtime, selected instruction previews, owner summary, doctor summaries, duplicate-avoidance rules, and next actions |
76
123
  | `runtime_status` | Manifest summary, selected runtime, tracked sessions, health, and MCP URL |
77
124
  | `orient` | Owner, instruction routing, connected boundaries, and next actions |
78
- | `instructions_resolve` | Selected instruction files for a query, with short previews |
125
+ | `instructions_resolve` | Selected instruction files for a query, with short previews and full-read policy |
126
+ | `route_candidates` | Compact route/controller/page matches for a query without dumping the raw route table |
79
127
  | `explain_summary` | Compact manifest summary or owner lookup |
80
128
  | `doctor` | Compact manifest and optional contract diagnostics |
81
129
  | `diagnose` | Composite diagnosis for an existing route, query, or request trace |
@@ -84,53 +132,47 @@ The v1 tools are read-only:
84
132
  | `perf_top` | Hot-path perf rollup |
85
133
  | `perf_request` | One-request waterfall and attribution |
86
134
  | `logs_tail` | Capped recent server logs |
87
-
88
- MCP v1 intentionally does not start/stop dev servers, refresh generated files, arm traces, export traces, write files, run migrations, or execute app commands.
89
-
90
- ## Resources
91
-
92
- Static resources expose common compact reads:
93
-
94
- - `proteum://runtime/status`
95
- - `proteum://instructions/router`
96
- - `proteum://manifest/summary`
97
- - `proteum://trace/latest/summary`
98
- - `proteum://perf/top`
135
+ | `db_query` | Capped read-only database diagnostics for one `SELECT`, `SHOW`, or `EXPLAIN` statement |
99
136
 
100
137
  ## CLI Boundary
101
138
 
102
139
  Use CLI commands when the result must be reproducible as a terminal step, CI-like validation, or human-shareable command output:
103
140
 
104
141
  ```bash
105
- proteum dev
142
+ proteum dev --session-file var/run/proteum/dev/agents/task.json --port 3101
106
143
  proteum build --prod
107
144
  proteum check
108
145
  proteum refresh
109
146
  proteum diagnose /dashboard --port 3101
110
147
  proteum verify request /dashboard --port 3101
111
148
  proteum trace show <requestId> --events --port 3101
149
+ proteum explain owner /dashboard
150
+ proteum db query "SELECT id, email FROM User LIMIT 5" --port 3101
151
+ proteum explain --routes --controllers --full # only when the raw route/controller arrays are required
112
152
  ```
113
153
 
114
- Use MCP when an agent is asking the same running app for repeated state:
154
+ Use MCP when an agent is asking a running app for repeated state:
115
155
 
116
156
  ```text
117
- runtime_status
118
- instructions_resolve
119
- orient
120
- diagnose
121
- trace_latest
122
- perf_request
123
- logs_tail
157
+ workflow_start { cwd, task, route? }
158
+ runtime_status { projectId }
159
+ instructions_resolve { projectId, query }
160
+ orient { projectId, query }
161
+ route_candidates { projectId, query }
162
+ explain_summary { projectId, query }
163
+ doctor { projectId }
164
+ diagnose { projectId, path }
165
+ trace_show { projectId, requestId }
166
+ trace_latest { projectId }
167
+ perf_request { projectId, query }
168
+ logs_tail { projectId }
169
+ db_query { projectId, sql, limit? }
124
170
  ```
125
171
 
126
- ## Routing Guidance
172
+ After an MCP read succeeds, do not run the equivalent CLI command for the same state, and do not run broad source searches for ownership that MCP already returned. CLI output is for fallback, validation, command evidence, and human-shareable reproductions.
127
173
 
128
- Use these surfaces in this order:
174
+ Database diagnostics are intentionally read-only. `db_query` and `proteum db query` accept only one `SELECT`, `SHOW`, or `EXPLAIN` statement, return rows, columns, elapsed milliseconds, and cap metadata, and reject multi-statement SQL, `EXPLAIN ANALYZE`, locking reads, file reads/writes, sleep, and benchmark functions.
129
175
 
130
- 1. Agent instructions for hard safety policy and routing rules.
131
- 2. MCP for repeated reads, runtime status, instruction selection, traces, perf, and logs.
132
- 3. Compact CLI for reproducible terminal validation and CI-like checks.
133
- 4. Full CLI escape hatches only after compact MCP/CLI output identifies the missing detail.
134
176
 
135
177
  ## Benchmark
136
178
 
@@ -140,10 +182,32 @@ The Product `/domains` diagnostic loop measured on May 7, 2026 used `ceil(UTF-8
140
182
  | --- | ---: | ---: |
141
183
  | Compact CLI single loop | 6,286 | 4,809 ms |
142
184
  | Dev-hosted HTTP MCP single loop | 5,211 | 232 ms |
143
- | Stdio MCP single loop | 5,526 | 900 ms |
144
185
  | Compact CLI repeated reads x3 | 11,660 | 9,572 ms |
145
186
  | Dev-hosted HTTP MCP repeated reads x3 | 10,537 | 214 ms |
146
187
 
147
- The benchmark included the routed instruction docs separately. Reading the four selected instruction files once was about 4,881 estimated output tokens; refreshing the instruction routing through MCP `instructions_resolve` was about 722 estimated output tokens.
188
+ Machine routing adds one lightweight `projects_list` lookup but keeps repeated app reads on the dev-hosted runtime endpoint. The practical rule is: use CLI for reproducible checks and final evidence, then use MCP with `projectId` for repeated reads against the same app/runtime.
189
+
190
+ ## Codex Usage Test
191
+
192
+ Proteum core uses Vitest for framework tests. The live Codex MCP usage test is opt-in because it runs the real Codex CLI, may spend model tokens, and depends on the developer machine's Codex auth plus MCP registration.
148
193
 
149
- The practical rule from the benchmark is: use CLI for the first reproducible check and validation record, then use MCP for repeated reads against the same app/runtime.
194
+ ```bash
195
+ PROTEUM_CODEX_MCP_USAGE_CWD=/absolute/path/to/proteum/app npm run test:codex-mcp
196
+ ```
197
+
198
+ The test sends a read-only runtime health prompt to `codex exec --json`, stores the JSONL transcript, stderr, last message, and `summary.json`, then asserts:
199
+
200
+ - token usage was reported and quantified
201
+ - at least one Proteum MCP `workflow_start` call happened
202
+ - total Proteum MCP calls meet `PROTEUM_CODEX_MCP_MIN_MCP_CALLS` (`4` by default)
203
+ - Proteum CLI fallback calls stay under `PROTEUM_CODEX_MCP_MAX_CLI_CALLS` (`4` by default)
204
+
205
+ Useful optional variables:
206
+
207
+ ```bash
208
+ CODEX_CLI=/path/to/codex
209
+ PROTEUM_CODEX_MCP_USAGE_OUTPUT_DIR=/tmp/proteum-codex-mcp-usage
210
+ PROTEUM_CODEX_MCP_USAGE_TIMEOUT_MS=1200000
211
+ PROTEUM_CODEX_MCP_MIN_MCP_CALLS=4
212
+ PROTEUM_CODEX_MCP_MAX_CLI_CALLS=4
213
+ ```