toolmenu 0.7.0
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/LICENSE +21 -0
- package/README.md +311 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +283 -0
- package/dist/compare.d.ts +32 -0
- package/dist/compare.js +108 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +27 -0
- package/dist/connect.d.ts +66 -0
- package/dist/connect.js +122 -0
- package/dist/diff.d.ts +58 -0
- package/dist/diff.js +404 -0
- package/dist/history.d.ts +88 -0
- package/dist/history.js +219 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/menu.d.ts +9 -0
- package/dist/menu.js +57 -0
- package/dist/report.d.ts +11 -0
- package/dist/report.js +278 -0
- package/dist/routes.d.ts +22 -0
- package/dist/routes.js +76 -0
- package/dist/rules/description.d.ts +28 -0
- package/dist/rules/description.js +158 -0
- package/dist/rules/determinism.d.ts +2 -0
- package/dist/rules/determinism.js +35 -0
- package/dist/rules/ids.d.ts +11 -0
- package/dist/rules/ids.js +138 -0
- package/dist/rules/index.d.ts +11 -0
- package/dist/rules/index.js +42 -0
- package/dist/rules/naming.d.ts +4 -0
- package/dist/rules/naming.js +145 -0
- package/dist/rules/rule.d.ts +33 -0
- package/dist/rules/rule.js +1 -0
- package/dist/rules/spec.d.ts +5 -0
- package/dist/rules/spec.js +102 -0
- package/dist/rules/write.d.ts +3 -0
- package/dist/rules/write.js +55 -0
- package/dist/semver.d.ts +11 -0
- package/dist/semver.js +41 -0
- package/dist/session.d.ts +90 -0
- package/dist/session.js +519 -0
- package/dist/snapshot.d.ts +16 -0
- package/dist/snapshot.js +42 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/words.d.ts +14 -0
- package/dist/words.js +63 -0
- package/package.json +57 -0
- package/schemas/2024-11-05.json +2077 -0
- package/schemas/2025-03-26.json +2139 -0
- package/schemas/2025-06-18.json +2517 -0
- package/schemas/2025-11-25.json +4058 -0
- package/schemas/2026-07-28.json +3963 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Era, Finding, Menu, MenuTool, Severity } from '../types.js';
|
|
2
|
+
import type { Routes } from '../routes.js';
|
|
3
|
+
export interface RuleContext {
|
|
4
|
+
menu: Menu;
|
|
5
|
+
/** The second `tools/list` from the same run, for the determinism check. */
|
|
6
|
+
secondList?: MenuTool[];
|
|
7
|
+
/** Raw `tools/list` result pages, as received. */
|
|
8
|
+
pages: Record<string, unknown>[];
|
|
9
|
+
/** Set when the official SDK client refused the tools/list result. */
|
|
10
|
+
clientError?: string;
|
|
11
|
+
protocolVersion?: string;
|
|
12
|
+
era?: Era;
|
|
13
|
+
capabilities: Record<string, unknown>;
|
|
14
|
+
usedAuth: boolean;
|
|
15
|
+
routes?: Routes;
|
|
16
|
+
/** Where clients are assumed to cut tool descriptions (description/buried). */
|
|
17
|
+
descriptionLimit?: number | string;
|
|
18
|
+
/** Tools (names or globs) the client sends uncut, so description/buried skips them. */
|
|
19
|
+
fullDescriptions?: string[];
|
|
20
|
+
}
|
|
21
|
+
export type RuleFinding = Omit<Finding, 'rule' | 'severity'> & {
|
|
22
|
+
severity?: Severity;
|
|
23
|
+
};
|
|
24
|
+
export interface Rule {
|
|
25
|
+
id: string;
|
|
26
|
+
severity: Severity;
|
|
27
|
+
/** The failure in "I built 100+ tools for one MCP server" this rule comes from. */
|
|
28
|
+
lesson?: string;
|
|
29
|
+
/** Spec version the rule applies from. Skipped for older servers. */
|
|
30
|
+
since?: string;
|
|
31
|
+
summary: string;
|
|
32
|
+
run(ctx: RuleContext): RuleFinding[];
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { Ajv } from 'ajv';
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
import addFormatsImport from 'ajv-formats';
|
|
6
|
+
// ajv-formats ships CommonJS; under NodeNext its default import is the module object.
|
|
7
|
+
const addFormats = (addFormatsImport.default ?? addFormatsImport);
|
|
8
|
+
const SCHEMA_DIR = fileURLToPath(new URL('../../schemas/', import.meta.url));
|
|
9
|
+
const validators = new Map();
|
|
10
|
+
function listToolsValidator(version) {
|
|
11
|
+
if (!validators.has(version)) {
|
|
12
|
+
const file = `${SCHEMA_DIR}${version}.json`;
|
|
13
|
+
if (!existsSync(file)) {
|
|
14
|
+
validators.set(version, null);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const schema = JSON.parse(readFileSync(file, 'utf8'));
|
|
18
|
+
// 2025-11-25 and later are draft 2020-12 with $defs; earlier ones are draft-07 with definitions.
|
|
19
|
+
const modernDraft = String(schema.$schema).includes('2020-12');
|
|
20
|
+
const ajv = modernDraft ? new Ajv2020({ strict: false, allErrors: true }) : new Ajv({ strict: false, allErrors: true });
|
|
21
|
+
addFormats(ajv);
|
|
22
|
+
ajv.addSchema(schema, 'mcp');
|
|
23
|
+
validators.set(version, ajv.compile({ $ref: `mcp#/${modernDraft ? '$defs' : 'definitions'}/ListToolsResult` }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return validators.get(version) ?? null;
|
|
27
|
+
}
|
|
28
|
+
export const schema = {
|
|
29
|
+
id: 'spec/schema',
|
|
30
|
+
severity: 'error',
|
|
31
|
+
summary: 'tools/list results match the official schema for their protocol version',
|
|
32
|
+
run(ctx) {
|
|
33
|
+
if (!ctx.protocolVersion)
|
|
34
|
+
return [];
|
|
35
|
+
const validate = listToolsValidator(ctx.protocolVersion);
|
|
36
|
+
if (!validate) {
|
|
37
|
+
return [{ severity: 'info', message: `No official schema bundled for protocol ${ctx.protocolVersion}; schema check skipped.` }];
|
|
38
|
+
}
|
|
39
|
+
const findings = [];
|
|
40
|
+
if (ctx.clientError && ctx.pages.every((page) => validate(page))) {
|
|
41
|
+
findings.push({ message: `The official MCP SDK client rejected the tools/list result: ${ctx.clientError.split('\n')[0]}` });
|
|
42
|
+
}
|
|
43
|
+
ctx.pages.forEach((page, i) => {
|
|
44
|
+
if (validate(page))
|
|
45
|
+
return;
|
|
46
|
+
const errors = validate.errors ?? [];
|
|
47
|
+
findings.push({
|
|
48
|
+
message: `tools/list result${ctx.pages.length > 1 ? ` (page ${i + 1})` : ''} doesn't match the ${ctx.protocolVersion} schema.`,
|
|
49
|
+
detail: (ctx.clientError ? ['The official MCP SDK client rejects this result, so real clients will fail to list tools.'] : []).concat(errors.slice(0, 5).map((e) => `${e.instancePath || '(result)'} ${e.message}${e.params && 'missingProperty' in e.params ? `: ${e.params.missingProperty}` : ''}`)
|
|
50
|
+
.concat(errors.length > 5 ? [`…and ${errors.length - 5} more`] : [])),
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return findings;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
export const discover = {
|
|
57
|
+
id: 'spec/discover',
|
|
58
|
+
severity: 'info',
|
|
59
|
+
summary: 'Reports when the server only speaks the 2025-era protocol',
|
|
60
|
+
run(ctx) {
|
|
61
|
+
if (ctx.era !== 'legacy')
|
|
62
|
+
return [];
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
message: `The server answered with protocol ${ctx.protocolVersion} and no working server/discover, so it isn't on 2026-07-28 yet. Rules for 2026-07-28 were skipped.`,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
export const deprecated = {
|
|
71
|
+
id: 'spec/deprecated',
|
|
72
|
+
severity: 'info',
|
|
73
|
+
since: '2026-07-28',
|
|
74
|
+
summary: 'Deprecated features still advertised',
|
|
75
|
+
run(ctx) {
|
|
76
|
+
if ('logging' in ctx.capabilities) {
|
|
77
|
+
return [{ message: 'Advertises the logging capability, which 2026-07-28 deprecates (SEP-2577). Log to stderr or use OpenTelemetry instead.' }];
|
|
78
|
+
}
|
|
79
|
+
return [];
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const cacheHints = {
|
|
83
|
+
id: 'spec/cache-hints',
|
|
84
|
+
severity: 'info',
|
|
85
|
+
since: '2026-07-28',
|
|
86
|
+
summary: 'Cache metadata recommendations (not correctness errors)',
|
|
87
|
+
run(ctx) {
|
|
88
|
+
const findings = [];
|
|
89
|
+
const meta = ctx.menu.listMeta ?? {};
|
|
90
|
+
if (meta.ttlMs === 0) {
|
|
91
|
+
findings.push({
|
|
92
|
+
message: 'tools/list has ttlMs: 0, so clients treat the list as immediately stale and may re-fetch it every time. Valid per spec (and the default in the official TypeScript SDK v2). If the tool set is stable, a positive ttlMs saves the polling.',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (meta.cacheScope === 'public' && ctx.usedAuth) {
|
|
96
|
+
findings.push({
|
|
97
|
+
message: 'tools/list is cacheScope "public" on a server that took credentials. Public means shared caches may serve it across authorization contexts. Fine only if the tool set never depends on the caller.',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return findings;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WRITE_VERBS, nouns, verbOf, words } from '../words.js';
|
|
2
|
+
const DRY_RUN_PARAMS = /^(dry[_-]?run|preview|validate[_-]?only|simulate|plan|what[_-]?if)$/i;
|
|
3
|
+
const PREVIEW_WORDS = new Set(['preview', 'validate', 'plan', 'simulate', 'dry']);
|
|
4
|
+
function isWriteByName(tool) {
|
|
5
|
+
return WRITE_VERBS.has(verbOf(tool.name) ?? '');
|
|
6
|
+
}
|
|
7
|
+
function hasAnnotations(tool) {
|
|
8
|
+
return !!tool.annotations && Object.keys(tool.annotations).length > 0;
|
|
9
|
+
}
|
|
10
|
+
export const unannotated = {
|
|
11
|
+
id: 'write/unannotated',
|
|
12
|
+
severity: 'warn',
|
|
13
|
+
lesson: '02',
|
|
14
|
+
summary: 'Tools that look like writes carry annotations',
|
|
15
|
+
run(ctx) {
|
|
16
|
+
return ctx.menu.tools
|
|
17
|
+
.filter((t) => isWriteByName(t) && !hasAnnotations(t))
|
|
18
|
+
.map((t) => ({
|
|
19
|
+
tool: t.name,
|
|
20
|
+
message: `${t.name}: the name suggests it changes something, but it has no annotations. Say readOnlyHint/destructiveHint so clients and agents know.`,
|
|
21
|
+
}));
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export const noDryRun = {
|
|
25
|
+
id: 'write/no-dry-run',
|
|
26
|
+
severity: 'info',
|
|
27
|
+
lesson: '02',
|
|
28
|
+
summary: 'Destructive tools offer a way to look before leaping',
|
|
29
|
+
run(ctx) {
|
|
30
|
+
const missing = [];
|
|
31
|
+
for (const tool of ctx.menu.tools) {
|
|
32
|
+
const a = tool.annotations ?? {};
|
|
33
|
+
const destructive = a.destructiveHint === true || (a.readOnlyHint === false && a.destructiveHint !== false);
|
|
34
|
+
if (!destructive)
|
|
35
|
+
continue;
|
|
36
|
+
const hasParam = Object.keys(tool.inputSchema?.properties ?? {}).some((p) => DRY_RUN_PARAMS.test(p));
|
|
37
|
+
const subject = new Set(nouns(tool.name));
|
|
38
|
+
const hasPreviewTool = ctx.menu.tools.some((other) => other.name !== tool.name &&
|
|
39
|
+
words(other.name).some((w) => PREVIEW_WORDS.has(w)) &&
|
|
40
|
+
nouns(other.name).some((n) => subject.has(n)));
|
|
41
|
+
if (!hasParam && !hasPreviewTool)
|
|
42
|
+
missing.push(tool.name);
|
|
43
|
+
}
|
|
44
|
+
if (missing.length === 0)
|
|
45
|
+
return [];
|
|
46
|
+
// One finding, not one per tool: it's a design note, not a list of defects.
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
...(missing.length === 1 ? { tool: missing[0] } : {}),
|
|
50
|
+
message: `${missing.length === 1 ? `${missing[0]} is` : `${missing.length} tools are`} destructive with no dry_run/preview parameter and no matching preview tool. Where the effect is costly to undo, a dry run lets the agent catch its own mistake while it's cheap.`,
|
|
51
|
+
...(missing.length > 1 ? { detail: [missing.join(', ')] } : {}),
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
},
|
|
55
|
+
};
|
package/dist/semver.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** One semver reading for diff and history, so they can't drift apart. */
|
|
2
|
+
export interface SemVer {
|
|
3
|
+
nums: [number, number, number];
|
|
4
|
+
/** Prerelease tag (1.0.0-rc.1 → "rc.1"). Build metadata (+…) is ignored. */
|
|
5
|
+
pre?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseSemver(version: string | undefined): SemVer | undefined;
|
|
8
|
+
/** Calendar versions (2026.8.31) promise nothing about compatibility. */
|
|
9
|
+
export declare function isCalendar(v: SemVer): boolean;
|
|
10
|
+
/** Semver precedence (prereleases before their release); unparseable versions sort first. */
|
|
11
|
+
export declare function compareVersions(a: string, b: string): number;
|
package/dist/semver.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function parseSemver(version) {
|
|
2
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?/.exec(version ?? '');
|
|
3
|
+
return m ? { nums: [Number(m[1]), Number(m[2]), Number(m[3])], ...(m[4] ? { pre: m[4] } : {}) } : undefined;
|
|
4
|
+
}
|
|
5
|
+
/** Calendar versions (2026.8.31) promise nothing about compatibility. */
|
|
6
|
+
export function isCalendar(v) {
|
|
7
|
+
return v.nums[0] >= 1000;
|
|
8
|
+
}
|
|
9
|
+
/** Semver precedence (prereleases before their release); unparseable versions sort first. */
|
|
10
|
+
export function compareVersions(a, b) {
|
|
11
|
+
const x = parseSemver(a);
|
|
12
|
+
const y = parseSemver(b);
|
|
13
|
+
if (!x || !y)
|
|
14
|
+
return x ? 1 : y ? -1 : 0;
|
|
15
|
+
for (let i = 0; i < 3; i++)
|
|
16
|
+
if (x.nums[i] !== y.nums[i])
|
|
17
|
+
return x.nums[i] - y.nums[i];
|
|
18
|
+
if (x.pre === y.pre)
|
|
19
|
+
return 0;
|
|
20
|
+
if (!x.pre)
|
|
21
|
+
return 1;
|
|
22
|
+
if (!y.pre)
|
|
23
|
+
return -1;
|
|
24
|
+
const xs = x.pre.split('.');
|
|
25
|
+
const ys = y.pre.split('.');
|
|
26
|
+
for (let i = 0; i < Math.max(xs.length, ys.length); i++) {
|
|
27
|
+
if (xs[i] === undefined)
|
|
28
|
+
return -1;
|
|
29
|
+
if (ys[i] === undefined)
|
|
30
|
+
return 1;
|
|
31
|
+
const xn = /^\d+$/.test(xs[i]);
|
|
32
|
+
const yn = /^\d+$/.test(ys[i]);
|
|
33
|
+
if (xn && yn && Number(xs[i]) !== Number(ys[i]))
|
|
34
|
+
return Number(xs[i]) - Number(ys[i]);
|
|
35
|
+
if (xn !== yn)
|
|
36
|
+
return xn ? -1 : 1;
|
|
37
|
+
if (xs[i] !== ys[i])
|
|
38
|
+
return xs[i] < ys[i] ? -1 : 1;
|
|
39
|
+
}
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type ToolChange } from './compare.js';
|
|
2
|
+
import { type Target } from './connect.js';
|
|
3
|
+
import type { Era, Finding, Menu, MenuTool, Severity } from './types.js';
|
|
4
|
+
export type Step = {
|
|
5
|
+
kind: 'list';
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'call';
|
|
8
|
+
tool: string;
|
|
9
|
+
args: Record<string, unknown>;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'wait_for';
|
|
12
|
+
event: 'tools_list_changed';
|
|
13
|
+
timeoutMs: number;
|
|
14
|
+
};
|
|
15
|
+
export interface Scenario {
|
|
16
|
+
allowWrites: boolean;
|
|
17
|
+
steps: Step[];
|
|
18
|
+
}
|
|
19
|
+
/** Read and check a scenario file. Mistakes are reported before anything runs. */
|
|
20
|
+
export declare function loadScenario(path: string): Promise<Scenario>;
|
|
21
|
+
export declare function parseScenario(data: unknown, where?: string): Scenario;
|
|
22
|
+
export declare function stepLabel(step: Step): string;
|
|
23
|
+
export type Scope = 'global' | 'connection-local' | 'per-process' | 'unclear';
|
|
24
|
+
export interface StepRecord {
|
|
25
|
+
index: number;
|
|
26
|
+
label: string;
|
|
27
|
+
status: 'ok' | 'refused' | 'failed' | 'timed-out';
|
|
28
|
+
/** Why no call was made, when none was: set where the status is set, never parsed from text. */
|
|
29
|
+
reason?: 'missing' | 'refused';
|
|
30
|
+
note?: string;
|
|
31
|
+
changed: boolean;
|
|
32
|
+
listChanged: number;
|
|
33
|
+
scope?: Scope;
|
|
34
|
+
tools: number;
|
|
35
|
+
tokens: number;
|
|
36
|
+
}
|
|
37
|
+
export interface SessionResult {
|
|
38
|
+
scenario: string;
|
|
39
|
+
server: Menu['server'];
|
|
40
|
+
transport: Target['kind'];
|
|
41
|
+
listening: boolean;
|
|
42
|
+
baseline: {
|
|
43
|
+
tools: number;
|
|
44
|
+
tokens: number;
|
|
45
|
+
};
|
|
46
|
+
final: {
|
|
47
|
+
tools: number;
|
|
48
|
+
tokens: number;
|
|
49
|
+
};
|
|
50
|
+
connectionCheck?: 'same' | 'different';
|
|
51
|
+
steps: StepRecord[];
|
|
52
|
+
findings: Finding[];
|
|
53
|
+
}
|
|
54
|
+
export interface SessionOptions {
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
/** How long to wait for a list_changed notification after a change. */
|
|
57
|
+
noticeGraceMs?: number;
|
|
58
|
+
rules?: Record<string, Severity | 'off'>;
|
|
59
|
+
ignore?: string[];
|
|
60
|
+
scenarioName?: string;
|
|
61
|
+
}
|
|
62
|
+
type Raw = Omit<Finding, 'severity'> & {
|
|
63
|
+
severity: Severity;
|
|
64
|
+
};
|
|
65
|
+
/** Observe the menu while a scripted session runs. No LLM: the scenario is the agent. */
|
|
66
|
+
export declare function session(target: Target, scenario: Scenario, options?: SessionOptions): Promise<SessionResult>;
|
|
67
|
+
/** Turn a menu change into findings, with the cost of each. */
|
|
68
|
+
export declare function changeFindings(before: MenuTool[], after: MenuTool[], changes: ToolChange[], step: number, origin?: string): Raw[];
|
|
69
|
+
/**
|
|
70
|
+
* Does a fresh connection see this step's changes? All of them: the server's tool
|
|
71
|
+
* set changed. None: the change belongs to this connection (or, on stdio, this
|
|
72
|
+
* process). Reorders alone can't tell, and a mix is unclear.
|
|
73
|
+
*/
|
|
74
|
+
export declare function scopeOf(changes: ToolChange[], next: MenuTool[], probe: MenuTool[], transport: Target['kind']): Scope;
|
|
75
|
+
export type { Era };
|
|
76
|
+
interface Unlocker {
|
|
77
|
+
tool: MenuTool;
|
|
78
|
+
score: number;
|
|
79
|
+
/** The parameter that names what to unlock, if there is one. */
|
|
80
|
+
param?: string;
|
|
81
|
+
/** Values to try for it, from the schema's enum. */
|
|
82
|
+
values: unknown[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* At most `max` characters, cut by code point at a word boundary, never inside a
|
|
86
|
+
* character. Drops U+FFFD left over from a server that cut its own message by bytes.
|
|
87
|
+
*/
|
|
88
|
+
export declare function clip(text: string, max: number): string;
|
|
89
|
+
export declare function unlockers(tools: MenuTool[]): Unlocker[];
|
|
90
|
+
export declare function starterScenario(menu: Menu): string;
|