@sdods/mcp 0.22.0 → 0.22.1

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.
@@ -0,0 +1,20 @@
1
+ export interface AsyncRunState {
2
+ runId: string;
3
+ status: 'queued' | 'running' | 'passed' | 'failed' | 'error' | 'cancelled';
4
+ startedAt: string;
5
+ finishedAt?: string;
6
+ exitCode?: number;
7
+ error?: {
8
+ code: string;
9
+ message: string;
10
+ };
11
+ }
12
+ /** Per-connection lifecycle, including failures before the CLI creates any artifacts. */
13
+ export declare class AsyncRunTracker {
14
+ private readonly maxEntries;
15
+ private readonly jobs;
16
+ constructor(maxEntries?: number);
17
+ get(runId: string): AsyncRunState | undefined;
18
+ start(runId: string, launch: (onProgress: () => void) => Promise<unknown>): AsyncRunState;
19
+ }
20
+ //# sourceMappingURL=async-runs.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { SdodsCliError } from './cli.js';
2
+ /** Per-connection lifecycle, including failures before the CLI creates any artifacts. */
3
+ export class AsyncRunTracker {
4
+ maxEntries;
5
+ jobs = new Map();
6
+ constructor(maxEntries = 1000) {
7
+ this.maxEntries = maxEntries;
8
+ if (!Number.isInteger(maxEntries) || maxEntries < 1)
9
+ throw new Error('Invalid async run capacity');
10
+ }
11
+ get(runId) {
12
+ const job = this.jobs.get(runId);
13
+ return job ? { ...job, ...(job.error ? { error: { ...job.error } } : {}) } : undefined;
14
+ }
15
+ start(runId, launch) {
16
+ if (this.jobs.has(runId)) {
17
+ throw Object.assign(new Error(`Run ${runId} already exists on this connection.`), {
18
+ error: { code: 'RUN_EXISTS' },
19
+ });
20
+ }
21
+ if (this.jobs.size >= this.maxEntries) {
22
+ // Keep active jobs observable. Only terminal entries are eligible for eviction.
23
+ const oldest = [...this.jobs.values()].find((job) => job.finishedAt !== undefined);
24
+ if (oldest)
25
+ this.jobs.delete(oldest.runId);
26
+ else
27
+ throw Object.assign(new Error('Too many active background runs on this connection.'), {
28
+ error: { code: 'RUN_CAPACITY' },
29
+ });
30
+ }
31
+ const job = { runId, status: 'queued', startedAt: new Date().toISOString() };
32
+ this.jobs.set(runId, job);
33
+ void Promise.resolve()
34
+ .then(() => launch(() => {
35
+ if (!job.finishedAt)
36
+ job.status = 'running';
37
+ }))
38
+ .then(() => {
39
+ job.status = 'passed';
40
+ job.exitCode = 0;
41
+ })
42
+ .catch((cause) => {
43
+ const cliError = cause instanceof SdodsCliError ? cause : undefined;
44
+ const aborted = cause instanceof Error && cause.name === 'AbortError';
45
+ job.status = aborted ? 'cancelled' : cliError?.exitCode === 1 ? 'failed' : 'error';
46
+ job.exitCode = cliError?.exitCode;
47
+ job.error = {
48
+ code: cliError?.error.code ?? (aborted ? 'ABORTED' : 'RUN_FAILED'),
49
+ message: (cause instanceof Error ? cause.message : String(cause)).slice(0, 2000),
50
+ };
51
+ })
52
+ .finally(() => {
53
+ job.finishedAt = new Date().toISOString();
54
+ });
55
+ return this.get(runId);
56
+ }
57
+ }
58
+ //# sourceMappingURL=async-runs.js.map
@@ -8,8 +8,8 @@ export declare const UPSTREAM_SHAPES: {
8
8
  readonly doubleClick: z.ZodOptional<z.ZodBoolean>;
9
9
  readonly button: z.ZodOptional<z.ZodEnum<{
10
10
  left: "left";
11
- right: "right";
12
11
  middle: "middle";
12
+ right: "right";
13
13
  }>>;
14
14
  readonly modifiers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
15
15
  Alt: "Alt";
@@ -22,10 +22,10 @@ export declare const UPSTREAM_SHAPES: {
22
22
  readonly browser_close: {};
23
23
  readonly browser_console_messages: {
24
24
  readonly level: z.ZodOptional<z.ZodEnum<{
25
+ debug: "debug";
25
26
  error: "error";
26
27
  info: "info";
27
28
  warning: "warning";
28
- debug: "debug";
29
29
  }>>;
30
30
  readonly all: z.ZodOptional<z.ZodBoolean>;
31
31
  readonly filename: z.ZodOptional<z.ZodString>;
@@ -64,11 +64,11 @@ export declare const UPSTREAM_SHAPES: {
64
64
  target: z.ZodString;
65
65
  name: z.ZodString;
66
66
  type: z.ZodEnum<{
67
- textbox: "textbox";
68
67
  checkbox: "checkbox";
69
- radio: "radio";
70
68
  combobox: "combobox";
69
+ radio: "radio";
71
70
  slider: "slider";
71
+ textbox: "textbox";
72
72
  }>;
73
73
  value: z.ZodString;
74
74
  }, z.core.$strip>>;
@@ -101,8 +101,8 @@ export declare const UPSTREAM_SHAPES: {
101
101
  readonly y: z.ZodNumber;
102
102
  readonly button: z.ZodOptional<z.ZodEnum<{
103
103
  left: "left";
104
- right: "right";
105
104
  middle: "middle";
105
+ right: "right";
106
106
  }>>;
107
107
  readonly clickCount: z.ZodOptional<z.ZodNumber>;
108
108
  readonly delay: z.ZodOptional<z.ZodNumber>;
@@ -110,8 +110,8 @@ export declare const UPSTREAM_SHAPES: {
110
110
  readonly browser_mouse_down: {
111
111
  readonly button: z.ZodOptional<z.ZodEnum<{
112
112
  left: "left";
113
- right: "right";
114
113
  middle: "middle";
114
+ right: "right";
115
115
  }>>;
116
116
  };
117
117
  readonly browser_mouse_drag_xy: {
@@ -127,8 +127,8 @@ export declare const UPSTREAM_SHAPES: {
127
127
  readonly browser_mouse_up: {
128
128
  readonly button: z.ZodOptional<z.ZodEnum<{
129
129
  left: "left";
130
- right: "right";
131
130
  middle: "middle";
131
+ right: "right";
132
132
  }>>;
133
133
  };
134
134
  readonly browser_mouse_wheel: {
@@ -142,16 +142,17 @@ export declare const UPSTREAM_SHAPES: {
142
142
  readonly browser_network_request: {
143
143
  readonly index: z.ZodNumber;
144
144
  readonly part: z.ZodOptional<z.ZodEnum<{
145
- "request-headers": "request-headers";
146
145
  "request-body": "request-body";
147
- "response-headers": "response-headers";
146
+ "request-headers": "request-headers";
148
147
  "response-body": "response-body";
148
+ "response-headers": "response-headers";
149
149
  }>>;
150
150
  readonly filename: z.ZodOptional<z.ZodString>;
151
151
  };
152
152
  readonly browser_network_requests: {
153
153
  readonly static: z.ZodOptional<z.ZodBoolean>;
154
154
  readonly filter: z.ZodOptional<z.ZodString>;
155
+ readonly all: z.ZodOptional<z.ZodBoolean>;
155
156
  readonly filename: z.ZodOptional<z.ZodString>;
156
157
  };
157
158
  readonly browser_pdf_save: {
@@ -212,8 +213,8 @@ export declare const UPSTREAM_SHAPES: {
212
213
  readonly element: z.ZodOptional<z.ZodString>;
213
214
  readonly target: z.ZodOptional<z.ZodString>;
214
215
  readonly type: z.ZodOptional<z.ZodEnum<{
215
- png: "png";
216
216
  jpeg: "jpeg";
217
+ png: "png";
217
218
  webp: "webp";
218
219
  }>>;
219
220
  readonly filename: z.ZodOptional<z.ZodString>;
@@ -239,12 +240,12 @@ export declare const UPSTREAM_SHAPES: {
239
240
  readonly browser_video_show_actions: {
240
241
  readonly duration: z.ZodOptional<z.ZodNumber>;
241
242
  readonly position: z.ZodOptional<z.ZodEnum<{
242
- "top-left": "top-left";
243
- top: "top";
244
- "top-right": "top-right";
245
- "bottom-left": "bottom-left";
246
243
  bottom: "bottom";
244
+ "bottom-left": "bottom-left";
247
245
  "bottom-right": "bottom-right";
246
+ top: "top";
247
+ "top-left": "top-left";
248
+ "top-right": "top-right";
248
249
  }>>;
249
250
  readonly cursor: z.ZodOptional<z.ZodEnum<{
250
251
  none: "none";
@@ -1,5 +1,5 @@
1
1
  // GENERATED by scripts/gen-browser-shapes.ts from
2
- // packages/mcp/test/fixtures/playwright-mcp-tools.json (Playwright 1.64.1).
2
+ // packages/mcp/test/fixtures/playwright-mcp-tools.json (Playwright 1.65.1).
3
3
  // Do not edit by hand: `bun run mcp:browser-shapes` rewrites it, and
4
4
  // packages/mcp/test/browser-schemas.test.ts fails if it drifts from the dump.
5
5
  //
@@ -256,6 +256,10 @@ export const UPSTREAM_SHAPES = {
256
256
  .string()
257
257
  .describe('Only return requests whose URL matches this regexp (e.g. "/api/.*user").')
258
258
  .optional(),
259
+ all: z
260
+ .boolean()
261
+ .describe('Return all network requests since the beginning of the session, not just since the last navigation. Defaults to false.')
262
+ .optional(),
259
263
  filename: z
260
264
  .string()
261
265
  .describe('File name to save the network requests to. Relative file names are resolved against the workspace root. If not provided, requests are returned as text.')
package/dist/cli.d.ts CHANGED
@@ -22,6 +22,8 @@ export interface CliOptions {
22
22
  timeoutMs?: number;
23
23
  signal?: AbortSignal;
24
24
  /** receives each stdout line as it arrives (progress) */
25
+ /** Called after the operating system successfully starts the child. */
26
+ onSpawn?: () => void;
25
27
  onLine?: (line: string, stream: 'stdout' | 'stderr') => void;
26
28
  /** do not pass --json (for commands that stream human output) */
27
29
  raw?: boolean;
package/dist/cli.js CHANGED
@@ -63,6 +63,7 @@ export async function sdodsCli(args, opts = {}) {
63
63
  stdio: ['ignore', 'pipe', 'pipe'],
64
64
  signal: opts.signal,
65
65
  });
66
+ child.once('spawn', () => opts.onSpawn?.());
66
67
  let stdout = '';
67
68
  let stderr = '';
68
69
  let outBuf = '';
package/dist/fs.d.ts CHANGED
@@ -38,8 +38,15 @@ export interface ScenarioAttemptFiles {
38
38
  }>;
39
39
  healEvents: unknown[];
40
40
  }
41
- /** Walk `<runDir>/<slug>/<fingerprint>/r<retry>/` directories. */
42
- export declare function listScenarioDirs(runDir: string, slug?: string): ScenarioAttemptFiles[];
43
- export declare function readScenarioDir(dir: string, fingerprint: string, retry: number): ScenarioAttemptFiles;
41
+ export interface ScenarioReadOptions {
42
+ /** List request/response filenames without reading their potentially large JSON bodies. */
43
+ includeApiBodies?: boolean;
44
+ }
45
+ export type ScenarioAttemptDir = Pick<ScenarioAttemptFiles, 'dir' | 'fingerprint' | 'retry'>;
46
+ /** Enumerate attempts without opening metadata, API snapshots or heal logs. */
47
+ export declare function listScenarioAttemptDirs(runDir: string, slug?: string): ScenarioAttemptDir[];
48
+ /** Walk and read all attempt artifacts for consumers that need their details. */
49
+ export declare function listScenarioDirs(runDir: string, slug?: string, options?: ScenarioReadOptions): ScenarioAttemptFiles[];
50
+ export declare function readScenarioDir(dir: string, fingerprint: string, retry: number, options?: ScenarioReadOptions): ScenarioAttemptFiles;
44
51
  export declare function screenshotUri(runId: string, fingerprint: string, retry: number, file: string): string;
45
52
  //# sourceMappingURL=fs.d.ts.map
package/dist/fs.js CHANGED
@@ -105,8 +105,8 @@ export function getRun(rootDir, runId) {
105
105
  export function lastRun(rootDir) {
106
106
  return listRuns(rootDir, 1)[0];
107
107
  }
108
- /** Walk `<runDir>/<slug>/<fingerprint>/r<retry>/` directories. */
109
- export function listScenarioDirs(runDir, slug) {
108
+ /** Enumerate attempts without opening metadata, API snapshots or heal logs. */
109
+ export function listScenarioAttemptDirs(runDir, slug) {
110
110
  const out = [];
111
111
  if (!existsSync(runDir))
112
112
  return out;
@@ -123,17 +123,21 @@ export function listScenarioDirs(runDir, slug) {
123
123
  const fpDir = join(sDir, fp);
124
124
  if (!statSync(fpDir).isDirectory())
125
125
  continue;
126
- for (const r of readdirSync(fpDir)) {
127
- const m = /^r(\d+)$/.exec(r);
128
- if (!m)
126
+ for (const r of readdirSync(fpDir, { withFileTypes: true })) {
127
+ const m = /^r(\d+)$/.exec(r.name);
128
+ if (!m || !r.isDirectory())
129
129
  continue;
130
- out.push(readScenarioDir(join(fpDir, r), fp, Number(m[1])));
130
+ out.push({ dir: join(fpDir, r.name), fingerprint: fp, retry: Number(m[1]) });
131
131
  }
132
132
  }
133
133
  }
134
134
  return out;
135
135
  }
136
- export function readScenarioDir(dir, fingerprint, retry) {
136
+ /** Walk and read all attempt artifacts for consumers that need their details. */
137
+ export function listScenarioDirs(runDir, slug, options = {}) {
138
+ return listScenarioAttemptDirs(runDir, slug).map((s) => readScenarioDir(s.dir, s.fingerprint, s.retry, options));
139
+ }
140
+ export function readScenarioDir(dir, fingerprint, retry, options = {}) {
137
141
  const files = existsSync(dir) ? readdirSync(dir) : [];
138
142
  const screenshots = [];
139
143
  for (const f of files) {
@@ -156,7 +160,7 @@ export function readScenarioDir(dir, fingerprint, retry) {
156
160
  stepIndex: Number(m[1]),
157
161
  callIndex: Number(m[2]),
158
162
  part: m[3],
159
- body: readJson(join(apiDir, f)),
163
+ body: options.includeApiBodies === false ? undefined : readJson(join(apiDir, f)),
160
164
  });
161
165
  }
162
166
  }
@@ -41,6 +41,30 @@ function clip(json) {
41
41
  ? json
42
42
  : `${json.slice(0, STRUCTURED_LIMIT)}… (${json.length - STRUCTURED_LIMIT} more chars; narrow the query or read the file directly)`;
43
43
  }
44
+ /** Omit only a provably complete duplicate; clipped summaries keep their structured supplement. */
45
+ function containsStructuredSummary(text, structured) {
46
+ const body = /\n\n```json\n([\s\S]*)\n```$/.exec(text)?.[1];
47
+ if (body === undefined)
48
+ return false;
49
+ try {
50
+ const parsed = JSON.parse(body);
51
+ const json = JSON.stringify(parsed);
52
+ if (json === JSON.stringify(structured))
53
+ return true;
54
+ const keys = Object.keys(structured);
55
+ // The registry wraps top-level arrays/primitives for MCP structuredContent.
56
+ return (keys.length === 1 &&
57
+ ((keys[0] === 'items' &&
58
+ Array.isArray(parsed) &&
59
+ json === JSON.stringify(structured.items)) ||
60
+ (keys[0] === 'value' &&
61
+ (parsed === null || typeof parsed !== 'object') &&
62
+ json === JSON.stringify(structured.value))));
63
+ }
64
+ catch {
65
+ return false;
66
+ }
67
+ }
44
68
  export function toAgentSdkTools(reg, ctx) {
45
69
  return reg.list(ctx).map((tool) => ({
46
70
  name: tool.name,
@@ -52,7 +76,8 @@ export function toAgentSdkTools(reg, ctx) {
52
76
  const content = [...r.content];
53
77
  // The text content is already clipped by `summarize`; appending the whole structured payload
54
78
  // would put it straight back and grow the conversation without bound, so it is clipped too.
55
- if (r.structuredContent)
79
+ if (r.structuredContent &&
80
+ !content.some((c) => c.type === 'text' && containsStructuredSummary(c.text, r.structuredContent)))
56
81
  content.push({ type: 'text', text: clip(JSON.stringify(r.structuredContent)) });
57
82
  return { content, isError: r.isError };
58
83
  },
@@ -1,3 +1,4 @@
1
+ import type { AsyncRunTracker } from '../async-runs.js';
1
2
  import { z, type ZodRawShape } from 'zod';
2
3
  import { type Scope } from '@sdods/contracts';
3
4
  export declare const DOCS_BASE_URL = "https://docs.sdods.com";
@@ -39,6 +40,8 @@ export interface ToolContext {
39
40
  * second principal cannot name the first one's session id and drive their logged-in browser.
40
41
  */
41
42
  browser?: BrowserSessions;
43
+ /** Background CLI lifecycle owned by this connection, never shared between principals. */
44
+ asyncRuns?: AsyncRunTracker;
42
45
  }
43
46
  /** The subset of the session manager the registry needs to know about, to avoid a cycle. */
44
47
  export interface BrowserSessions {
package/dist/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { AsyncRunTracker } from './async-runs.js';
1
2
  import { z } from 'zod';
2
3
  import { McpServer } from '@modelcontextprotocol/server';
3
4
  import { SCOPES } from '@sdods/contracts';
@@ -58,6 +59,7 @@ export function buildToolContext(opts = {}) {
58
59
  env: opts.env,
59
60
  onProgress: opts.onProgress,
60
61
  logger: opts.logger ?? stderrLogger(),
62
+ asyncRuns: caps.has('run') ? new AsyncRunTracker() : undefined,
61
63
  browser: caps.has('browser') ? new BrowserSessionManager({ rootDir }) : undefined,
62
64
  };
63
65
  }
@@ -14,10 +14,10 @@ export declare function analyzeCoverage(root: string): {
14
14
  suites: string[];
15
15
  }[];
16
16
  endpoints: {
17
- scenarios: number;
18
- suites: string[];
19
17
  module: string;
20
18
  endpoint: string;
19
+ scenarios: number;
20
+ suites: string[];
21
21
  }[];
22
22
  modules: {
23
23
  module: string;
@@ -32,7 +32,7 @@ export declare function analyzeCoverage(root: string): {
32
32
  };
33
33
  export declare function analyzeBestPractices(root: string): {
34
34
  findings: {
35
- severity: "error" | "warning" | "info";
35
+ severity: 'error' | 'warning' | 'info';
36
36
  rule: string;
37
37
  file: string;
38
38
  line?: number;
@@ -1,8 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  export declare const proposalTools: (import("../registry/registry.js").SdodsTool<{
3
3
  status: z.ZodOptional<z.ZodEnum<{
4
- pending: "pending";
5
4
  accepted: "accepted";
5
+ pending: "pending";
6
6
  rejected: "rejected";
7
7
  }>>;
8
8
  project: z.ZodOptional<z.ZodString>;
@@ -5,24 +5,24 @@ export declare const runTools: (import("../registry/registry.js").SdodsTool<{
5
5
  tags: z.ZodOptional<z.ZodString>;
6
6
  layers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
7
7
  api: "api";
8
- ui: "ui";
9
8
  hybrid: "hybrid";
10
9
  recorded: "recorded";
10
+ ui: "ui";
11
11
  }>>>;
12
12
  browsers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
13
13
  chromium: "chromium";
14
14
  edge: "edge";
15
15
  firefox: "firefox";
16
- webkit: "webkit";
17
16
  "mobile-chrome": "mobile-chrome";
18
17
  "mobile-safari": "mobile-safari";
18
+ webkit: "webkit";
19
19
  }>>>;
20
20
  process: z.ZodOptional<z.ZodString>;
21
21
  modules: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
22
  harMode: z.ZodOptional<z.ZodEnum<{
23
23
  off: "off";
24
- update: "update";
25
24
  replay: "replay";
25
+ update: "update";
26
26
  }>>;
27
27
  workers: z.ZodOptional<z.ZodNumber>;
28
28
  retries: z.ZodOptional<z.ZodNumber>;
@@ -35,6 +35,9 @@ export declare const runTools: (import("../registry/registry.js").SdodsTool<{
35
35
  project: z.ZodOptional<z.ZodString>;
36
36
  }> | import("../registry/registry.js").SdodsTool<{
37
37
  runId: z.ZodString;
38
+ includeScenarios: z.ZodOptional<z.ZodBoolean>;
39
+ limit: z.ZodOptional<z.ZodNumber>;
40
+ offset: z.ZodOptional<z.ZodNumber>;
38
41
  }> | import("../registry/registry.js").SdodsTool<{
39
42
  runId: z.ZodString;
40
43
  fingerprint: z.ZodString;
package/dist/tools/run.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { z } from 'zod';
4
- import { BrowserSchema, isRunId, runFiles } from '@sdods/contracts';
4
+ import { BrowserSchema, isRunId, newRunId, runFiles } from '@sdods/contracts';
5
5
  import { SdodsCliError, sdodsCli } from '../cli.js';
6
- import { getRun, lastRun, listRuns, listScenarioDirs, readScenarioDir, screenshotUri, } from '../fs.js';
6
+ import { getRun, lastRun, listRuns, listScenarioDirs, listScenarioAttemptDirs, readScenarioDir, screenshotUri, } from '../fs.js';
7
7
  import { defineTool, summarize } from '../registry/registry.js';
8
8
  const runArgs = {
9
9
  project: z.string(),
@@ -92,12 +92,9 @@ export const runTools = [
92
92
  annotations: { openWorldHint: true },
93
93
  docsPath: '/docs/reference/cli-commands/run',
94
94
  handler: async (args, ctx) => {
95
- const cli = buildRunCli(args);
96
- let runId = args.runId;
95
+ const runId = args.runId ?? newRunId();
96
+ const cli = buildRunCli({ ...args, runId });
97
97
  const onLine = (line) => {
98
- const m = /run[- ]?id[:=]\s*([0-9a-f-]{20,})/i.exec(line);
99
- if (m && !runId)
100
- runId = m[1];
101
98
  const p = /\[(\d+)\/(\d+)\]/.exec(line);
102
99
  ctx.onProgress?.({
103
100
  message: line.slice(0, 200),
@@ -129,9 +126,7 @@ export const runTools = [
129
126
  exitCode = 1;
130
127
  json = safeJson(e.stderr) ?? safeJson(e.message);
131
128
  }
132
- const summaryObj = json ?? {};
133
- runId = runId ?? summaryObj.runId ?? lastRun(ctx.rootDir)?.runId;
134
- const run = runId ? getRun(ctx.rootDir, runId) : undefined;
129
+ const run = getRun(ctx.rootDir, runId);
135
130
  const summary = run?.summary ?? json;
136
131
  return {
137
132
  text: summaryText(runId ?? '?', summary, exitCode),
@@ -149,13 +144,19 @@ export const runTools = [
149
144
  capability: 'run',
150
145
  annotations: { openWorldHint: true },
151
146
  handler: async (args, ctx) => {
152
- const { newRunId } = await import('@sdods/contracts');
153
147
  const runId = args.runId ?? newRunId();
154
148
  const cli = buildRunCli({ ...args, runId });
155
- void sdodsCli(cli, { cwd: ctx.rootDir, timeoutMs: 60 * 60_000 }).catch(() => undefined);
149
+ if (!ctx.asyncRuns)
150
+ throw new Error('Background runs require a server run-tracking context.');
151
+ if (getRun(ctx.rootDir, runId)) {
152
+ throw Object.assign(new Error(`Run ${runId} already has artifacts.`), {
153
+ error: { code: 'RUN_EXISTS' },
154
+ });
155
+ }
156
+ const state = ctx.asyncRuns.start(runId, (onProgress) => sdodsCli(cli, { cwd: ctx.rootDir, timeoutMs: 60 * 60_000, onSpawn: onProgress }));
156
157
  return {
157
- text: `Run ${runId} started. Poll with run_get { runId: "${runId}" }.`,
158
- data: { runId, status: 'running' },
158
+ text: `Run ${runId} queued. Poll with run_get { runId: "${runId}", includeScenarios: false }.`,
159
+ data: state,
159
160
  };
160
161
  },
161
162
  }),
@@ -188,18 +189,43 @@ export const runTools = [
188
189
  defineTool({
189
190
  name: 'run_get',
190
191
  title: 'Get run',
191
- description: 'Manifest, summary, report paths and the scenario list of a run (use "last" for the latest).',
192
- shape: { runId: z.string() },
192
+ description: 'Manifest, summary, reports and paginated scenario attempts (default 50, max 200). Use includeScenarios:false for lightweight status polling; use run_get_scenario for artifacts. Use "last" for the latest.',
193
+ shape: {
194
+ runId: z.string(),
195
+ includeScenarios: z
196
+ .boolean()
197
+ .optional()
198
+ .describe('Set false for lightweight status polling; skips scenario artifact reads and returns summary totals only.'),
199
+ limit: z
200
+ .number()
201
+ .int()
202
+ .positive()
203
+ .max(200)
204
+ .optional()
205
+ .describe('Scenario attempts per page (default 50).'),
206
+ offset: z.number().int().min(0).optional(),
207
+ },
193
208
  access: 'read',
194
209
  domain: 'runs',
195
210
  capability: 'run',
196
211
  handler: async (args, ctx) => {
197
212
  const run = args.runId === 'last' ? lastRun(ctx.rootDir) : getRun(ctx.rootDir, args.runId);
213
+ const job = ctx.asyncRuns?.get(run?.runId ?? args.runId);
214
+ if (!run && job)
215
+ return { text: summarize(`Run ${job.runId}`, job), data: job };
198
216
  if (!run)
199
217
  throw Object.assign(new Error(`Unknown run ${args.runId}`), {
200
218
  error: { code: 'NOT_FOUND' },
201
219
  });
202
- const scenarios = listScenarioDirs(run.dir, run.manifest?.projectSlug).map((s) => ({
220
+ const attempts = args.includeScenarios === false
221
+ ? []
222
+ : listScenarioAttemptDirs(run.dir, run.manifest?.projectSlug);
223
+ const offset = args.offset ?? 0;
224
+ const limit = args.limit ?? 50;
225
+ const scenarios = attempts
226
+ .slice(offset, offset + limit)
227
+ .map((s) => readScenarioDir(s.dir, s.fingerprint, s.retry, { includeApiBodies: false }))
228
+ .map((s) => ({
203
229
  fingerprint: s.fingerprint,
204
230
  retry: s.retry,
205
231
  name: s.meta?.scenarioName,
@@ -213,16 +239,29 @@ export const runTools = [
213
239
  const data = {
214
240
  runId: run.runId,
215
241
  dir: run.dir,
216
- status: run.summary?.status ??
217
- (existsSync(join(run.dir, runFiles.summary)) ? 'finished' : 'running'),
242
+ status: job && !job.finishedAt
243
+ ? job.status
244
+ : (run.summary?.status ??
245
+ job?.status ??
246
+ (existsSync(join(run.dir, runFiles.summary)) ? 'finished' : 'running')),
247
+ ...(job ? { execution: job } : {}),
218
248
  manifest: run.manifest,
219
- summary: run.summary,
249
+ summary: args.includeScenarios === false && run.summary
250
+ ? { status: run.summary.status, totals: run.summary.totals }
251
+ : run.summary,
220
252
  reports: {
221
253
  html: join(run.dir, runFiles.htmlReport),
222
254
  dashboard: join(run.dir, runFiles.dashboard),
223
255
  messages: join(run.dir, runFiles.messages),
224
256
  },
225
257
  scenarios,
258
+ scenarioPage: {
259
+ included: args.includeScenarios !== false,
260
+ total: args.includeScenarios === false ? undefined : attempts.length,
261
+ offset,
262
+ limit,
263
+ nextOffset: offset + limit < attempts.length ? offset + limit : undefined,
264
+ },
226
265
  };
227
266
  return {
228
267
  text: summarize(`Run ${run.runId}`, { ...data, scenarios: scenarios.slice(0, 50) }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdods/mcp",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "SDODS MCP server: project analysis, runs, results and proposals as tools for AI clients.",
5
5
  "license": "Apache-2.0",
6
6
  "funding": "https://sdods.com/sponsor/",
@@ -30,9 +30,9 @@
30
30
  "node": ">=22"
31
31
  },
32
32
  "dependencies": {
33
- "@sdods/contracts": "0.22.0",
33
+ "@sdods/contracts": "0.22.1",
34
34
  "@cucumber/gherkin": "^42.0.1",
35
- "@cucumber/messages": "^34.2.1",
35
+ "@cucumber/messages": "^35.0.0",
36
36
  "@modelcontextprotocol/client": "^2.4.0",
37
37
  "@modelcontextprotocol/node": "^2.1.2",
38
38
  "@modelcontextprotocol/server": "^2.4.0",