@chapterdev/mcp-dev-studio 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -9,7 +9,7 @@ MCP Dev Studio lets you:
9
9
  1. **Test your MCP locally:** see if agents call the right tool and load the right skill.
10
10
  2. **Run evals:** repeat every test in Claude Code and Codex and get a pass rate.
11
11
  3. **Compare models:** one prompt, several agents and models, answers side by side.
12
- 4. **Auto-fix with your agent:** it rewrites your tool descriptions and skills until the tests pass.
12
+ 4. **Auto-fix with your agent:** it writes tests aimed at your weak spots, then fixes your tool descriptions and skills until they pass.
13
13
 
14
14
  ![The Playground: one request answered side by side by Claude Code on Opus 5.5, Claude Code on Haiku 5.5 and Codex on GPT-6.1 Terra. Each card shows that the agent used the server and loaded the billing skill, every tool call with its timing, and the invoice preview the server rendered](docs/playground.png)
15
15
 
@@ -1,25 +1,44 @@
1
1
  // The skill that teaches a coding agent (Claude Code, Codex) to iterate on an
2
2
  // MCP server and its skills with mcp-dev-studio, while a person watches in the UI.
3
- // `mcp-dev-studio skill` writes it into the project.
3
+ // `mcp-dev-studio setup` writes it into the project, stamped with the version that wrote it,
4
+ // so `eval` can tell people (and their agents) when an upgrade brought a newer one.
5
+ import { existsSync, readFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ export const SKILL_DIRS = ['.claude/skills/mcp-dev-studio', '.agents/skills/mcp-dev-studio'];
4
8
  export function loopSkill(p) {
5
9
  return `---
6
10
  name: mcp-dev-studio
7
11
  description: Improve an MCP server's tool descriptions or its SKILL.md files by testing them in real agents (Claude Code, Codex) with mcp-dev-studio, then changing one thing at a time until the tests pass. Use when asked to fix, tune or test how agents use this MCP server or its skills, or why a skill does or doesn't load.
8
12
  ---
9
-
13
+ ${p.version ? `\n<!-- Written by mcp-dev-studio ${p.version}. Update with: npx @chapterdev/mcp-dev-studio setup -->\n` : ''}
10
14
  # Iterating with mcp-dev-studio
11
15
 
12
16
  mcp-dev-studio runs saved tests against ${p.server} in real Claude Code and Codex, several times each, and records every run as an attempt. The person you're working with may have the studio open (\`npx @chapterdev/mcp-dev-studio\`); it shows each run live and the history of attempts, so leave notes that read well there.
13
17
 
18
+ ## Write tests that can fail
19
+
20
+ The loop only finds what the tests probe, and happy-path tests usually pass. Before the baseline, read the server's tools (descriptions and parameters) and its skills, and list every weak spot you notice. Write at least one test aimed at each:
21
+
22
+ - **Vague or missing parameter descriptions**: ask the way a person would, not the way the schema wants. If a parameter takes an id but doesn't say so, ask to act on the item by its name.
23
+ - **Bare tool descriptions**: a prompt that needs what the description leaves out, like allowed values or formats.
24
+ - **Overlapping tools**: a prompt only one of them should handle, with \`forbidTools\` for the other.
25
+ - **Over-broad or vague skill descriptions**: a should-load test (\`expectSkills\`) and a shouldn't-load test (\`forbidSkills\`) on a nearby but unrelated prompt.
26
+
27
+ Make the checks strict enough to catch the agent working around the flaw. A capable agent recovers from a failed call with extra lookups and still gets there, so set \`maxToolCalls\` to what a clear description would need, or have \`judge\` require no failed tool calls.
28
+
29
+ Test only the agents the person asked for (\`--host claude-code\` if they said Claude Code); otherwise both.
30
+
14
31
  ## The loop
15
32
 
16
- 1. **Baseline.** \`npx @chapterdev/mcp-dev-studio eval --json --host claude-code,codex --note "baseline"\`
33
+ 1. **Baseline.** \`npx @chapterdev/mcp-dev-studio eval --json --host claude-code,codex --note "baseline"\` (or just the agents the person asked for)
17
34
  2. **Read why it failed.** In the JSON, each failing test has \`failures\` (check, detail, how many runs) and \`transcripts\`. Open a transcript before guessing: \`events\` shows every tool call and what the agent said.
18
35
  3. **Change one thing** that explains the failure (see "What to change").
19
36
  4. **Rerun what failed**, saying what you changed: \`npx @chapterdev/mcp-dev-studio eval --json --failed --host <same hosts> --note "<the change, in a few words>"\`. \`sinceLastAttempt.tests\` says which tests were fixed or broke.
20
37
  5. **Check for regressions** with a full run once the failures pass. A change that fixes one test and breaks another isn't done.
21
38
  6. **Keep or revert.** If an attempt made things worse, undo the change before trying the next idea.
22
- 7. **Stop** when everything passes on both agents, or after about five attempts without progress. Then say what you changed, what each attempt showed, and what's still failing.
39
+ 7. **Stop** when everything passes, or after about five attempts without progress. Then say what you changed, what each attempt showed, and what's still failing.
40
+
41
+ A suite that passes on its first run hasn't found anything yet. Before calling it done, check the transcripts for workarounds (failed calls, extra lookups, guessed values), add harder tests for the weak spots you listed, and run again. If a weak spot still won't fail, say so rather than leaving it out.
23
42
 
24
43
  Agents vary, so results are rates. Explore with \`--trials 1\` and confirm with the default (3) before calling something fixed. Every run is real agent time; rerun only what you need.
25
44
 
@@ -32,7 +51,7 @@ Agents vary, so results are rates. Explore with \`--trials 1\` and confirm with
32
51
 
33
52
  ## Tests
34
53
 
35
- Tests are JSON files in \`${p.tests}/\`. Add one when the person describes behaviour no test covers:
54
+ Tests are JSON files in \`${p.tests}/\`. Add one for each weak spot (see above), and when the person describes behaviour no test covers:
36
55
 
37
56
  \`\`\`json
38
57
  {
@@ -64,4 +83,21 @@ Run one test with \`--journey <part of its slug or name>\`.
64
83
  Tests call the real server. If a tool changes real data (creates, sends, deletes), hide it in \`${p.store}/overrides.json\` with \`{ "tool_name": { "hidden": true } }\` unless the test is about that tool, and say so before running.
65
84
  `;
66
85
  }
86
+ /** Installed copies of the loop skill written by an older version (or before versions were stamped). */
87
+ export function outdatedSkills(project, version) {
88
+ const older = (a, b) => {
89
+ const [x, y] = [a, b].map((v) => v.split(/[.-]/).slice(0, 3).map(Number));
90
+ for (let i = 0; i < 3; i++)
91
+ if (x[i] !== y[i])
92
+ return (x[i] ?? 0) < (y[i] ?? 0);
93
+ return false;
94
+ };
95
+ return SKILL_DIRS.map((d) => join(d, 'SKILL.md')).filter((f) => {
96
+ const path = join(project, f);
97
+ if (!existsSync(path))
98
+ return false;
99
+ const stamp = /Written by mcp-dev-studio (\d+\.\d+\.\d+)/.exec(readFileSync(path, 'utf8'))?.[1];
100
+ return !stamp || older(stamp, version);
101
+ });
102
+ }
67
103
  //# sourceMappingURL=loop-skill.js.map
@@ -79,18 +79,23 @@ export function newSessionId() {
79
79
  export class FlagTracker {
80
80
  seen = new Map();
81
81
  lastErr = new Map();
82
- streak = { name: '', n: 0 };
82
+ /** The same tool failing call after call. */
83
+ failing = { name: '', n: 0 };
83
84
  flags(name, args, isError, text, tokens) {
84
85
  const flags = [];
85
86
  const key = name + JSON.stringify(args);
86
- if (this.seen.has(key))
87
+ const times = (this.seen.get(key) ?? 0) + 1;
88
+ this.seen.set(key, times);
89
+ if (times > 1)
87
90
  flags.push('repeat');
88
- this.seen.set(key, (this.seen.get(key) ?? 0) + 1);
89
91
  if (this.lastErr.get(name) === true)
90
92
  flags.push('retry');
91
93
  this.lastErr.set(name, isError);
92
- this.streak = this.streak.name === name ? { name, n: this.streak.n + 1 } : { name, n: 1 };
93
- if (this.streak.n >= 3)
94
+ // Looping means stuck: the same call a third time, or a third failure in a row from
95
+ // one tool. Calling a tool again with new arguments (three to-dos, three customers)
96
+ // is normal work.
97
+ this.failing = !isError ? { name: '', n: 0 } : this.failing.name === name ? { name, n: this.failing.n + 1 } : { name, n: 1 };
98
+ if (times >= 3 || this.failing.n >= 3)
94
99
  flags.push('loop');
95
100
  if (tokens > 1500)
96
101
  flags.push('bloated');
package/dist/cli.js CHANGED
@@ -17,13 +17,14 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
17
17
  import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
18
18
  import { splitCommand } from './mcp/connection.js';
19
19
  import { createApp } from './server/app.js';
20
+ import { listenFrom } from './server/listen.js';
20
21
  import { runEvalCli } from './eval/cli.js';
21
22
  import { fileSink, httpSink, recordingPipe } from './analytics/recorder.js';
22
23
  import { DEMO_ENTRY, Workspace } from './workspace.js';
23
24
  import { autoPick, discover } from './discover.js';
24
25
  import { detectClaudeCode } from './hosts/claude-code.js';
25
26
  import { detectCodex } from './hosts/codex.js';
26
- import { loopSkill } from './agent/loop-skill.js';
27
+ import { SKILL_DIRS, loopSkill, outdatedSkills } from './agent/loop-skill.js';
27
28
  const here = dirname(fileURLToPath(import.meta.url));
28
29
  const pkg = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
29
30
  const HELP = `mcp-dev-studio ${pkg.version} — design, test and iterate on an Agent Surface (MCP + Skills)
@@ -39,8 +40,8 @@ Usage (run with npx @chapterdev/mcp-dev-studio …)
39
40
  mcp-dev-studio demo-server Run the demo server over stdio
40
41
 
41
42
  Options
42
- --skills <dir> SKILL.md folder to co-edit (default .mcp-dev-studio/skills)
43
- --store <dir> Data dir (default ./.mcp-dev-studio; demo uses .mcp-dev-studio/demo)
43
+ --skills <dir> SKILL.md folder to co-edit (default skills/, .claude/skills or .agents/skills)
44
+ --store <dir> Data dir (default ~/.mcp-dev-studio/projects/<repo>)
44
45
  --cwd <dir> Working directory for --stdio
45
46
  --header "K: V" HTTP header for --url (repeatable)
46
47
  --token-file <path> Read a bearer token for --url from a file (keeps it out of ps)
@@ -130,10 +131,10 @@ async function main() {
130
131
  if (command === 'skill' || command === 'setup') {
131
132
  // Inside the repo: relative. In the private store: ~/… so the path reads the same for everyone.
132
133
  const rel = (p) => (relative(project, p).startsWith('..') ? p.replace(homedir(), '~') : relative(project, p) || '.');
133
- const text = loopSkill({ store: rel(ws.store.root), skills: rel(ws.skills.dir), tests: rel(ws.store.testsDir), server: ws.store.savedServer()?.name ?? 'the MCP server' });
134
+ const text = loopSkill({ store: rel(ws.store.root), skills: rel(ws.skills.dir), tests: rel(ws.store.testsDir), server: ws.store.savedServer()?.name ?? 'the MCP server', version: pkg.version });
134
135
  if (values.print)
135
136
  return void process.stdout.write(text);
136
- for (const dir of ['.claude/skills/mcp-dev-studio', '.agents/skills/mcp-dev-studio']) {
137
+ for (const dir of SKILL_DIRS) {
137
138
  mkdirSync(join(project, dir), { recursive: true });
138
139
  writeFileSync(join(project, dir, 'SKILL.md'), text);
139
140
  console.log(` wrote ${dir}/SKILL.md`);
@@ -149,7 +150,7 @@ async function main() {
149
150
  return { choice: { target: explicit, save: command === 'serve' }, why: 'from the command line', found: 0 };
150
151
  const saved = ws.store.savedServer();
151
152
  if (saved)
152
- return { choice: saved, why: 'from .mcp-dev-studio/server.json', found: 0 };
153
+ return { choice: saved, why: 'the server you picked last time', found: 0 };
153
154
  const list = await discover(project);
154
155
  const pick = autoPick(list);
155
156
  return pick ? { choice: { name: pick.name, target: pick.target, start: pick.start, save: true }, why: `found in ${pick.from}`, found: list.length } : { why: '', found: list.length };
@@ -195,6 +196,10 @@ async function main() {
195
196
  await ws.close();
196
197
  process.exit(2);
197
198
  }
199
+ // Agents read this too, so an upgrade's better instructions reach them.
200
+ const stale = outdatedSkills(project, pkg.version);
201
+ if (stale.length)
202
+ console.error(`Note: the mcp-dev-studio skill in ${stale.join(' and ')} is from an older version. Run \`npx @chapterdev/mcp-dev-studio setup\` to update it.`);
198
203
  const code = await runEvalCli({ conn: ws.conn, store: ws.store, skills: ws.skills, filter: values.journey, json: values.json, trials: values.trials ? Number(values.trials) : undefined, failed: values.failed, note: values.note, hosts: values.host ? values.host.split(',').map((h) => h.trim()).filter(Boolean) : undefined });
199
204
  await ws.close();
200
205
  process.exit(code);
@@ -211,20 +216,12 @@ async function main() {
211
216
  return;
212
217
  }
213
218
  }
214
- let server;
215
- let port = first;
216
- for (; port < first + 20; port++) {
217
- const app = createApp({ workspace: ws, uiDir: join(here, 'ui'), version: pkg.version, ingestUrl: `http://127.0.0.1:${port}/api/ingest` });
218
- server = await new Promise((ok) => {
219
- const s = app.listen(port, '127.0.0.1', () => ok(s)).once('error', () => ok(undefined));
220
- });
221
- if (server)
222
- break;
223
- }
224
- if (!server) {
219
+ const started = await listenFrom((port) => createApp({ workspace: ws, uiDir: join(here, 'ui'), version: pkg.version, ingestUrl: `http://127.0.0.1:${port}/api/ingest` }), first);
220
+ if (!started) {
225
221
  console.error(`Ports ${first}–${first + 19} are all in use. Pass --port <n>.`);
226
222
  process.exit(2);
227
223
  }
224
+ const { server, port } = started;
228
225
  const url = `http://localhost:${port}`;
229
226
  const shutdown = async () => {
230
227
  server.close();
@@ -1,7 +1,8 @@
1
1
  // The studio's local HTTP API (+ the built UI). Bound to 127.0.0.1 only.
2
2
  import express from 'express';
3
- import { existsSync } from 'node:fs';
4
- import { join } from 'node:path';
3
+ import { execFileSync } from 'node:child_process';
4
+ import { existsSync, readdirSync } from 'node:fs';
5
+ import { join, relative } from 'node:path';
5
6
  import { autoPick, discover } from '../discover.js';
6
7
  import { watchStore } from '../store-watch.js';
7
8
  import { modelOptions } from '../hosts/models.js';
@@ -451,6 +452,35 @@ export function createApp({ workspace: ws, uiDir, version, ingestUrl, sessionFac
451
452
  res.end();
452
453
  }));
453
454
  // Tests are private by default; sharing moves them into the repo so teammates get them.
455
+ // What sharing would do, for the confirm dialog: which files, and what git will make of them.
456
+ app.get('/api/tests/share', (_req, res) => {
457
+ const git = (...args) => {
458
+ try {
459
+ return { ok: true, out: execFileSync('git', args, { cwd: ws.project, stdio: ['ignore', 'pipe', 'ignore'] }).toString() };
460
+ }
461
+ catch {
462
+ return { ok: false, out: '' };
463
+ }
464
+ };
465
+ const dir = ws.sharedTestsDir;
466
+ const inRepo = git('rev-parse', '--is-inside-work-tree').ok;
467
+ let files = [];
468
+ try {
469
+ files = readdirSync(store.testsDir).filter((f) => f.endsWith('.json')).sort();
470
+ }
471
+ catch {
472
+ /* no tests yet */
473
+ }
474
+ res.json({
475
+ shared: store.testsShared,
476
+ dir: relative(ws.project, dir),
477
+ files,
478
+ inRepo,
479
+ // check-ignore exits 0 when the path is ignored.
480
+ ignored: inRepo && git('check-ignore', '-q', join(dir, 'x.json')).ok,
481
+ uncommitted: inRepo && store.testsShared && git('status', '--porcelain', '--', dir).out.trim().length > 0,
482
+ });
483
+ });
454
484
  app.post('/api/tests/share', (req, res) => {
455
485
  if (ws.demo)
456
486
  return void res.status(400).json({ error: 'The demo has no repo to share tests in' });
@@ -0,0 +1,12 @@
1
+ export async function listenFrom(make, first, tries = 20) {
2
+ for (let port = first; port < first + tries; port++) {
3
+ // Express 5 calls listen's callback on errors too (a busy port included), so check for one.
4
+ const server = await new Promise((ok) => {
5
+ const s = make(port).listen(port, '127.0.0.1', (err) => ok(err ? undefined : s));
6
+ });
7
+ if (server)
8
+ return { server, port };
9
+ }
10
+ return undefined;
11
+ }
12
+ //# sourceMappingURL=listen.js.map