diff --git a/.changeset/35036-mcp-door-tool-names.md b/.changeset/35036-mcp-door-tool-names.md new file mode 100644 index 00000000000..7488c40d04a --- /dev/null +++ b/.changeset/35036-mcp-door-tool-names.md @@ -0,0 +1,17 @@ +--- +'@objectstack/spec': patch +'@objectstack/lint': patch +--- + +fix(lint): `ai-skill-tool-unresolved` resolves every tool the MCP door registers for a skill offered over MCP, and says why when a skill kept out of MCP names one + +Clause-②: yes (widening) — `ai-skill-tool-unresolved` stops warning on eight tool names the MCP door registers, and `@objectstack/spec/system` gains the export `MCP_DOOR_TOOL_NAMES`; nothing that resolved before is reported +Metadata-protocol: none + +The MCP door in `@objectstack/mcp` registers record, file, action, federation and dataset tools, and offers a skill bound to them over MCP. The lint rule knew only the two file tools, so a skill bound to `aggregate_records`, `delete_record`, `delete_records`, `list_actions`, `run_action`, `resume_run`, `list_remote_tables` or `import_object` was warned that the agent cannot call it, and `os lint --strict` failed. + +`@objectstack/spec/system` now exports `MCP_DOOR_TOOL_NAMES`, every tool the door registers on a bridge carrying every optional member under a grant naming every scope. For a skill offered over MCP (`mcpPrompt` not `false`), the rule resolves every name in it. `@objectstack/mcp` has a test that keeps this list equal to what the door registers, so a tool added to or renamed at the door fails there until the list follows it. Some door names (`get_record`, `query_records`, `describe_object`, …) are cloud registrations as well and stay in `PLATFORM_PROVIDED_TOOL_NAMES`; the door's names do not join `PLATFORM_TOOLS_BY_PACKAGE`, so each group there stays the exact set one cloud package registers. `MCP_FILE_TOOL_NAMES` stays as it was and is part of the new list. + +A skill kept out of MCP (`mcpPrompt: false`) runs only in the in-product agents, which do not have the door tools no cloud package registers, so naming one there is still reported. The warning now says so: "Tool "run_action" resolves only for a skill offered over MCP, and this skill sets `mcpPrompt: false`, so the in-product agents it runs in have no such tool". The fix line offers dropping `mcpPrompt: false` or removing the name. A trailing-wildcard entry that matches only door tools gets the same verdict. + +`os explain ai-skill-tool-unresolved` names `MCP_DOOR_TOOL_NAMES` as the third source and adds that a skill which runs an app action binds `action_` (or `action_*`) rather than `run_action`: the MCP door serves that entry through `run_action`, and the in-product agents call the action tool itself. diff --git a/packages/lint/src/reference-integrity-suite.ts b/packages/lint/src/reference-integrity-suite.ts index 242b8060b6c..0454c139cb9 100644 --- a/packages/lint/src/reference-integrity-suite.ts +++ b/packages/lint/src/reference-integrity-suite.ts @@ -691,7 +691,7 @@ export const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [ // `collectToolUniverse` unions `PLATFORM_PROVIDED_TOOL_NAMES` ∪ // `stack.tools` ∪ the materialised action family from `stack.actions` and // every object's `actions`, and a skill offered over MCP (`mcpPrompt` not - // `false`) also resolves `MCP_FILE_TOOL_NAMES`, the door's file tools. A + // `false`) also resolves `MCP_DOOR_TOOL_NAMES`, the door's own tools. A // per-write snapshot carries `objects` — so an // object-level `action_` resolves — but NEITHER `tools` NOR `actions`, // and no snapshot can carry a tool a runtime plugin registers. So at this diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index cba378f810d..345427718f5 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -5559,10 +5559,11 @@ const AI_SKILL_TOOL_UNRESOLVED_EXPLANATION: RuleExplanation = { // The four sources and the wildcard are held to the rule by its test, each one silencing it. 'A `skill.tools` entry resolves, in order, against the stack\'s own `stack.tools` names; ' + '`PLATFORM_PROVIDED_TOOL_NAMES` (`@objectstack/spec/system`), the tools the cloud AI runtime ' + - 'registers at boot; `MCP_FILE_TOOL_NAMES` (same module), the file tools the MCP door registers ' + - '(`read_file`, `create_upload_link`), only for a skill offered over MCP: no cloud package ' + - 'registers either, so an in-product turn runs without them, and a skill kept out of MCP ' + - '(`mcpPrompt: false`) is still reported for naming them; and the materialised action tools, ' + + 'registers at boot; `MCP_DOOR_TOOL_NAMES` (same module), every tool the MCP door registers ' + + '(its record, file, action, federation and dataset tools), only for a skill offered over MCP: ' + + 'a door tool no cloud package registers, such as `run_action` or `read_file`, is absent from an ' + + 'in-product turn, so a skill kept out of MCP (`mcpPrompt: false`) is still reported for naming ' + + 'one, by a verdict that says the name resolves over MCP only; and the materialised action tools, ' + 'one `action_` per declarative action in `stack.actions` or any object\'s `actions` ' + '(ADR-0109: the default path declares no tool record at all). A trailing-wildcard entry ' + '(`action_*`, `crm_*`) resolves when any member of that universe starts with its prefix.', @@ -5580,7 +5581,9 @@ const AI_SKILL_TOOL_UNRESOLVED_EXPLANATION: RuleExplanation = { 'Family prefixes materialised by the runtime: action_. A materialised tool needs no tool record ' + '(the ADR-0109 default path), so backing a name means declaring the action, or referencing a ' + 'platform tool by its registered name; otherwise remove the name and the instructions that mention ' + - 'it. Ignore the warning only if a runtime plugin outside the platform registry provides the name.', + 'it. To run an app action, bind `action_` (or `action_*`) rather than `run_action`: the MCP ' + + 'door serves that entry through `run_action`, and the in-product agents call the action tool itself. ' + + 'Ignore the warning only if a runtime plugin outside the platform registry provides the name.', 'The runtime drops an unresolved name without a word, so the skill\'s instructions promise a ' + 'capability the agent cannot call, and the assistant improvises or fails when asked to use it. ' + 'A warning, not an error (ADR-0078\'s advisory-first ratchet): a runtime plugin outside the ' + diff --git a/packages/lint/src/validate-ai-tool-references.test.ts b/packages/lint/src/validate-ai-tool-references.test.ts index 264de9bef57..d6ad23ddfa5 100644 --- a/packages/lint/src/validate-ai-tool-references.test.ts +++ b/packages/lint/src/validate-ai-tool-references.test.ts @@ -5,7 +5,12 @@ import { validateAiToolReferences as validateAiToolReferencesUnrecorded, AI_SKILL_TOOL_UNRESOLVED, } from './validate-ai-tool-references.js'; -import { MCP_FILE_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES } from '@objectstack/spec/system'; +import { + MCP_DOOR_TOOL_NAMES, + MCP_FILE_TOOL_NAMES, + PLATFORM_PROVIDED_TOOL_NAMES, + PLATFORM_TOOL_FAMILY_PREFIXES, +} from '@objectstack/spec/system'; import { explainRule } from './rule-explanations.js'; // [#22161] Each finding is one verdict sentence; the reasoning it used to @@ -57,12 +62,12 @@ describe('validate-ai-tool-references', () => { ]); }); - it('checks the tools of a skill its owner keeps out of MCP (mcpPrompt: false) exactly as without the key, the MCP file tools aside (#34167)', () => { + it('checks the tools of a skill its owner keeps out of MCP (mcpPrompt: false) exactly as without the key, the MCP door tools aside (#34167)', () => { // The opt-out narrows MCP prompt projection: the binding is still the // in-product agent's tool set, and still checked in both distributions. - // Its one effect on this rule is the MCP file tools, which resolve only for - // a skill offered over MCP (the #34948 control below); this fixture names - // none of them. + // Its one effect on this rule is the MCP door's tools, which resolve only + // for a skill offered over MCP (the #34948 and #35036 controls below); this + // fixture names none the door alone serves. const stack = (mcpPrompt?: boolean) => ({ skills: [ { @@ -249,15 +254,17 @@ describe('validate-ai-tool-references', () => { * [#34948] The MCP door's file pair. `@objectstack/mcp` registers `read_file` * and `create_upload_link` and offers a skill bound to them over MCP, but no * cloud package registers either, so they are not in the cloud registry: the - * rule reads them from `MCP_FILE_TOOL_NAMES`. While it did not, a skill bound - * to the tools it uses failed `os lint --strict`. + * rule reads them from the door's list (`MCP_FILE_TOOL_NAMES`, now a part of + * `MCP_DOOR_TOOL_NAMES`). While it did not, a skill bound to the tools it + * uses failed `os lint --strict`. */ it('resolves the MCP door\'s file tools, read_file and create_upload_link (#34948)', () => { const two = ['read_file', 'create_upload_link']; expect(validateAiToolReferences({ skills: [{ name: 'receipts', tools: two }] })).toEqual([]); - // The list the rule reads is the one the door's conformance test holds - // equal to what it registers. + // The lists the door's conformance tests hold equal to what it registers: + // the file pair, inside the door's whole set, which the rule reads. expect([...MCP_FILE_TOOL_NAMES].sort()).toEqual([...two].sort()); + expect(MCP_DOOR_TOOL_NAMES).toEqual(expect.arrayContaining(two)); // The control: a third name shaped like the two and registered by nobody // is still reported, so this pin fails on a universe widened too far. @@ -283,6 +290,8 @@ describe('validate-ai-tool-references', () => { expect(findings).toHaveLength(1); expect(findings[0].path).toBe('skills[0].tools[0]'); expect(findings[0].message).toContain('"read_file"'); + // [#35036] The verdict says why: the name resolves over MCP only. + expect(findings[0].message).toContain('resolves only for a skill offered over MCP'); // The same skill with the key absent, or `true`, is offered over MCP and // resolves: the verdict follows `mcpPrompt` and nothing else. expect(validateAiToolReferences({ skills: [{ name: 'receipts', tools: ['read_file'] }] })).toEqual([]); @@ -291,6 +300,64 @@ describe('validate-ai-tool-references', () => { ).toEqual([]); }); + /** + * [#35036] Every other tool the MCP door registers. The door serves the + * record, action, federation and dataset tools as well as the file pair, and + * a skill offered over MCP is offered where they are listed, but the rule + * read only the file pair: a skill bound to `run_action` or + * `aggregate_records` failed `os lint --strict` for naming a served tool. + * The rule reads `MCP_DOOR_TOOL_NAMES`, which `@objectstack/mcp` holds equal + * to what the door registers. + */ + it('resolves every tool the MCP door registers for a skill offered over MCP (#35036)', () => { + const eight = [ + 'aggregate_records', 'delete_record', 'delete_records', 'list_actions', + 'run_action', 'resume_run', 'list_remote_tables', 'import_object', + ]; + // None of the eight is a cloud registration: each resolved from nowhere before. + for (const name of eight) expect(PLATFORM_PROVIDED_TOOL_NAMES.has(name), name).toBe(false); + expect(validateAiToolReferences({ skills: [{ name: 'ops', tools: eight }] })).toEqual([]); + expect(validateAiToolReferences({ skills: [{ name: 'ops', tools: [...MCP_DOOR_TOOL_NAMES] }] })).toEqual([]); + // A family the door alone serves resolves too. + expect(validateAiToolReferences({ skills: [{ name: 'ops', tools: ['resume_*'] }] })).toEqual([]); + + // The control: a name shaped like the door's and registered by nobody is + // still reported, so this pin fails on a universe widened too far. + const control = validateAiToolReferences({ skills: [{ name: 'ops', tools: [...eight, 'run_actions'] }] }); + expect(control).toHaveLength(1); + expect(control[0].path).toBe('skills[0].tools[8]'); + expect(control[0].message).toContain('"run_actions" resolves to no stack, platform or materialised action tool'); + }); + + /** + * [#35036] On a skill its owner keeps out of MCP (`mcpPrompt: false`), a + * name only the door serves is still reported, since the in-product agents + * the skill runs in have no such tool, and the verdict says the name + * resolves over MCP only instead of calling it fictional. A door name a + * cloud package registers too resolves there as before. + */ + it('reports a door-only name on a mcpPrompt: false skill with a verdict that says it resolves over MCP only (#35036)', () => { + const findings = validateAiToolReferences({ + skills: [{ + name: 'ops', + mcpPrompt: false, + tools: ['get_record', 'run_action', 'resume_*', 'nope_tool'], + }], + }); + expect(findings.map((f) => f.path)).toEqual(['skills[0].tools[1]', 'skills[0].tools[2]', 'skills[0].tools[3]']); + expect(findings[0].message).toBe( + 'Tool "run_action" resolves only for a skill offered over MCP, and this skill sets `mcpPrompt: false`, ' + + 'so the in-product agents it runs in have no such tool', + ); + expect(findings[0].hint).toBe( + 'Drop `mcpPrompt: false` if the skill is written for MCP clients, or remove "run_action" and the ' + + 'instructions that mention it', + ); + expect(findings[1].message).toMatch(/^Tool family "resume_\*" resolves only for a skill offered over MCP/); + // The control: a name nobody registers keeps the fictional-name verdict. + expect(findings[2].message).toContain('"nope_tool" resolves to no stack, platform or materialised action tool'); + }); + /** * The chat's confirmed record write (cloud#3565; it replaced cloud#3383's * `draft_record`): a skill naming `create_record` / `update_record` resolves; @@ -414,8 +481,10 @@ describe('[#22161] one-line verdicts — ai-skill-tool-unresolved', () => { for (const fact of [ '`stack.tools`', '`PLATFORM_PROVIDED_TOOL_NAMES`', - '`MCP_FILE_TOOL_NAMES`', + '`MCP_DOOR_TOOL_NAMES`', 'only for a skill offered over MCP', + 'by a verdict that says the name resolves over MCP only', + 'bind `action_` (or `action_*`) rather than `run_action`', '`mcpPrompt: false`', '`stack.actions` or any object\'s `actions`', 'trailing-wildcard', @@ -451,7 +520,8 @@ describe('[#22161] one-line verdicts — ai-skill-tool-unresolved', () => { it('every verdict the cases in this file fired is one line of at most 200 characters', () => { const converted = fired.filter((f) => f.rule === AI_SKILL_TOOL_UNRESOLVED); - // The coverage control first: all three arms fired. + // The coverage control first: all four arms fired. + expect(converted.some((f) => f.message.includes('resolves only for a skill offered over MCP'))).toBe(true); expect(converted.some((f) => f.message.startsWith('Tool family '))).toBe(true); expect(converted.some((f) => f.message.includes('does not become an AI tool'))).toBe(true); expect(converted.some((f) => f.message.includes('resolves to no stack, platform or materialised action tool'))).toBe(true); @@ -468,7 +538,8 @@ describe('[#22161] one-line verdicts — ai-skill-tool-unresolved', () => { describe('[#22161] one-line fixes — ai-skill-tool-unresolved', () => { it('every `fix:` line the cases in this file fired is one line of at most 200 characters', () => { const converted = fired.filter((f) => f.rule === AI_SKILL_TOOL_UNRESOLVED); - // Coverage control: the opt-in arm and the back-it arm both fired. + // Coverage control: the MCP-only, opt-in and back-it arms all fired. + expect(converted.some((f) => f.hint.startsWith('Drop `mcpPrompt: false`'))).toBe(true); expect(converted.some((f) => f.hint.startsWith('Opt "'))).toBe(true); expect(converted.some((f) => f.hint.startsWith('Back "'))).toBe(true); for (const f of converted) { diff --git a/packages/lint/src/validate-ai-tool-references.ts b/packages/lint/src/validate-ai-tool-references.ts index 41476446e1f..71261d4230a 100644 --- a/packages/lint/src/validate-ai-tool-references.ts +++ b/packages/lint/src/validate-ai-tool-references.ts @@ -13,14 +13,15 @@ * 2. `PLATFORM_PROVIDED_TOOL_NAMES` — the curated registry of tools the * cloud AI runtime registers at boot (spec owns the list; the owning * cloud packages carry the conformance tests) — and, only for a skill - * offered over MCP (`mcpPrompt` is not `false`), `MCP_FILE_TOOL_NAMES`: - * the file tools the MCP door registers (`read_file`, - * `create_upload_link`; `@objectstack/mcp` carries their conformance - * test), kept out of the cloud registry so each of its groups stays the - * exact set one cloud package registers. No cloud package registers - * either, so an in-product turn runs without them: a skill whose owner - * keeps it out of MCP (`mcpPrompt: false`) runs only there, and naming - * the pair in it is still reported; + * offered over MCP (`mcpPrompt` is not `false`), `MCP_DOOR_TOOL_NAMES`: + * every tool the MCP door registers (`@objectstack/mcp` carries the + * conformance test holding the list equal to `wireBridgeTools`), kept + * out of the cloud registry so each of its groups stays the exact set + * one cloud package registers. A door name no cloud package registers + * (`run_action`, `read_file`, `aggregate_records`, …) is absent from an + * in-product turn: a skill whose owner keeps it out of MCP + * (`mcpPrompt: false`) runs only there, so naming one in it is still + * reported, by a verdict that says the name resolves over MCP only; * 3. the materialised `action_` family — one tool per declarative * action (`stack.actions` ∪ every object's `actions`), the mechanism the * built-in `actions_executor` subscribes to with `action_*`. @@ -41,7 +42,7 @@ */ import { - MCP_FILE_TOOL_NAMES, + MCP_DOOR_TOOL_NAMES, PLATFORM_PROVIDED_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES, } from '@objectstack/spec/system'; @@ -152,7 +153,7 @@ function materialisesAsTool(action: AnyRec): boolean { /** * The set of tool names resolvable from this stack for EVERY skill: declared * tool records ∪ the platform registry ∪ the materialised action family. The - * MCP door's file tools join it per skill ({@link offeredOverMcp}). + * MCP door's tools join it per skill ({@link offeredOverMcp}). */ function collectToolUniverse(stack: AnyRec): Set { const universe = new Set(PLATFORM_PROVIDED_TOOL_NAMES); @@ -195,12 +196,13 @@ function collectUnexposedActionNames(stack: AnyRec): Set { } /** - * Can this skill be offered over MCP, where the door's file tools are served? + * Can this skill be offered over MCP, where the door's tools are served? * `mcpPrompt: false` keeps a skill off every MCP connection whatever its * binding (`SkillSchema.mcpPrompt`), so it runs only in the in-product agents, - * and no cloud AI package registers `read_file` or `create_upload_link` - * there. Seat ruling on the contract review of this rule's MCP widening: - * `mcpPrompt !== false` is the whole condition (no `instructions` test). + * which have none of the door's tools that no cloud AI package registers + * (`run_action`, `read_file`, …). Seat ruling on the contract review of this + * rule's MCP widening: `mcpPrompt !== false` is the whole condition (no + * `instructions` test). */ function offeredOverMcp(skill: AnyRec): boolean { return skill.mcpPrompt !== false; @@ -215,7 +217,7 @@ export function validateAiToolReferences(stack: AnyRec): AiToolRefFinding[] { if (!stack || typeof stack !== 'object') return findings; const shared = collectToolUniverse(stack); - const withMcpFileTools = new Set([...shared, ...MCP_FILE_TOOL_NAMES]); + const withMcpDoorTools = new Set([...shared, ...MCP_DOOR_TOOL_NAMES]); const unexposedActions = collectUnexposedActionNames(stack); const resolves = (ref: string, universe: ReadonlySet): boolean => { @@ -234,13 +236,18 @@ export function validateAiToolReferences(stack: AnyRec): AiToolRefFinding[] { const skill = skills[si]; const skillName = strName(skill.name) ?? `#${si}`; const refs = Array.isArray(skill.tools) ? skill.tools : []; - const universe = offeredOverMcp(skill) ? withMcpFileTools : shared; + const overMcp = offeredOverMcp(skill); + const universe = overMcp ? withMcpDoorTools : shared; for (let ti = 0; ti < refs.length; ti++) { const ref = strName(refs[ti]); if (!ref || resolves(ref, universe)) continue; const isPattern = ref.endsWith('*'); + // A name (or family) the MCP door serves, on a skill its owner keeps out + // of MCP: it would resolve for the same skill offered there, so the + // verdict says that instead of calling the name fictional. + const mcpOnly = !overMcp && resolves(ref, withMcpDoorTools); // The distinct, high-frequency case: the action EXISTS but never // materialises. "Fictional name" and "real action that isn't exposed" // need different fixes, so they get different messages. @@ -257,25 +264,31 @@ export function validateAiToolReferences(stack: AnyRec): AiToolRefFinding[] { // [#22161] One verdict sentence per arm, opening on the tool (`where` // names the skill); the resolution ladder, when an action materialises // as a tool and why it only warns are `os explain ai-skill-tool-unresolved`. - message: isPattern - ? `Tool family "${ref}" matches no tool this stack can resolve, so the subscription ` + - `contributes zero tools at runtime` - : unexposed - ? `Tool "${ref}" names action "${unexposed}", which does not become an AI tool (it needs ` + - `\`ai.exposed\` and a headless path), so the runtime drops the reference` - : `Tool "${ref}" resolves to no stack, platform or materialised action tool, so the ` + - `runtime drops it and the agent cannot call it.` + - suggest(ref, universe), + message: mcpOnly + ? `${isPattern ? 'Tool family' : 'Tool'} "${ref}" resolves only for a skill offered over MCP, and ` + + `this skill sets \`mcpPrompt: false\`, so the in-product agents it runs in have no such tool` + : isPattern + ? `Tool family "${ref}" matches no tool this stack can resolve, so the subscription ` + + `contributes zero tools at runtime` + : unexposed + ? `Tool "${ref}" names action "${unexposed}", which does not become an AI tool (it needs ` + + `\`ai.exposed\` and a headless path), so the runtime drops the reference` + : `Tool "${ref}" resolves to no stack, platform or materialised action tool, so the ` + + `runtime drops it and the agent cannot call it.` + + suggest(ref, universe), // [#22161] One remedy line per arm. That a UI-only action stays // human-driven by design, the ADR-0109 default path, the family // prefixes the runtime materialises (written out there and held to // `PLATFORM_TOOL_FAMILY_PREFIXES` by this rule's test) and the // runtime-plugin exception are `os explain ai-skill-tool-unresolved`. - hint: unexposed - ? `Opt "${unexposed}" in with \`ai: { exposed: true, description: '…' }\` and a headless type, or ` + - `drop the reference and have the instructions recommend the UI action` - : `Back "${ref}" with an opted-in action (\`ai.exposed: true\`, tool \`action_\`) or a ` + - `registered platform tool, or remove it and the instructions that mention it`, + hint: mcpOnly + ? `Drop \`mcpPrompt: false\` if the skill is written for MCP clients, or remove "${ref}" and ` + + `the instructions that mention it` + : unexposed + ? `Opt "${unexposed}" in with \`ai: { exposed: true, description: '…' }\` and a headless type, or ` + + `drop the reference and have the instructions recommend the UI action` + : `Back "${ref}" with an opted-in action (\`ai.exposed: true\`, tool \`action_\`) or a ` + + `registered platform tool, or remove it and the instructions that mention it`, }); } } diff --git a/packages/mcp/src/mcp-file-tools.test.ts b/packages/mcp/src/mcp-file-tools.test.ts index 81473d24cec..608ceda278b 100644 --- a/packages/mcp/src/mcp-file-tools.test.ts +++ b/packages/mcp/src/mcp-file-tools.test.ts @@ -20,11 +20,22 @@ import { createRequire } from 'node:module'; import { pathToFileURL } from 'node:url'; import { crc32, deflateRawSync } from 'node:zlib'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; -import { MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_DATA_WRITE } from '@objectstack/spec/ai'; -import { MCP_FILE_TOOL_NAMES } from '@objectstack/spec/system'; +import { + MCP_OAUTH_SCOPE_ACTIONS, + MCP_OAUTH_SCOPE_DATA_READ, + MCP_OAUTH_SCOPE_DATA_WRITE, + MCP_OAUTH_SCOPE_METADATA_WRITE, +} from '@objectstack/spec/ai'; +import { MCP_DOOR_TOOL_NAMES, MCP_FILE_TOOL_NAMES, PLATFORM_PROVIDED_TOOL_NAMES } from '@objectstack/spec/system'; import { validateAiToolReferences } from '@objectstack/lint'; import { MCPServerRuntime } from './mcp-server-runtime.js'; -import { registerFileTools, type McpDataBridge } from './mcp-http-tools.js'; +import { + registerFileTools, + wireBridgeTools, + type McpActionBridge, + type McpDataBridge, + type McpFederationBridge, +} from './mcp-http-tools.js'; import { READ_FILE_CPU_BUDGET_MS_DEFAULT, READ_FILE_CPU_BUDGET_MS_ENV, @@ -310,6 +321,71 @@ describe('the file tools the door registers are the ones a skill may bind', () = }); }); +/** + * [#35036] Every tool the door registers, and the names a skill may bind. The + * door serves its record, action, federation and dataset tools beside the file + * pair, and a skill offered over MCP is offered where they are listed, so + * `os lint` resolves every name in `MCP_DOOR_TOOL_NAMES` for such a skill. + * Held equal here to `wireBridgeTools`, the one composition both transports + * call, on a bridge carrying every optional member under a grant naming every + * scope: a tool added to or renamed at the door fails this case until the list + * follows it, and with it the lint rule. + */ +describe('the tools the door registers are the ones a skill offered over MCP may bind', () => { + const unused = async (): Promise => { + throw new Error('not called: this pin reads the registration only'); + }; + /** Every optional member the door wires a tool for, on top of the file members. */ + function everyMemberBridge(): McpDataBridge & McpActionBridge & McpFederationBridge & McpFileBridge { + return Object.assign(fullBridge(), { + aggregate: unused, + listActions: unused, + runAction: unused, + resumeRun: unused, + listRemoteTables: unused, + importObject: unused, + listDatasets: unused, + queryDataset: unused, + datasetToolDefinitions: () => [ + { name: 'list_datasets', description: 'List the datasets.' }, + { name: 'query_dataset', description: 'Query one metric of a dataset.' }, + ], + }); + } + const everyScope = [ + MCP_OAUTH_SCOPE_DATA_READ, + MCP_OAUTH_SCOPE_DATA_WRITE, + MCP_OAUTH_SCOPE_ACTIONS, + MCP_OAUTH_SCOPE_METADATA_WRITE, + ]; + const door = () => new McpServer({ name: 'door-tools', version: '0.0.0' }); + + it('wireBridgeTools registers exactly MCP_DOOR_TOOL_NAMES, and the lint rule resolves each', () => { + const registered = wireBridgeTools(door(), everyMemberBridge(), { grantedScopes: everyScope }); + expect([...registered].sort()).toEqual([...MCP_DOOR_TOOL_NAMES]); + expect(validateAiToolReferences({ skills: [{ name: 'ops', tools: registered }] })).toEqual([]); + // The control: a bridge with only the data members and a grant without + // the action and metadata scopes registers fewer, so the equality above is + // read from the registration sites, not assumed. + const fewer = wireBridgeTools(door(), makeBridge(null), { + grantedScopes: [MCP_OAUTH_SCOPE_DATA_READ, MCP_OAUTH_SCOPE_DATA_WRITE], + }); + expect(fewer.length).toBeGreaterThan(0); + expect(fewer.length).toBeLessThan(registered.length); + expect(fewer).not.toContain('run_action'); + expect(fewer).not.toContain('import_object'); + }); + + it('on a skill kept out of MCP, each name only the door serves is reported as resolving over MCP only', () => { + const registered = wireBridgeTools(door(), everyMemberBridge(), { grantedScopes: everyScope }); + const doorOnly = registered.filter((name) => !PLATFORM_PROVIDED_TOOL_NAMES.has(name)); + expect(doorOnly).toEqual(expect.arrayContaining(['run_action', 'read_file', 'aggregate_records'])); + const findings = validateAiToolReferences({ skills: [{ name: 'ops', mcpPrompt: false, tools: registered }] }); + expect(findings.map((f) => f.path)).toEqual(doorOnly.map((name) => `skills[0].tools[${registered.indexOf(name)}]`)); + for (const f of findings) expect(f.message, f.path).toContain('resolves only for a skill offered over MCP'); + }); +}); + describe('read_file', () => { let runtime: MCPServerRuntime; beforeEach(() => { diff --git a/packages/spec/api-surface/system.json b/packages/spec/api-surface/system.json index be3cbbeaa1b..00319c195af 100644 --- a/packages/spec/api-surface/system.json +++ b/packages/spec/api-surface/system.json @@ -347,6 +347,7 @@ "LoggingConfig (type)", "LoggingConfigParsed (type)", "LoggingConfigSchema (const)", + "MCP_DOOR_TOOL_NAMES (const)", "MCP_FILE_TOOL_NAMES (const)", "METADATA_FORM_REGISTRY (const)", "MIGRATION_JOURNAL_KINDS (const)", diff --git a/packages/spec/export-origins/system.json b/packages/spec/export-origins/system.json index a4d22ecc43a..d87a04c8117 100644 --- a/packages/spec/export-origins/system.json +++ b/packages/spec/export-origins/system.json @@ -334,6 +334,7 @@ "LoggingConfig": "src/system/logging.zod.ts#LoggingConfig (type)", "LoggingConfigParsed": "src/system/logging.zod.ts#LoggingConfigParsed (type)", "LoggingConfigSchema": "src/system/logging.zod.ts#LoggingConfigSchema (const)", + "MCP_DOOR_TOOL_NAMES": "src/system/constants/platform-tool-names.ts#MCP_DOOR_TOOL_NAMES (const)", "MCP_FILE_TOOL_NAMES": "src/system/constants/platform-tool-names.ts#MCP_FILE_TOOL_NAMES (const)", "METADATA_FORM_REGISTRY": "src/system/metadata-form-registry.ts#METADATA_FORM_REGISTRY (const)", "MIGRATION_JOURNAL_KINDS": "src/system/migration.zod.ts#MIGRATION_JOURNAL_KINDS (const)", diff --git a/packages/spec/src/ai/skill.zod.ts b/packages/spec/src/ai/skill.zod.ts index 83f10d50285..b6487b5cdfc 100644 --- a/packages/spec/src/ai/skill.zod.ts +++ b/packages/spec/src/ai/skill.zod.ts @@ -366,12 +366,12 @@ export const SkillSchema = lazySchema(() => strictObject({ * declares none (ADR-0109). A name here resolves against, in order: the * stack's own `stack.tools[]` names; `PLATFORM_PROVIDED_TOOL_NAMES`, the * curated registry of tools the cloud AI runtime registers at boot; - * `MCP_FILE_TOOL_NAMES`, the file tools the MCP door registers (`read_file`, - * `create_upload_link`), only when the skill is offered over MCP - * (`mcpPrompt` is not `false`), since an in-product turn runs without them; - * and the `action_` family the runtime materialises from the app's own - * AI-exposed declarative actions (`ai.exposed` + `ai.description` on a - * headless action type — ADR-0011). The first of those is the OPTIONAL + * `MCP_DOOR_TOOL_NAMES`, every tool the MCP door registers (`run_action`, + * `read_file`, `aggregate_records`, …), only when the skill is offered over + * MCP (`mcpPrompt` is not `false`), since an in-product turn runs without the + * door tools no cloud package registers; and the `action_` family the + * runtime materialises from the app's own AI-exposed declarative actions + * (`ai.exposed` + `ai.description` on a headless action type — ADR-0011). The first of those is the OPTIONAL * AI-presentation refinement layer (Phase 2: LLM-facing description, * parameter narrowing, flow exposure) and has no runtime reader until that * lands, so a `stack.tools` record authored today is inert. In the default @@ -450,8 +450,9 @@ export const SkillSchema = lazySchema(() => strictObject({ * in-product agent runtime resolves, binds and activates the skill exactly as * without it, and its `surface` is validated as before. One authoring verdict * reads it: with `false`, `ai-skill-tool-unresolved` resolves `tools` without - * the MCP door's file tools (`MCP_FILE_TOOL_NAMES`), since no in-product turn - * registers them; every other name is checked as before. + * the MCP door's tools (`MCP_DOOR_TOOL_NAMES`), since no in-product turn + * registers the ones no cloud package registers, and says so for a name only + * the door serves; every other name is checked as before. */ mcpPrompt: z.boolean().optional().describe( 'Whether this skill is offered as an MCP prompt. false = written for the in-product agents only: never listed by prompts/list and unknown to prompts/get on any MCP connection, whatever its tools binding. Absent or true = offered where the server serves its tools', diff --git a/packages/spec/src/system/constants/platform-tool-names.test.ts b/packages/spec/src/system/constants/platform-tool-names.test.ts index 47aa72bdaa5..3b06a3362ca 100644 --- a/packages/spec/src/system/constants/platform-tool-names.test.ts +++ b/packages/spec/src/system/constants/platform-tool-names.test.ts @@ -14,6 +14,7 @@ import { PLATFORM_TOOLS_BY_PACKAGE, PLATFORM_PROVIDED_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES, + MCP_DOOR_TOOL_NAMES, MCP_FILE_TOOL_NAMES, isPlatformProvidedToolName, } from './platform-tool-names'; @@ -95,3 +96,40 @@ describe('MCP_FILE_TOOL_NAMES — the MCP door\'s file tools, kept apart from th } }); }); + +describe('MCP_DOOR_TOOL_NAMES — every tool the MCP door registers, kept apart from the cloud registry', () => { + // Which names the door registers is pinned in `@objectstack/mcp` + // (`mcp-file-tools.test.ts`), and which the lint rule resolves in + // `@objectstack/lint`. What this file pins is the list's own shape and how + // it sits beside the cloud registry and the file pair. + it('is snake_case, sorted and duplicate-free', () => { + for (const name of MCP_DOOR_TOOL_NAMES) { + expect(name).toMatch(/^[a-z_][a-z0-9_]*$/); + } + expect([...MCP_DOOR_TOOL_NAMES].sort()).toEqual([...MCP_DOOR_TOOL_NAMES]); + expect(new Set(MCP_DOOR_TOOL_NAMES).size).toBe(MCP_DOOR_TOOL_NAMES.length); + }); + + it('holds the file pair and the dataset pair, and no name inside a materialised family', () => { + expect(MCP_DOOR_TOOL_NAMES).toEqual(expect.arrayContaining([...MCP_FILE_TOOL_NAMES])); + expect(MCP_DOOR_TOOL_NAMES).toEqual(expect.arrayContaining([LIST_DATASETS_TOOL_NAME, QUERY_DATASET_TOOL_NAME])); + for (const name of MCP_DOOR_TOOL_NAMES) { + for (const prefix of PLATFORM_TOOL_FAMILY_PREFIXES) { + expect(name.startsWith(prefix), name).toBe(false); + } + } + }); + + it('is not folded into the cloud registry: a name the door alone serves is not a cloud name', () => { + // Some door names are cloud registrations too (a cloud package registers + // the same name); the rest are the door's alone and stay out of every + // PLATFORM_TOOLS_BY_PACKAGE group, each the exact set one cloud package + // registers. + const shared = MCP_DOOR_TOOL_NAMES.filter((name) => isPlatformProvidedToolName(name)); + expect(shared).toEqual(expect.arrayContaining(['describe_object', 'get_record', 'query_records'])); + for (const doorOnly of ['run_action', 'delete_records', 'read_file']) { + expect(MCP_DOOR_TOOL_NAMES, doorOnly).toContain(doorOnly); + expect(isPlatformProvidedToolName(doorOnly), doorOnly).toBe(false); + } + }); +}); diff --git a/packages/spec/src/system/constants/platform-tool-names.ts b/packages/spec/src/system/constants/platform-tool-names.ts index fe20f9f4620..3bd14938fbf 100644 --- a/packages/spec/src/system/constants/platform-tool-names.ts +++ b/packages/spec/src/system/constants/platform-tool-names.ts @@ -36,8 +36,9 @@ * cloud registrations, so they never join {@link PLATFORM_TOOLS_BY_PACKAGE}: * a group there is the exact set one cloud package registers, and the MCP * bridge reads {@link PLATFORM_PROVIDED_TOOL_NAMES} to annotate the tools it - * bridges from the cloud runtime. The door's file pair has its own constant, - * {@link MCP_FILE_TOOL_NAMES}, which the `skill.tools[]` lint rule resolves + * bridges from the cloud runtime. The door's own tools have their own + * constant, {@link MCP_DOOR_TOOL_NAMES} (its file pair also + * {@link MCP_FILE_TOOL_NAMES}), which the `skill.tools[]` lint rule resolves * against beside this registry for a skill offered over MCP. */ @@ -130,15 +131,61 @@ export const PLATFORM_PROVIDED_TOOL_NAMES: ReadonlySet = new Set( Object.values(PLATFORM_TOOLS_BY_PACKAGE).flat(), ); +/** + * Every tool the MCP door registers (`wireBridgeTools` in `@objectstack/mcp`, + * the one composition its HTTP and stdio transports share), on a bridge + * carrying every optional member under a grant naming every scope: the + * record reads and writes (`delete_record` and `delete_records` delete only + * on a confirmed call), `aggregate_records`, the file pair + * ({@link MCP_FILE_TOOL_NAMES}), the action family (`list_actions`, + * `run_action`, `resume_run`), the federation pair (`list_remote_tables`, + * `import_object`, under `metadata:write` only), the dataset pair and + * `validate_expression`. + * + * Some names are also cloud registrations (`get_record`, `query_records`, + * `describe_object`, …) and are in {@link PLATFORM_PROVIDED_TOOL_NAMES} as + * well; the rest are served by the door alone. The `skill.tools[]` lint rule + * resolves every name here for a skill offered over MCP, since the door serves + * it there. A skill kept out of MCP (`mcpPrompt: false`) runs only in the + * in-product agents, so a name served by the door alone is still reported for + * it, and the finding says why. A skill that runs an app action binds + * `action_` rather than `run_action`: the door serves that entry through + * `run_action`, and the in-product agents call the action tool itself. + * + * Maintenance contract: this is the exact set `wireBridgeTools` registers on + * such a bridge. `@objectstack/mcp` carries the conformance test that holds + * the two equal, so a tool added to or renamed at the door fails there until + * this list follows it. + */ +export const MCP_DOOR_TOOL_NAMES: readonly string[] = [ + 'aggregate_records', + 'create_record', + 'create_upload_link', + 'delete_record', + 'delete_records', + 'describe_object', + 'get_record', + 'import_object', + 'list_actions', + 'list_datasets', + 'list_objects', + 'list_remote_tables', + 'query_dataset', + 'query_records', + 'read_file', + 'resume_run', + 'run_action', + 'update_record', + 'validate_expression', +]; + /** * The file tools the MCP door registers (`registerFileTools` in * `@objectstack/mcp`): `read_file` reads a file a record carries, and * `create_upload_link` mints a single-use link to upload a file onto a record. * No cloud AI package registers either, so neither is in - * {@link PLATFORM_PROVIDED_TOOL_NAMES}; a skill bound to them is served over - * MCP, and the `skill.tools[]` lint rule resolves both names from this list - * for a skill offered there. An in-product turn runs without them, so a skill - * kept out of MCP (`mcpPrompt: false`) naming either is still reported. + * {@link PLATFORM_PROVIDED_TOOL_NAMES}. Both are members of + * {@link MCP_DOOR_TOOL_NAMES}, the list the `skill.tools[]` lint rule reads. * * Maintenance contract: this is the exact set `registerFileTools` registers on * a bridge carrying every file member. `@objectstack/mcp` carries the