From f65a10012da5cd7f09fbb3b6651cbcc463a6d66a Mon Sep 17 00:00:00 2001 From: Volodymyr Vreshch Date: Sun, 22 Nov 2026 18:25:16 +0100 Subject: [PATCH 1/2] feat(extension): serve tools as {id}_{name}, read both forms The kit names each tool {id}_{name}. The schemas, toolsAreOwn, the app host program and the widget bridge accept {id}_ and the old {id}__. Kit 0.23.0, apphost 0.5.0, widget 0.5.0. Claude-Session: https://claude.ai/code/session_01XQkodgygL4W8UcLQDwC212 --- docs/part-image.md | 2 +- docs/parts.md | 2 +- package-lock.json | 10 +-- .../fixtures/check/core/installation.json | 2 +- .../fixtures/check/platform/installation.json | 2 +- .../fixtures/check/root/installation.json | 2 +- .../fixtures/check/test/installation.json | 2 +- packages/apphost/package.json | 6 +- packages/apphost/src/daemon-c1.test.ts | 6 +- packages/apphost/src/daemon-cli-user.test.ts | 2 +- packages/apphost/src/daemon-seal.test.ts | 4 +- packages/apphost/src/host-document.test.ts | 15 ++++ packages/extension/README.md | 5 +- .../fixtures/bad-entries-exports/package.json | 4 +- .../fixtures/bad-manifest/package.json | 4 +- .../extension/fixtures/bad-stack/package.json | 4 +- .../fixtures/bad-store-kind/package.json | 4 +- packages/extension/fixtures/base/package.json | 4 +- packages/extension/package.json | 2 +- .../schemas/extension-discovery.schema.json | 2 +- .../schemas/extension-record.schema.json | 2 +- .../schemas/host-document.schema.json | 2 +- packages/extension/src/auth/part-mcp.test.ts | 6 +- .../extension/src/auth/token-guard.test.ts | 8 +- .../src/discovery/combine-answers.test.ts | 19 ++++- .../src/discovery/discovery.schema.ts | 7 +- .../extension/src/discovery/discovery.test.ts | 10 +-- .../src/discovery/host-document.test.ts | 6 +- packages/extension/src/host/host-auth.test.ts | 2 +- .../extension/src/host/host-discovery.test.ts | 2 +- .../src/host/host-migrations.test.ts | 2 +- .../extension/src/host/host-mounts.test.ts | 6 +- .../extension/src/host/host-parts.test.ts | 4 +- .../src/manifest/primitives.schema.ts | 8 +- .../extension/src/manifest/tool-name.test.ts | 74 +++++++++++++++++++ packages/extension/src/mcp/mcp-app.test.ts | 4 +- packages/extension/src/mcp/mcp-fields.test.ts | 24 +++--- packages/extension/src/mcp/mcp-rows.test.ts | 12 +-- packages/extension/src/mcp/mcp.test.ts | 10 +-- packages/extension/src/mcp/snapshot.test.ts | 4 +- .../extension/src/mcp/tool-errors.test.ts | 2 +- .../extension/src/mcp/tool-result.test.ts | 2 +- packages/extension/src/mcp/tools.ts | 6 +- packages/extension/src/runtime/part-mounts.ts | 2 +- .../src/runtime/part-runners.test.ts | 4 +- .../test-support/combine/combined.golden.json | 2 +- .../src/test-support/combine/probe.json | 2 +- .../extension/src/test-support/packages.ts | 4 +- .../src/test-support/part-fixture.ts | 2 +- .../extension/src/test-support/up-fixtures.ts | 2 +- .../src/testing/batch-a-helpers.test.ts | 2 +- packages/extension/src/testing/test-server.ts | 2 +- packages/extension/src/tool/check.test.ts | 8 +- .../extension/src/tool/record-extras.test.ts | 6 +- .../extension/src/tool/rules/surface.test.ts | 6 +- .../extension/src/tool/up/up-files.test.ts | 2 +- packages/logs/src/event.test.ts | 2 +- packages/logs/src/logger.test.ts | 8 +- packages/widget/README.md | 7 +- packages/widget/e2e/widget.spec.ts | 4 +- packages/widget/package.json | 2 +- packages/widget/src/bundle/bundle.test.ts | 2 +- packages/widget/src/host/bridge.test.ts | 14 ++-- packages/widget/src/host/bridge.ts | 11 ++- packages/widget/src/host/tool.test.ts | 34 ++++----- packages/widget/src/host/version.ts | 2 +- .../src/test-support/fixture/src/ui/echo.tsx | 2 +- .../src/test-support/fixture/src/ui/tools.ts | 4 +- template/CLAUDE.md | 2 +- template/README.md | 4 +- template/src/mcp/index.test.ts | 2 +- template/src/mcp/index.ts | 2 +- template/src/ui/echo.tsx | 2 +- template/template.mcpc.json | 2 +- 74 files changed, 290 insertions(+), 166 deletions(-) create mode 100644 packages/extension/src/manifest/tool-name.test.ts diff --git a/docs/part-image.md b/docs/part-image.md index 591c07ba..a75448ea 100644 --- a/docs/part-image.md +++ b/docs/part-image.md @@ -34,7 +34,7 @@ id with no valid answer is `down` and has no route. A part routes only when a co and the installation exposes it. An answer for an id that is not installed is refused, and so is a second pages route. The caller can set a row to `starting` or `failed`; with its last good document the entry keeps its `app` row and has no route. A document with an old `/api/v{N}` openapi is refused, and so is a tool that is not -`{id}__{name}` of its own id. An answer can carry `expectedId`, the id its container was listed for; +`{id}_{name}` of its own id. The old form `{id}__{name}` is still accepted for a time. An answer can carry `expectedId`, the id its container was listed for; an answer for another id is refused as `claims another id`. When some answer is listed for an id, an answer with no `expectedId` for that id is refused as `not listed for this id`. A bad answer never throws. Only an installation that gives an invalid host document (two rows of one id) throws. diff --git a/docs/parts.md b/docs/parts.md index 98ae1434..df93fed2 100644 --- a/docs/parts.md +++ b/docs/parts.md @@ -9,7 +9,7 @@ envelope is the kit's standard JSON answer shape: `{ success, data, meta? }` or export const create = (ctx: PartContext): Router => { /* ctx.store.query(...) */ }; -// src/mcp/index.ts: tools served as {id}__{name} on POST /mcp (SDK v2, stateless) +// src/mcp/index.ts: tools served as {id}_{name} on POST /mcp (SDK v2, stateless) export function create(ctx: McpContext) { ctx.tool( 'echo', diff --git a/package-lock.json b/package-lock.json index 4b3df14f..a59c0230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9601,7 +9601,7 @@ }, "packages/apphost": { "name": "@agentage/apphost", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "dependencies": { "@agentage/shell-dashboard": "0.4.0", @@ -9614,18 +9614,18 @@ "agentage-apphost-cloud": "dist/cloud-main.js" }, "devDependencies": { - "@agentage/extension": "~0.22.0" + "@agentage/extension": "~0.23.0" }, "engines": { "node": ">=22" }, "peerDependencies": { - "@agentage/extension": "~0.22.0" + "@agentage/extension": "~0.23.0" } }, "packages/extension": { "name": "@agentage/extension", - "version": "0.22.0", + "version": "0.23.0", "license": "MIT", "dependencies": { "@modelcontextprotocol/server": "^2.4.0", @@ -9729,7 +9729,7 @@ }, "packages/widget": { "name": "@agentage/widget", - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "dependencies": { "@agentage/design-system": "^0.20.1", diff --git a/packages/apphost/fixtures/check/core/installation.json b/packages/apphost/fixtures/check/core/installation.json index 0401faed..9f5ef463 100644 --- a/packages/apphost/fixtures/check/core/installation.json +++ b/packages/apphost/fixtures/check/core/installation.json @@ -1,6 +1,6 @@ { "host": "core", - "program": { "version": "0.4.0" }, + "program": { "version": "0.5.0" }, "extensions": [ { "id": "market", diff --git a/packages/apphost/fixtures/check/platform/installation.json b/packages/apphost/fixtures/check/platform/installation.json index b7546f5c..725f648c 100644 --- a/packages/apphost/fixtures/check/platform/installation.json +++ b/packages/apphost/fixtures/check/platform/installation.json @@ -1,6 +1,6 @@ { "host": "platform", - "program": { "version": "0.4.0" }, + "program": { "version": "0.5.0" }, "shell": { "package": "@agentage/shell-dashboard" }, "extensions": [ { diff --git a/packages/apphost/fixtures/check/root/installation.json b/packages/apphost/fixtures/check/root/installation.json index 07957a51..6f067396 100644 --- a/packages/apphost/fixtures/check/root/installation.json +++ b/packages/apphost/fixtures/check/root/installation.json @@ -1,6 +1,6 @@ { "host": "root", - "program": { "version": "0.4.0" }, + "program": { "version": "0.5.0" }, "core": "https://core.next.agentage.io", "extensions": [ { diff --git a/packages/apphost/fixtures/check/test/installation.json b/packages/apphost/fixtures/check/test/installation.json index 3e79947d..98a0630b 100644 --- a/packages/apphost/fixtures/check/test/installation.json +++ b/packages/apphost/fixtures/check/test/installation.json @@ -1,6 +1,6 @@ { "host": "test", - "program": { "version": "0.4.0" }, + "program": { "version": "0.5.0" }, "core": "https://core.next.agentage.io", "extensions": [ { diff --git a/packages/apphost/package.json b/packages/apphost/package.json index 708b4d66..f1649520 100644 --- a/packages/apphost/package.json +++ b/packages/apphost/package.json @@ -1,6 +1,6 @@ { "name": "@agentage/apphost", - "version": "0.4.0", + "version": "0.5.0", "description": "The agentage app host program: runs extensions through a runner and serves the combined discovery, the session and the shell", "type": "module", "license": "MIT", @@ -46,10 +46,10 @@ "zod": "^4.2.0" }, "peerDependencies": { - "@agentage/extension": "~0.22.0" + "@agentage/extension": "~0.23.0" }, "devDependencies": { - "@agentage/extension": "~0.22.0" + "@agentage/extension": "~0.23.0" }, "keywords": [ "agentage", diff --git a/packages/apphost/src/daemon-c1.test.ts b/packages/apphost/src/daemon-c1.test.ts index 34d81455..05047dc9 100644 --- a/packages/apphost/src/daemon-c1.test.ts +++ b/packages/apphost/src/daemon-c1.test.ts @@ -40,8 +40,8 @@ const rpc = (method: string, params?: object) => describe('the daemon routes of C1', () => { it('/mcp/{id} reaches the child: tools/list, tools/call; GET is 405 from the child', async () => { await allRunning(); - expect(await (await rpc('tools/list')).text()).toContain('"name":"all__echo"'); - const call = await rpc('tools/call', { name: 'all__echo', arguments: { msg: 'hi' } }); + expect(await (await rpc('tools/list')).text()).toContain('"name":"all_echo"'); + const call = await rpc('tools/call', { name: 'all_echo', arguments: { msg: 'hi' } }); expect(await call.text()).toContain('pong hi'); expect((await fetch(at('/mcp/all'))).status).toBe(405); }); @@ -74,7 +74,7 @@ describe('the daemon routes of C1', () => { commit: '0'.repeat(40), state: 'running', parts: PARTS, - tools: [{ name: 'all__echo', scope: 'all:read' }], + tools: [{ name: 'all_echo', scope: 'all:read' }], openapi: '/api/all/openapi.json', expose: { api: 'internal', mcp: 'internal' }, }, diff --git a/packages/apphost/src/daemon-cli-user.test.ts b/packages/apphost/src/daemon-cli-user.test.ts index f1a50ba7..677bf67e 100644 --- a/packages/apphost/src/daemon-cli-user.test.ts +++ b/packages/apphost/src/daemon-cli-user.test.ts @@ -66,7 +66,7 @@ const started = async (text?: string) => { const api = async () => ((await (await fetch(at('/api/who/me'))).json()) as { data: unknown }).data; const tool = async () => { - const params = { name: 'who__who', arguments: {} }; + const params = { name: 'who_who', arguments: {} }; const body = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params }); const text = await (await fetch(at('/mcp/who'), { method: 'POST', headers: MCP, body })).text(); const line = text.split('\n').find((l) => l.startsWith('data:')) ?? `data:${text}`; diff --git a/packages/apphost/src/daemon-seal.test.ts b/packages/apphost/src/daemon-seal.test.ts index ed16add2..94bda51f 100644 --- a/packages/apphost/src/daemon-seal.test.ts +++ b/packages/apphost/src/daemon-seal.test.ts @@ -26,7 +26,7 @@ const SPY_MANIFEST = { name: '@agentage/extension-spy', version: '0.1.0', type: 'module', - engines: { agentage: '^0.22' }, + engines: { agentage: '^0.23' }, agentage: { id: 'spy', parts: { api: true } }, }; @@ -80,7 +80,7 @@ describe.runIf(SEALED)('a sealed child (C2, Node at the floor)', () => { headers: MCP, body, }); - expect(await listed.text()).toContain('all__echo'); + expect(await listed.text()).toContain('all_echo'); await vi.waitFor( async () => { const ticks = (await h.call('GET', '/api/all/ticks')).body as { data: { total: number } }; diff --git a/packages/apphost/src/host-document.test.ts b/packages/apphost/src/host-document.test.ts index 6ead21c7..4c4e83d8 100644 --- a/packages/apphost/src/host-document.test.ts +++ b/packages/apphost/src/host-document.test.ts @@ -129,6 +129,21 @@ describe('hostDocumentOf: the host document from the discovery of each child (J. expect((await hostDocumentOf(entries, new Map())).extensions).toEqual([]); }); + it('tools in the new {id}_ and the old {id}__ form are listed; a foreign tool is down', async () => { + const withTool = (id: string, name: string) => + child(200, JSON.stringify({ ...docOf(id), tools: [{ name, scope: 'public' }] })); + const entries = entriesOf( + entryOf('a', 'running', await withTool('a', 'a_echo')), + entryOf('b', 'running', await withTool('b', 'b__echo')), + entryOf('c', 'running', await withTool('c', 'cc_echo')) + ); + const doc = await hostDocumentOf(entries, new Map()); + expect(doc.extensions.map((e) => [e.id, e.tools?.[0]?.name])).toEqual([ + ['a', 'a_echo'], + ['b', 'b__echo'], + ]); + }); + it('every row of an id: the pages row is in the document as it is in the routes', async () => { const api = await child(200, JSON.stringify(docOf('a'))); const pages = await child( diff --git a/packages/extension/README.md b/packages/extension/README.md index 55d589b1..434387dc 100644 --- a/packages/extension/README.md +++ b/packages/extension/README.md @@ -11,7 +11,7 @@ npm install @agentage/extension express zod ``` A part is one folder in `src/`. This MCP part, from the extension template, serves the tool -`{id}__echo` on `POST /mcp`: +`{id}_echo` on `POST /mcp`: ```ts import { type McpContext } from '@agentage/extension'; @@ -31,6 +31,9 @@ export function create(ctx: McpContext) { } ``` +Since 0.23.0 the kit names each tool `{id}_{name}`, with one underscore. Its schemas still accept +the old `{id}__{name}` for now, and refuse a tool of another id. + Start a new extension with `npx @agentage/cli extension create my-ext`: it pins this kit for you. - The subpaths, the core client, the check report and secrets: diff --git a/packages/extension/fixtures/bad-entries-exports/package.json b/packages/extension/fixtures/bad-entries-exports/package.json index 7912a8bb..3deb2df5 100644 --- a/packages/extension/fixtures/bad-entries-exports/package.json +++ b/packages/extension/fixtures/bad-entries-exports/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "engines": { - "agentage": "^0.22" + "agentage": "^0.23" }, "agentage": { "id": "base", @@ -13,7 +13,7 @@ } }, "dependencies": { - "@agentage/extension": "^0.22.0", + "@agentage/extension": "^0.23.0", "express": "^5.1.0", "zod": "^4.2.0" }, diff --git a/packages/extension/fixtures/bad-manifest/package.json b/packages/extension/fixtures/bad-manifest/package.json index 249870dc..d478ad6c 100644 --- a/packages/extension/fixtures/bad-manifest/package.json +++ b/packages/extension/fixtures/bad-manifest/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "engines": { - "agentage": "^0.22" + "agentage": "^0.23" }, "agentage": { "id": "Probe!", @@ -13,7 +13,7 @@ } }, "dependencies": { - "@agentage/extension": "^0.22.0", + "@agentage/extension": "^0.23.0", "express": "^5.1.0", "zod": "^4.2.0" } diff --git a/packages/extension/fixtures/bad-stack/package.json b/packages/extension/fixtures/bad-stack/package.json index 91aab4f9..17e45c60 100644 --- a/packages/extension/fixtures/bad-stack/package.json +++ b/packages/extension/fixtures/bad-stack/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "engines": { - "agentage": "^0.22" + "agentage": "^0.23" }, "agentage": { "id": "base", @@ -13,7 +13,7 @@ } }, "dependencies": { - "@agentage/extension": "^0.22.0", + "@agentage/extension": "^0.23.0", "express": "^4.19.0", "zod": "^4.2.0" } diff --git a/packages/extension/fixtures/bad-store-kind/package.json b/packages/extension/fixtures/bad-store-kind/package.json index efb2b059..0cdd19d6 100644 --- a/packages/extension/fixtures/bad-store-kind/package.json +++ b/packages/extension/fixtures/bad-store-kind/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "engines": { - "agentage": "^0.22" + "agentage": "^0.23" }, "agentage": { "id": "base", @@ -13,7 +13,7 @@ } }, "dependencies": { - "@agentage/extension": "^0.22.0", + "@agentage/extension": "^0.23.0", "express": "^5.1.0", "zod": "^4.2.0" } diff --git a/packages/extension/fixtures/base/package.json b/packages/extension/fixtures/base/package.json index 8feb6442..fd6cd7ce 100644 --- a/packages/extension/fixtures/base/package.json +++ b/packages/extension/fixtures/base/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "type": "module", "engines": { - "agentage": "^0.22" + "agentage": "^0.23" }, "agentage": { "id": "base", @@ -13,7 +13,7 @@ } }, "dependencies": { - "@agentage/extension": "^0.22.0", + "@agentage/extension": "^0.23.0", "express": "^5.1.0", "zod": "^4.2.0" } diff --git a/packages/extension/package.json b/packages/extension/package.json index c6fbc325..6c8a7990 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -1,6 +1,6 @@ { "name": "@agentage/extension", - "version": "0.22.0", + "version": "0.23.0", "description": "The agentage extension kit: create(ctx) per part (pages, ui, api, mcp, worker, cli), the store, /health, discovery, the envelope, and the build tool with up and token", "type": "module", "license": "MIT", diff --git a/packages/extension/schemas/extension-discovery.schema.json b/packages/extension/schemas/extension-discovery.schema.json index 06412598..01c80b89 100644 --- a/packages/extension/schemas/extension-discovery.schema.json +++ b/packages/extension/schemas/extension-discovery.schema.json @@ -186,7 +186,7 @@ "name": { "type": "string", "maxLength": 64, - "pattern": "^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$" + "pattern": "^[a-z][a-z0-9-]*__?[a-z][a-z0-9_-]*$" }, "scope": { "type": "string", diff --git a/packages/extension/schemas/extension-record.schema.json b/packages/extension/schemas/extension-record.schema.json index 373f3ed8..a74cdcfb 100644 --- a/packages/extension/schemas/extension-record.schema.json +++ b/packages/extension/schemas/extension-record.schema.json @@ -141,7 +141,7 @@ "name": { "type": "string", "maxLength": 64, - "pattern": "^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$" + "pattern": "^[a-z][a-z0-9-]*__?[a-z][a-z0-9_-]*$" }, "scope": { "type": "string", diff --git a/packages/extension/schemas/host-document.schema.json b/packages/extension/schemas/host-document.schema.json index c7dad1f0..3be282d9 100644 --- a/packages/extension/schemas/host-document.schema.json +++ b/packages/extension/schemas/host-document.schema.json @@ -94,7 +94,7 @@ "name": { "type": "string", "maxLength": 64, - "pattern": "^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$" + "pattern": "^[a-z][a-z0-9-]*__?[a-z][a-z0-9_-]*$" }, "scope": { "type": "string", diff --git a/packages/extension/src/auth/part-mcp.test.ts b/packages/extension/src/auth/part-mcp.test.ts index d5075767..cc2bb005 100644 --- a/packages/extension/src/auth/part-mcp.test.ts +++ b/packages/extension/src/auth/part-mcp.test.ts @@ -28,7 +28,7 @@ afterEach(async () => { const start = (settings?: string) => startPart(dir, 'mcp', { ...authEnv(issuer, dir), AGENTAGE_SETTINGS: settings }); -const CALL = { name: 'probe__echo', arguments: { msg: 'hi' } }; +const CALL = { name: 'probe_echo', arguments: { msg: 'hi' } }; const message = (id: number, method: string, params: object) => ({ jsonrpc: '2.0', id, @@ -85,7 +85,7 @@ describe('an mcp part checks tokens (C5, C7)', () => { it('a bad argument is a failed tool with the REST error shape', async () => { const url = await start(); const read = await issuer.bearer({ scope: 'probe:read' }); - const bad = await rpc(url, 'tools/call', { name: 'probe__echo', arguments: { msg: 5 } }, read); + const bad = await rpc(url, 'tools/call', { name: 'probe_echo', arguments: { msg: 5 } }, read); expect(bad.res.status).toBe(200); expect(bad.body['result']).toEqual({ isError: true, @@ -105,7 +105,7 @@ describe('an mcp part checks tokens (C5, C7)', () => { expect((await rpc(url, 'tools/list', {})).res.status).toBe(401); const read = await issuer.bearer({ scope: 'probe:read' }); const listed = await rpc(url, 'tools/list', {}, read); - expect(listed.body['result']?.['tools']).toMatchObject([{ name: 'probe__echo' }]); + expect(listed.body['result']?.['tools']).toMatchObject([{ name: 'probe_echo' }]); }); it('no key and the issuer down: tools/call is 503 with Retry-After 5', async () => { diff --git a/packages/extension/src/auth/token-guard.test.ts b/packages/extension/src/auth/token-guard.test.ts index 0f65ec62..da404ce9 100644 --- a/packages/extension/src/auth/token-guard.test.ts +++ b/packages/extension/src/auth/token-guard.test.ts @@ -131,8 +131,8 @@ describe('token check on mcp tools', () => { it('each tools/call asks for its tool scope, read when it declares none', async () => { const { asked, check } = recorder(); const s = await mcp(check); - expect((await rpc(s, 'tools/call', { name: 'probe__wipe', arguments: {} })).status).toBe(200); - await rpc(s, 'tools/call', { name: 'probe__echo', arguments: {} }); + expect((await rpc(s, 'tools/call', { name: 'probe_wipe', arguments: {} })).status).toBe(200); + await rpc(s, 'tools/call', { name: 'probe_echo', arguments: {} }); await rpc(s, 'tools/list'); expect(asked).toEqual([ ['Bearer aga_x', 'admin'], @@ -142,7 +142,7 @@ describe('token check on mcp tools', () => { it('a refused call is HTTP 403 or 503 with Retry-After, the envelope, never a tool result', async () => { const s = await mcp(recorder(() => fail('FORBIDDEN', 'insufficient_scope probe:admin')).check); - const res = await rpc(s, 'tools/call', { name: 'probe__wipe', arguments: {} }); + const res = await rpc(s, 'tools/call', { name: 'probe_wipe', arguments: {} }); expect(res.status).toBe(403); expect(await res.json()).toMatchObject({ success: false, @@ -150,7 +150,7 @@ describe('token check on mcp tools', () => { }); await served?.close(); const down = await mcp(recorder(() => fail('UNAVAILABLE', 'JWKS unreachable')).check); - const busy = await rpc(down, 'tools/call', { name: 'probe__echo', arguments: {} }); + const busy = await rpc(down, 'tools/call', { name: 'probe_echo', arguments: {} }); expect([busy.status, busy.headers.get('retry-after')]).toEqual([503, '30']); expect(await busy.json()).toMatchObject({ error: { code: 'UNAVAILABLE' } }); }); diff --git a/packages/extension/src/discovery/combine-answers.test.ts b/packages/extension/src/discovery/combine-answers.test.ts index 753e1901..180fa21e 100644 --- a/packages/extension/src/discovery/combine-answers.test.ts +++ b/packages/extension/src/discovery/combine-answers.test.ts @@ -4,10 +4,10 @@ import { entryRefusal } from './combine-answers.js'; import { combineHost } from './combine.js'; import { type DiscoveryDocument } from './discovery.schema.js'; -const TOOLS_ISSUE = 'tools: every tool is {id}__{name}'; +const TOOLS_ISSUE = 'tools: every tool is {id}_{name}'; const poison = (doc: Record) => ({ ...doc, - tools: [{ name: 'other__x', scope: 'public' }], + tools: [{ name: 'other_x', scope: 'public' }], }); describe('combineHost never throws on one bad answer', () => { @@ -23,6 +23,21 @@ describe('combineHost never throws on one bad answer', () => { expect(out.routes.map((r) => r.id)).toEqual(['fixture']); }); + it('takes one answer in the new form and one in the old form: both run', async () => { + const { probe, fixture, installation } = await setup(); + const tools = (name: string) => [{ name, scope: 'public' }]; + const answers = [ + at('probe', { ...probe, tools: tools('probe_echo') }), + at('fixture', { ...fixture, tools: tools('fixture__echo') }), + ]; + const out = combineHost({ kind: 'cloud', installation, answers }); + expect(out.refused).toEqual([]); + expect([entry(out, 'probe')?.state, entry(out, 'fixture')?.state]).toEqual([ + 'running', + 'running', + ]); + }); + it('refuses every answer when all are poisoned: each entry is down, no route', async () => { const { probe, fixture, installation } = await setup(); const answers = [at('probe', poison(probe)), at('fixture', poison(fixture))]; diff --git a/packages/extension/src/discovery/discovery.schema.ts b/packages/extension/src/discovery/discovery.schema.ts index 20fe152f..3c73b656 100644 --- a/packages/extension/src/discovery/discovery.schema.ts +++ b/packages/extension/src/discovery/discovery.schema.ts @@ -4,6 +4,7 @@ import { CommitSchema, ExtensionIdSchema, IMAGE_PART_KINDS, + ownsTool, PrefixedToolNameSchema, SecretNameSchema, SecretPartSchema, @@ -142,11 +143,11 @@ const OPENAPI_RULE = { message: 'openapi is /api/{id}/openapi.json', path: ['ope const openapiIsOwn = ({ id, openapi }: { id: string; openapi?: string }) => !openapi || openapi === `/api/${id}/openapi.json`; -// A served tool is {id}__{name} of this id: the host gives every tool under its extension. +// A served tool is {id}_{name} (or the old {id}__{name}) of this id: the host names it so. export const toolsAreOwn = ({ id, tools }: { id: string; tools?: { name: string }[] }) => - (tools ?? []).every((t) => t.name.startsWith(`${id}__`)); + (tools ?? []).every((t) => ownsTool(id, t.name)); -export const TOOLS_RULE = { message: 'every tool is {id}__{name}', path: ['tools'] }; +export const TOOLS_RULE = { message: 'every tool is {id}_{name}', path: ['tools'] }; // A scoped name lives only in secretParts, so an estate that does not read it mounts nothing. const scoped = (name: string) => diff --git a/packages/extension/src/discovery/discovery.test.ts b/packages/extension/src/discovery/discovery.test.ts index ef7390d4..2dfa39d1 100644 --- a/packages/extension/src/discovery/discovery.test.ts +++ b/packages/extension/src/discovery/discovery.test.ts @@ -174,12 +174,12 @@ describe('tools in the record (C8)', () => { it('are objects naming the scope tools/call needs, or public', () => { const record = recordOf(API_MANIFEST, BUILD, { api: API_IMAGE }); const valid = (tools: unknown) => ExtensionRecordSchema.safeParse({ ...record, tools }).success; - expect(valid([{ name: 'probe__echo', scope: 'probe:read' }])).toBe(true); - expect(valid([{ name: 'probe__time', scope: 'public' }])).toBe(true); + expect(valid([{ name: 'probe_echo', scope: 'probe:read' }])).toBe(true); + expect(valid([{ name: 'probe_time', scope: 'public' }])).toBe(true); for (const tools of [ - ['probe__echo'], - [{ name: 'probe__echo' }], - [{ name: 'probe__echo', scope: 'read' }], + ['probe_echo'], + [{ name: 'probe_echo' }], + [{ name: 'probe_echo', scope: 'read' }], ]) expect(valid(tools), JSON.stringify(tools)).toBe(false); }); diff --git a/packages/extension/src/discovery/host-document.test.ts b/packages/extension/src/discovery/host-document.test.ts index 1791480d..cb98d23f 100644 --- a/packages/extension/src/discovery/host-document.test.ts +++ b/packages/extension/src/discovery/host-document.test.ts @@ -47,16 +47,16 @@ describe('host document schema', () => { expect(bad({})).toBe(false); expect(bad({ parts: ['api', 'mcp'] })).toBe(true); expect(bad({ openapi: '/api/other/openapi.json' })).toBe(true); - expect(bad({ tools: [{ name: 'other__echo', scope: 'other:read' }] })).toBe(true); + expect(bad({ tools: [{ name: 'other_echo', scope: 'other:read' }] })).toBe(true); expect(bad({ state: 'gone' })).toBe(true); expect(bad({ expose: { app: 'internal' } })).toBe(true); }); it('takes its tool rule from the discovery document; the build record keeps what it takes', async () => { - const tools = [{ name: 'other__x', scope: 'public' }]; + const tools = [{ name: 'other_x', scope: 'public' }]; const probe = { ...(await read('probe.json')), tools }; expect(DiscoveryDocumentSchema.safeParse(probe).error?.issues[0]?.message).toBe( - 'every tool is {id}__{name}' + 'every tool is {id}_{name}' ); const served = new Set(['host', 'serves', 'app']); const record = Object.fromEntries(Object.entries(probe).filter(([key]) => !served.has(key))); diff --git a/packages/extension/src/host/host-auth.test.ts b/packages/extension/src/host/host-auth.test.ts index a349ce7b..1c30e429 100644 --- a/packages/extension/src/host/host-auth.test.ts +++ b/packages/extension/src/host/host-auth.test.ts @@ -19,7 +19,7 @@ afterEach(async () => { }); const MCP = { 'content-type': 'application/json', accept: 'application/json, text/event-stream' }; -const CALL = { name: 'all__echo', arguments: { msg: 'hi' } }; +const CALL = { name: 'all_echo', arguments: { msg: 'hi' } }; const call = (port: number, authorization: string) => fetch(`http://127.0.0.1:${port}/mcp/all`, { diff --git a/packages/extension/src/host/host-discovery.test.ts b/packages/extension/src/host/host-discovery.test.ts index d762aefb..2ef9193c 100644 --- a/packages/extension/src/host/host-discovery.test.ts +++ b/packages/extension/src/host/host-discovery.test.ts @@ -42,7 +42,7 @@ describe('the kit host serves the full discovery record', () => { host, parts: { api: {}, mcp: {}, worker: {}, store: { kind: 'postgres', migrations: 1 } }, openapi: '/api/all/openapi.json', - tools: [{ name: 'all__echo', scope: 'all:read' }], + tools: [{ name: 'all_echo', scope: 'all:read' }], serves: ['api', 'mcp', 'worker'], }); expect(doc).not.toHaveProperty('app'); diff --git a/packages/extension/src/host/host-migrations.test.ts b/packages/extension/src/host/host-migrations.test.ts index 5d124435..2573afb8 100644 --- a/packages/extension/src/host/host-migrations.test.ts +++ b/packages/extension/src/host/host-migrations.test.ts @@ -39,7 +39,7 @@ describe('migrateHost', () => { 'package.json': json({ name: 'x', version: '1.0.0', - engines: { agentage: '^0.22' }, + engines: { agentage: '^0.23' }, agentage: { id: 'x', parts }, }), }); diff --git a/packages/extension/src/host/host-mounts.test.ts b/packages/extension/src/host/host-mounts.test.ts index e671a143..a6e9930d 100644 --- a/packages/extension/src/host/host-mounts.test.ts +++ b/packages/extension/src/host/host-mounts.test.ts @@ -71,9 +71,9 @@ describe('extra mounts with no token check (a daemon child)', () => { const server = await open(); const connector = await (await server.fetch('/connector/mem', rpc('tools/list'))).text(); expect(connector).toContain('"name":"search"'); - expect(connector).not.toContain('mem__echo'); + expect(connector).not.toContain('mem_echo'); const mcp = await (await server.fetch('/mcp/mem', rpc('tools/list'))).text(); - expect([mcp.includes('"name":"mem__echo"'), mcp.includes('search')]).toEqual([true, false]); + expect([mcp.includes('"name":"mem_echo"'), mcp.includes('search')]).toEqual([true, false]); const call = rpc('tools/call', { name: 'search', arguments: { query: 'q' } }); expect(await (await server.fetch('/connector/mem', call)).text()).toContain('nobody'); const record = await (await server.fetch('/.well-known/agentage-extension.json')).text(); @@ -111,7 +111,7 @@ describe('extra mounts with a token check', () => { authorization_servers: [issuer!.url], }); } - const call = rpc('tools/call', { name: 'mem__echo', arguments: {} }); + const call = rpc('tools/call', { name: 'mem_echo', arguments: {} }); const refused = await at('/mcp/mem', call); const metadata = `Bearer resource_metadata="${ORIGIN}/.well-known/oauth-protected-resource/mcp/mem"`; expect([refused.status, refused.headers.get('www-authenticate')]).toEqual([401, metadata]); diff --git a/packages/extension/src/host/host-parts.test.ts b/packages/extension/src/host/host-parts.test.ts index ea870814..281a47ae 100644 --- a/packages/extension/src/host/host-parts.test.ts +++ b/packages/extension/src/host/host-parts.test.ts @@ -46,8 +46,8 @@ describe('one host process runs every server part', () => { const ticks = await (await server.fetch('/api/all/ticks')).json(); expect(ticks).toMatchObject({ data: { total: 0, part: 'api' } }); const list = await (await server.fetch('/mcp/all', rpc('tools/list'))).text(); - expect(list).toContain('"name":"all__echo"'); - const call = rpc('tools/call', { name: 'all__echo', arguments: { msg: 'hi' } }); + expect(list).toContain('"name":"all_echo"'); + const call = rpc('tools/call', { name: 'all_echo', arguments: { msg: 'hi' } }); expect(await (await server.fetch('/mcp/all', call)).text()).toContain('pong hi'); expect((await server.fetch('/mcp/all')).status).toBe(405); expect((await server.fetch('/mcp', rpc('tools/list'))).status).toBe(404); diff --git a/packages/extension/src/manifest/primitives.schema.ts b/packages/extension/src/manifest/primitives.schema.ts index 8c1b6cab..28cd76a5 100644 --- a/packages/extension/src/manifest/primitives.schema.ts +++ b/packages/extension/src/manifest/primitives.schema.ts @@ -74,10 +74,16 @@ export const FULL_SHA = /^[0-9a-f]{40}$/; export const CommitSchema = z.string().regex(FULL_SHA, { message: 'full 40-hex git sha' }); +// {id}_{name} or the old {id}__{name}: an id has no _ and a name starts with a letter. +const OWN_TOOL_REST = /^__?[a-z][a-z0-9_-]*$/; + export const PrefixedToolNameSchema = z .string() .max(64) - .regex(/^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$/); + .regex(/^[a-z][a-z0-9-]*__?[a-z][a-z0-9_-]*$/); + +export const ownsTool = (id: string, name: string): boolean => + name.startsWith(id) && OWN_TOOL_REST.test(name.slice(id.length)); export const IMAGE_PART_KINDS = ['pages', 'ui', 'api', 'mcp', 'worker'] as const; diff --git a/packages/extension/src/manifest/tool-name.test.ts b/packages/extension/src/manifest/tool-name.test.ts new file mode 100644 index 00000000..db49f5c8 --- /dev/null +++ b/packages/extension/src/manifest/tool-name.test.ts @@ -0,0 +1,74 @@ +import { describe, expect, it } from 'vitest'; +import { DiscoveryDocumentSchema, toolsAreOwn } from '../discovery/discovery.schema.js'; +import { createToolRegistry, prefixed } from '../mcp/tools.js'; +import { ExtensionIdSchema, ownsTool, PrefixedToolNameSchema } from './primitives.schema.js'; + +const name = (value: string) => PrefixedToolNameSchema.safeParse(value).success; + +describe('tool names: {id}_{name}, the old {id}__{name} still read', () => { + it('the kit serves {id}_{name}', () => { + expect([prefixed('probe', 'echo'), prefixed('a-b', 'list_all')]).toEqual([ + 'probe_echo', + 'a-b_list_all', + ]); + }); + + it('the name schema takes both forms and nothing else', () => { + expect(['probe_echo', 'probe__echo', 'a-b_x', 'a_list_all'].map(name)).toEqual([ + true, + true, + true, + true, + ]); + expect( + ['probe', 'probe___echo', 'probe_', '_echo', 'probe_Echo', 'probe_1x'].map(name) + ).toEqual([false, false, false, false, false, false]); + }); + + it('an id owns its tools in both forms, never a tool of a longer id', () => { + expect([ownsTool('probe', 'probe_echo'), ownsTool('probe', 'probe__echo')]).toEqual([ + true, + true, + ]); + const foreign = [ + 'probex_echo', + 'probex__echo', + 'probe___echo', + 'probe-x_echo', + 'probe', + 'a_echo', + ]; + expect(foreign.filter((tool) => ownsTool('probe', tool))).toEqual([]); + expect(ownsTool('a', 'a-b_x')).toBe(false); + expect(toolsAreOwn({ id: 'p', tools: [{ name: 'p_a' }, { name: 'p__b' }] })).toBe(true); + expect(toolsAreOwn({ id: 'p', tools: [{ name: 'p_a' }, { name: 'q_b' }] })).toBe(false); + }); + + it('the split is unambiguous: an id holds no _, a tool name starts with a letter', () => { + expect(ExtensionIdSchema.safeParse('a_b').success).toBe(false); + const { tool } = createToolRegistry(); + const spec = { description: 'x', input: {} as never }; + expect(() => tool('_x', spec, () => ({}))).toThrow('lowercase, digits, _ and -'); + }); + + it('a discovery document refuses a tool of another id in either form', async () => { + const doc = (tools: { name: string }[]) => + DiscoveryDocumentSchema.safeParse({ ...base, tools: tools.map(publicTool) }).success; + expect([ + doc([{ name: 'probe_a' }, { name: 'probe__b' }]), + doc([{ name: 'probex__a' }]), + ]).toEqual([true, false]); + }); +}); + +const publicTool = ({ name: n }: { name: string }) => ({ name: n, scope: 'public' }); + +const base = { + id: 'probe', + version: '1.0.0', + commit: 'a'.repeat(40), + buildTime: '2026-11-19T00:00:00Z', + host: 'http://127.0.0.1:1', + parts: { api: {} }, + serves: ['api'], +}; diff --git a/packages/extension/src/mcp/mcp-app.test.ts b/packages/extension/src/mcp/mcp-app.test.ts index f4b0638e..8a3513a0 100644 --- a/packages/extension/src/mcp/mcp-app.test.ts +++ b/packages/extension/src/mcp/mcp-app.test.ts @@ -22,7 +22,7 @@ const META = { }; const SCHEMA = 'https://json-schema.org/draft/2020-12/schema'; const ECHO = { - name: 'probe__echo', + name: 'probe_echo', description: 'Echo', inputSchema: { $schema: SCHEMA, type: 'object', properties: {} }, outputSchema: { $schema: SCHEMA, type: 'object', properties: {}, additionalProperties: false }, @@ -150,7 +150,7 @@ describe('a client that closes early', () => { const after: ErrorRequestHandler = (err, _req, _res, next) => (thrown.push(err), next()); const mcp = createMcpApp({ pkg: PKG, build: BUILD, log, tools, listing: 'open' }); served = await serveApp(mcp.use(after)); - const params = { name: 'probe__big', arguments: {} }; + const params = { name: 'probe_big', arguments: {} }; const body = JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params }); const abort = new AbortController(); const init = { method: 'POST', headers: HEADERS, body, signal: abort.signal }; diff --git a/packages/extension/src/mcp/mcp-fields.test.ts b/packages/extension/src/mcp/mcp-fields.test.ts index 7028b883..bbef302d 100644 --- a/packages/extension/src/mcp/mcp-fields.test.ts +++ b/packages/extension/src/mcp/mcp-fields.test.ts @@ -70,13 +70,13 @@ const toolNamed = async (url: string, name: string) => describe('mcp tool fields (G7)', () => { it('lists title and annotations as the production snapshot has them, no SDK defaults', async () => { - const write = await toolNamed(await start(), 'memory__write'); + const write = await toolNamed(await start(), 'memory_write'); expect(write?.['title']).toBe(WRITE_TITLE); expect(write?.['annotations']).toEqual(WRITE_ANNOTATIONS); }); it('lists a tool that sets neither field with no title, no annotations', async () => { - const plain = await toolNamed(await start(), 'memory__plain'); + const plain = await toolNamed(await start(), 'memory_plain'); expect(Object.keys(plain ?? {}).sort()).toEqual([ 'description', 'inputSchema', @@ -87,8 +87,8 @@ describe('mcp tool fields (G7)', () => { it('a tool with no output lists no outputSchema and answers text only', async () => { const url = await start(); - expect((await toolNamed(url, 'memory__text'))?.['outputSchema']).toBeUndefined(); - expect(await callTool(url, 'memory__text', {})).toBeUndefined(); + expect((await toolNamed(url, 'memory_text'))?.['outputSchema']).toBeUndefined(); + expect(await callTool(url, 'memory_text', {})).toBeUndefined(); }); }); @@ -102,14 +102,14 @@ describe('the caller in the tool handler', () => { jsonrpc: '2.0', id: 2, method: 'tools/call', - params: { name: 'memory__write', arguments: {} }, + params: { name: 'memory_write', arguments: {} }, }), }); expect((await dataOf(res)).result['structuredContent']).toEqual({ sub: 'u_alice' }); }); it('is null with no token check (a daemon child)', async () => { - expect(await callTool(await start(), 'memory__write', {})).toEqual({ sub: null }); + expect(await callTool(await start(), 'memory_write', {})).toEqual({ sub: null }); }); }); @@ -140,7 +140,7 @@ describe('the 2026-07-28 era', () => { it('a tools/call handler gets the caller; server/discover gets the per-caller instructions', async () => { const per = (caller: Caller | null) => `vaults of ${caller?.sub ?? 'nobody'}`; const url = await start(per, byBearer); - const call = await modern(url, 'tools/call', { name: 'memory__write', arguments: {} }, 'u_eve'); + const call = await modern(url, 'tools/call', { name: 'memory_write', arguments: {} }, 'u_eve'); expect(call['structuredContent']).toEqual({ sub: 'u_eve' }); const found = await modern(url, 'server/discover', {}, 'u_eve'); expect(JSON.stringify(found)).toContain('vaults of u_eve'); @@ -149,8 +149,8 @@ describe('the 2026-07-28 era', () => { describe('server instructions', () => { it('a text goes to initialize as it is', async () => { - expect(await initialize(await start('Use memory__write to save.'))).toBe( - 'Use memory__write to save.' + expect(await initialize(await start('Use memory_write to save.'))).toBe( + 'Use memory_write to save.' ); }); @@ -164,8 +164,8 @@ describe('server instructions', () => { it('a function runs only for the opening message, never for tools/list or tools/call', async () => { let runs = 0; const url = await start((caller) => `run ${++runs} for ${caller?.sub ?? 'nobody'}`, byBearer); - expect(await callTool(url, 'memory__write', {})).toEqual({ sub: null }); - expect(await callTool(url, 'memory__plain', {})).toEqual({ sub: null }); + expect(await callTool(url, 'memory_write', {})).toEqual({ sub: null }); + expect(await callTool(url, 'memory_plain', {})).toEqual({ sub: null }); const list = JSON.stringify({ jsonrpc: '2.0', id: 4, method: 'tools/list' }); expect((await fetch(url, { method: 'POST', headers: HEADERS, body: list })).status).toBe(200); expect(runs).toBe(0); @@ -176,7 +176,7 @@ describe('server instructions', () => { const url = await start(() => { throw new Error('store down'); }, byBearer); - expect(await callTool(url, 'memory__write', {})).toEqual({ sub: null }); + expect(await callTool(url, 'memory_write', {})).toEqual({ sub: null }); expect(await initialize(url, 'u_bob')).toBeUndefined(); }); diff --git a/packages/extension/src/mcp/mcp-rows.test.ts b/packages/extension/src/mcp/mcp-rows.test.ts index 94326fa7..892112c3 100644 --- a/packages/extension/src/mcp/mcp-rows.test.ts +++ b/packages/extension/src/mcp/mcp-rows.test.ts @@ -50,14 +50,14 @@ describe('mcp rows', () => { it('a tools/call is one mcp row with who and outcome, and no http row', async () => { const { post, lines } = await start(); for (const name of ['list', 'refuse', 'crash']) - await post('tools/call', { name: `probe__${name}`, arguments: {} }); + await post('tools/call', { name: `probe_${name}`, arguments: {} }); await settle(); const rows = lines.filter((line) => line['kind'] === 'mcp'); expect(lines.filter((line) => line['kind'] === 'http')).toEqual([]); expect(rows.map((r) => [r['gen_ai.tool.name'], r['level'], r['error.type']])).toEqual([ - ['probe__list', 'info', undefined], - ['probe__refuse', 'info', undefined], - ['probe__crash', 'error', 'RangeError'], + ['probe_list', 'info', undefined], + ['probe_refuse', 'info', undefined], + ['probe_crash', 'error', 'RangeError'], ]); expect(rows[0]).toMatchObject({ ...{ sub: 'usr_7f3a', session: 'tok_1', user_type: 'agent', client: 'claude-code' }, @@ -65,13 +65,13 @@ describe('mcp rows', () => { }); const errors = lines.filter((line) => line['kind'] === 'error'); expect(errors.map((e) => [e['msg'], e['agentage.where']])).toEqual([ - ['RangeError: secret', 'probe__crash'], + ['RangeError: secret', 'probe_crash'], ]); }); it('a tools/call to an unknown tool keeps its http row', async () => { const { post, lines } = await start(); - await post('tools/call', { name: 'probe__nope', arguments: {} }); + await post('tools/call', { name: 'probe_nope', arguments: {} }); await settle(); expect(lines.map((line) => [line['kind'], line['http.route']])).toEqual([['http', '/mcp']]); }); diff --git a/packages/extension/src/mcp/mcp.test.ts b/packages/extension/src/mcp/mcp.test.ts index 6846fa73..ac81f336 100644 --- a/packages/extension/src/mcp/mcp.test.ts +++ b/packages/extension/src/mcp/mcp.test.ts @@ -79,7 +79,7 @@ const call = async ( describe('mcp part', () => { it('answers tools/call with text and structured content', async () => { const { server: s } = await start(); - const result = await call(s, 'probe__echo', { msg: 'hi' }); + const result = await call(s, 'probe_echo', { msg: 'hi' }); expect(result['structuredContent']).toEqual({ msg: 'pong hi' }); expect(result['content']).toEqual([{ type: 'text', text: '{"msg":"pong hi"}' }]); expect(result['isError']).toBeUndefined(); @@ -87,7 +87,7 @@ describe('mcp part', () => { it('a failing tool is isError with the REST error code; a crash is a generic INTERNAL', async () => { const { server: s, ctx } = await start(); - const refused = await call(s, 'probe__refuse', {}); + const refused = await call(s, 'probe_refuse', {}); expect(refused['isError']).toBe(true); const error = { code: 'FORBIDDEN', @@ -96,7 +96,7 @@ describe('mcp part', () => { }; expect(refused['structuredContent']).toEqual({ error }); expect(refused['content']).toEqual([{ type: 'text', text: 'not for you' }]); - const crashed = await call(s, 'probe__crash', {}, '0ddd251eb290efb0df7f43b54c8a463b'); + const crashed = await call(s, 'probe_crash', {}, '0ddd251eb290efb0df7f43b54c8a463b'); expect(crashed['structuredContent']).toEqual({ error: { code: 'INTERNAL', @@ -117,7 +117,7 @@ describe('mcp part', () => { agcid: '8f095a1766c7b42b7c7d9b001e03eb7e', }; expect( - await call(s, 'probe__echo', args, '8f095a1766c7b42b7c7d9b001e03eb7e'), + await call(s, 'probe_echo', args, '8f095a1766c7b42b7c7d9b001e03eb7e'), JSON.stringify(args).slice(0, 20) ).toEqual({ isError: true, @@ -153,7 +153,7 @@ describe('mcp part', () => { jsonrpc: '2.0', id: 1, method: 'tools/call', - params: { name: 'probe__refuse', arguments: {} }, + params: { name: 'probe_refuse', arguments: {} }, }; const res = await handler.fetch( new Request('http://mcp/mcp', { diff --git a/packages/extension/src/mcp/snapshot.test.ts b/packages/extension/src/mcp/snapshot.test.ts index fc2c7f36..1acdcefa 100644 --- a/packages/extension/src/mcp/snapshot.test.ts +++ b/packages/extension/src/mcp/snapshot.test.ts @@ -21,7 +21,7 @@ const SNAPSHOT = { required: ['msg'], type: 'object', }, - name: 'probe__echo', + name: 'probe_echo', outputSchema: { $schema: SCHEMA, additionalProperties: false, @@ -33,7 +33,7 @@ const SNAPSHOT = { { description: 'Lists nothing', inputSchema: { $schema: SCHEMA, properties: {}, type: 'object' }, - name: 'probe__list', + name: 'probe_list', outputSchema: { $schema: SCHEMA, additionalProperties: false, diff --git a/packages/extension/src/mcp/tool-errors.test.ts b/packages/extension/src/mcp/tool-errors.test.ts index 5a2928d6..7d1e16a9 100644 --- a/packages/extension/src/mcp/tool-errors.test.ts +++ b/packages/extension/src/mcp/tool-errors.test.ts @@ -36,7 +36,7 @@ const call = async (name: string, args: object = {}) => { jsonrpc: '2.0', id: 4, method: 'tools/call', - params: { name: `memory__${name}`, arguments: args }, + params: { name: `memory_${name}`, arguments: args }, }), }); const text = await res.text(); diff --git a/packages/extension/src/mcp/tool-result.test.ts b/packages/extension/src/mcp/tool-result.test.ts index 8e8f067a..7b5130ba 100644 --- a/packages/extension/src/mcp/tool-result.test.ts +++ b/packages/extension/src/mcp/tool-result.test.ts @@ -46,7 +46,7 @@ const call = async (name: string) => { jsonrpc: '2.0', id: 3, method: 'tools/call', - params: { name: `memory__${name}`, arguments: {} }, + params: { name: `memory_${name}`, arguments: {} }, }), }); const text = await res.text(); diff --git a/packages/extension/src/mcp/tools.ts b/packages/extension/src/mcp/tools.ts index 4c4fe17f..8101fa87 100644 --- a/packages/extension/src/mcp/tools.ts +++ b/packages/extension/src/mcp/tools.ts @@ -69,7 +69,7 @@ export type ToolHandler = ( caller: Caller | null ) => Answer | Promise>; -// Registers a tool under its own name; the kit serves it as {id}__{name}. +// Registers a tool under its own name; the kit serves it as {id}_{name}. export type ToolRegistrar = ( name: string, spec: ToolSpec, @@ -119,8 +119,8 @@ export const createToolRegistry = () => { return { tool, tools, instructions, served, connector, connectors }; }; -export const prefixed = (id: string, name: string): string => `${id}__${name}`; +export const prefixed = (id: string, name: string): string => `${id}_${name}`; -// A connector tool keeps its own name (search, fetch); every other is {id}__{name}. +// A connector tool keeps its own name (search, fetch); every other is {id}_{name}. export const nameOf = (id: string, name: string, bare?: boolean): string => bare ? name : prefixed(id, name); diff --git a/packages/extension/src/runtime/part-mounts.ts b/packages/extension/src/runtime/part-mounts.ts index d1b327a1..ac7d4132 100644 --- a/packages/extension/src/runtime/part-mounts.ts +++ b/packages/extension/src/runtime/part-mounts.ts @@ -72,7 +72,7 @@ const mcp = async (input: RunnerInput): Promise => { const paths = input.mcpPaths; const options = { ...input.base, tools: registered, listing, paths, ...served }; const mount = (app: Express) => mountWithConnector(app, options, registry.connectors); - // Connector tools stay out of the record: the record lists the {id}__{name} tools only. + // Connector tools stay out of the record: the record lists the {id}_{name} tools only. const tools = toolRecords(input.pkg.agentage.id, registry.tools); return { mount, record: tools.length ? { tools } : {} }; }; diff --git a/packages/extension/src/runtime/part-runners.test.ts b/packages/extension/src/runtime/part-runners.test.ts index b4e5164b..6cd597bd 100644 --- a/packages/extension/src/runtime/part-runners.test.ts +++ b/packages/extension/src/runtime/part-runners.test.ts @@ -67,7 +67,7 @@ const start = async (part: string, env: Record = {}, at = dir): }; describe('runPart per part', () => { - it('mcp: imports dist/mcp/index.js and serves its tools as {id}__{name}', async () => { + it('mcp: imports dist/mcp/index.js and serves its tools as {id}_{name}', async () => { const url = await start('mcp'); const snapshot = await mcpSnapshot(`${url}/mcp`, '2025-11-25'); const $schema = 'https://json-schema.org/draft/2020-12/schema'; @@ -76,7 +76,7 @@ describe('runPart per part', () => { serverInfo: { name: 'agentage-probe', version: '0.2.0' }, tools: [ { - name: 'probe__echo', + name: 'probe_echo', description: 'Echo', inputSchema: { ...object, type: 'object' }, outputSchema: { ...object, type: 'object', additionalProperties: false }, diff --git a/packages/extension/src/test-support/combine/combined.golden.json b/packages/extension/src/test-support/combine/combined.golden.json index 50f5c71e..d88096dd 100644 --- a/packages/extension/src/test-support/combine/combined.golden.json +++ b/packages/extension/src/test-support/combine/combined.golden.json @@ -9,7 +9,7 @@ "version": "0.4.0", "commit": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "parts": ["api", "mcp", "worker", "app"], - "tools": [{ "name": "probe__echo", "scope": "probe:read" }], + "tools": [{ "name": "probe_echo", "scope": "probe:read" }], "openapi": "/api/probe/openapi.json", "app": { "title": "Probe", diff --git a/packages/extension/src/test-support/combine/probe.json b/packages/extension/src/test-support/combine/probe.json index 447b035c..83de9904 100644 --- a/packages/extension/src/test-support/combine/probe.json +++ b/packages/extension/src/test-support/combine/probe.json @@ -6,7 +6,7 @@ "host": "https://apps.example.com", "parts": { "api": {}, "mcp": {}, "worker": {} }, "openapi": "/api/probe/openapi.json", - "tools": [{ "name": "probe__echo", "scope": "probe:read" }], + "tools": [{ "name": "probe_echo", "scope": "probe:read" }], "serves": ["api", "mcp", "worker", "app"], "app": { "title": "Probe", diff --git a/packages/extension/src/test-support/packages.ts b/packages/extension/src/test-support/packages.ts index b0f909a1..4aa69cf8 100644 --- a/packages/extension/src/test-support/packages.ts +++ b/packages/extension/src/test-support/packages.ts @@ -7,7 +7,7 @@ import { type ExtensionPackage } from '../manifest/manifest.schema.js'; export const SPEC_MANIFEST = { name: '@agentage/extension-probe', version: '0.1.0', - engines: { agentage: '^0.22' }, + engines: { agentage: '^0.23' }, agentage: { id: 'probe', parts: { @@ -28,7 +28,7 @@ export const SPEC_MANIFEST = { export const API_MANIFEST: ExtensionPackage = { name: '@agentage/extension-probe', version: '0.1.0', - engines: { agentage: '^0.22.0' }, + engines: { agentage: '^0.23.0' }, agentage: { id: 'probe', parts: { api: true } }, }; diff --git a/packages/extension/src/test-support/part-fixture.ts b/packages/extension/src/test-support/part-fixture.ts index e19bef4e..0443563a 100644 --- a/packages/extension/src/test-support/part-fixture.ts +++ b/packages/extension/src/test-support/part-fixture.ts @@ -34,7 +34,7 @@ const RECORD = { commit: SHA, buildTime: '2026-11-06T09:00:00Z', parts: { api: image('api'), mcp: image('mcp') }, - tools: [{ name: 'probe__echo', scope: 'probe:read' }], + tools: [{ name: 'probe_echo', scope: 'probe:read' }], }; const FILES = { 'package.json': json(MANIFEST), diff --git a/packages/extension/src/test-support/up-fixtures.ts b/packages/extension/src/test-support/up-fixtures.ts index 58ae7def..706d13a0 100644 --- a/packages/extension/src/test-support/up-fixtures.ts +++ b/packages/extension/src/test-support/up-fixtures.ts @@ -45,7 +45,7 @@ const PROBE_FILES = { const SCHEMA = { $schema: 'https://json-schema.org/draft/2020-12/schema', type: 'object' }; const ECHO = { - name: 'probe__echo', + name: 'probe_echo', description: 'Echo', inputSchema: { ...SCHEMA, properties: {} }, outputSchema: { ...SCHEMA, properties: {}, additionalProperties: false }, diff --git a/packages/extension/src/testing/batch-a-helpers.test.ts b/packages/extension/src/testing/batch-a-helpers.test.ts index 4cfb1a0e..d4bb15df 100644 --- a/packages/extension/src/testing/batch-a-helpers.test.ts +++ b/packages/extension/src/testing/batch-a-helpers.test.ts @@ -45,7 +45,7 @@ describe('startTestMcp().call', () => { it('throws on a tool error', async () => { server = await startTestMcp({ create: echo }); - await expect(server.call('refuse')).rejects.toThrow(/^tool test__refuse: /); + await expect(server.call('refuse')).rejects.toThrow(/^tool test_refuse: /); }); }); diff --git a/packages/extension/src/testing/test-server.ts b/packages/extension/src/testing/test-server.ts index ff9640a5..ab2d17ad 100644 --- a/packages/extension/src/testing/test-server.ts +++ b/packages/extension/src/testing/test-server.ts @@ -81,7 +81,7 @@ export const startTestServer = async ( ); }; -// Runs an mcp part's create(ctx) inside the kit's real /mcp app: tools named {id}__{name}; connector tools at /connector. +// Runs an mcp part's create(ctx) inside the kit's real /mcp app: tools named {id}_{name}; connector tools at /connector. export const startTestMcp = async (options: TestMcpOptions): Promise => { const ctx = options.ctx ?? createTestContext(); const registry = createToolRegistry(); diff --git a/packages/extension/src/tool/check.test.ts b/packages/extension/src/tool/check.test.ts index 86e135f9..1b1ceaea 100644 --- a/packages/extension/src/tool/check.test.ts +++ b/packages/extension/src/tool/check.test.ts @@ -113,21 +113,21 @@ describe('problem paths', () => { }); describe('stack', () => { - const stackOf = async (dependencies: Record, agentage = '^0.22') => { + const stackOf = async (dependencies: Record, agentage = '^0.23') => { const pkg = { ...SPEC_MANIFEST, engines: { agentage }, dependencies }; const dir = await tempPackage({ 'package.json': json(pkg) }); return (await check(dir, only('stack'))).problems.map((p) => p.problem); }; it('needs express 5, zod 4, the MCP SDK 2 and a kit range inside engines.agentage', async () => { - const good = { express: '^5.1.0', zod: '^4.2.0', '@agentage/extension': '^0.22.0' }; + const good = { express: '^5.1.0', zod: '^4.2.0', '@agentage/extension': '^0.23.0' }; expect(await stackOf(good)).toEqual([]); const old = { express: '>=4', zod: '^3.23.0', '@modelcontextprotocol/server': '>=1' }; - expect(await stackOf({ ...old, '@agentage/extension': '^0.23.0' })).toEqual([ + expect(await stackOf({ ...old, '@agentage/extension': '^0.24.0' })).toEqual([ 'express >=4, needs ^5', 'zod ^3.23.0, needs ^4', '@modelcontextprotocol/server >=1, needs ^2', - '@agentage/extension ^0.23.0, needs ^0.22', + '@agentage/extension ^0.24.0, needs ^0.23', ]); }); diff --git a/packages/extension/src/tool/record-extras.test.ts b/packages/extension/src/tool/record-extras.test.ts index 1078cafa..63aa6654 100644 --- a/packages/extension/src/tool/record-extras.test.ts +++ b/packages/extension/src/tool/record-extras.test.ts @@ -10,9 +10,9 @@ const BUILD = { commit: SHA, buildTime: '2026-11-05T10:00:00Z' }; const WIDGETS = [{ name: 'echo', element: 'probe-echo', module: '/ui/0.1.0/probe.js' }]; // C8: each tool with the scope tools/call needs, read when it declares none. const TOOLS = [ - { name: 'probe__echo', scope: 'probe:read' }, - { name: 'probe__count', scope: 'probe:write' }, - { name: 'probe__time', scope: 'public' }, + { name: 'probe_echo', scope: 'probe:read' }, + { name: 'probe_count', scope: 'probe:write' }, + { name: 'probe_time', scope: 'public' }, ]; const MCP = `import { z } from 'zod'; diff --git a/packages/extension/src/tool/rules/surface.test.ts b/packages/extension/src/tool/rules/surface.test.ts index f6740c78..09905a4e 100644 --- a/packages/extension/src/tool/rules/surface.test.ts +++ b/packages/extension/src/tool/rules/surface.test.ts @@ -23,7 +23,7 @@ export const create = (ctx) => const SCHEMA = 'https://json-schema.org/draft/2020-12/schema'; const ECHO = { - name: 'probe__echo', + name: 'probe_echo', description: 'Echo', inputSchema: { $schema: SCHEMA, @@ -163,11 +163,11 @@ describe('surface, the mcp part', () => { it('names each tool that differs, and a missing snapshot', async () => { const stale = [ { ...ECHO, description: 'Old' }, - { ...ECHO, name: 'probe__gone' }, + { ...ECHO, name: 'probe_gone' }, ]; const files = { 'dist/mcp/index.js': MCP, 'probe.mcpc.json': snapshot(stale) }; expect(await surfaceOf(files, { mcp: true })).toEqual([ - 'probe.mcpc.json differs from the generated tool list (probe__echo, probe__gone)', + 'probe.mcpc.json differs from the generated tool list (probe_echo, probe_gone)', ]); expect(await surfaceOf({ 'dist/mcp/index.js': MCP }, { mcp: true })).toEqual([ 'probe.mcpc.json is missing: the mcp part commits its tool list', diff --git a/packages/extension/src/tool/up/up-files.test.ts b/packages/extension/src/tool/up/up-files.test.ts index b57370b0..cdb220fc 100644 --- a/packages/extension/src/tool/up/up-files.test.ts +++ b/packages/extension/src/tool/up/up-files.test.ts @@ -16,7 +16,7 @@ describe('up files', () => { const record = validateRecord(await read('record.json')); expect(record.parts.api).toEqual({ image: `ghcr.io/agentage/probe-api@${IMAGE_ID}` }); expect(record).toMatchObject({ - tools: [{ name: 'probe__echo', scope: 'probe:read' }], + tools: [{ name: 'probe_echo', scope: 'probe:read' }], commands: ['ping'], parts: { store: { migrations: 1 } }, }); diff --git a/packages/logs/src/event.test.ts b/packages/logs/src/event.test.ts index 9ae97c90..e13448e1 100644 --- a/packages/logs/src/event.test.ts +++ b/packages/logs/src/event.test.ts @@ -20,7 +20,7 @@ const SAMPLES: Record> = { }, mcp: { 'mcp.method.name': 'tools/call', - 'gen_ai.tool.name': 'probe__echo', + 'gen_ai.tool.name': 'probe_echo', 'agentage.results': 1, }, job: { diff --git a/packages/logs/src/logger.test.ts b/packages/logs/src/logger.test.ts index 48b32166..fa4e094c 100644 --- a/packages/logs/src/logger.test.ts +++ b/packages/logs/src/logger.test.ts @@ -60,9 +60,9 @@ describe('createLogger', () => { it('mcp, job, span and event rows, each with its level rule; no deferred fields', async () => { const { log, lines } = capture(); - log.mcp({ tool: 'probe__echo', ms: 9 }); - log.mcp({ tool: 'probe__find', ms: 6000 }); - log.mcp({ tool: 'probe__crash', ms: 2, error: new RangeError('x') }); + log.mcp({ tool: 'probe_echo', ms: 9 }); + log.mcp({ tool: 'probe_find', ms: 6000 }); + log.mcp({ tool: 'probe_crash', ms: 2, error: new RangeError('x') }); log.job({ name: 'retention', runId: 'r1', ms: 310 }); log.job({ name: 'retention', runId: 'r2', ms: 5, error: new Error('x') }); await log.span('store.query', () => 1); @@ -82,7 +82,7 @@ describe('createLogger', () => { ]); expect(lines[0]?.['fields']).toEqual({ 'mcp.method.name': 'tools/call', - 'gen_ai.tool.name': 'probe__echo', + 'gen_ai.tool.name': 'probe_echo', 'agentage.duration_ms': 9, }); expect(lines[2]?.['fields']).toMatchObject({ 'error.type': 'RangeError' }); diff --git a/packages/widget/README.md b/packages/widget/README.md index d263e11a..2170dcc7 100644 --- a/packages/widget/README.md +++ b/packages/widget/README.md @@ -11,7 +11,10 @@ npm install -D @agentage/widget npm install react react-dom ``` -This widget from the extension template calls the extension's MCP tool `{id}__echo`: +This widget from the extension template calls the extension's MCP tool `{id}_echo`: + +Since 0.5.0 a widget calls a tool of its own id in the form `{id}_{name}` or the old `{id}__{name}`. +A tool of another id is refused with `FOREIGN_TOOL`. ```tsx // src/ui/echo.tsx @@ -23,7 +26,7 @@ export function Echo() { const { tool, context } = useHost(); const [answer, setAnswer] = useState(''); const ping = () => - tool(`${context.extension}__echo`, { msg: 'hi' }).then( + tool(`${context.extension}_echo`, { msg: 'hi' }).then( ({ msg }) => String(msg), (error: Error) => error.message ); diff --git a/packages/widget/e2e/widget.spec.ts b/packages/widget/e2e/widget.spec.ts index 4b36cd98..32dece33 100644 --- a/packages/widget/e2e/widget.spec.ts +++ b/packages/widget/e2e/widget.spec.ts @@ -82,11 +82,11 @@ test('the harness speaks 2026-07-28 tools/call and keeps the token in the bridge authorization: 'Bearer aga_e2e', 'mcp-protocol-version': '2026-07-28', 'mcp-method': 'tools/call', - 'mcp-name': 'probe__echo', + 'mcp-name': 'probe_echo', }); expect(call?.body).toMatchObject({ method: 'tools/call', - params: { name: 'probe__echo', arguments: { msg: 'hi' } }, + params: { name: 'probe_echo', arguments: { msg: 'hi' } }, }); await expect(page).not.toHaveURL(/token=/); const reach = await page.evaluate(widgetReach); diff --git a/packages/widget/package.json b/packages/widget/package.json index 6755f6ae..059e62ae 100644 --- a/packages/widget/package.json +++ b/packages/widget/package.json @@ -1,6 +1,6 @@ { "name": "@agentage/widget", - "version": "0.4.0", + "version": "0.5.0", "description": "The agentage widget kit: useHost, design-system Button and Card in a shadow root, registerWidgets, and the ui bundler with its harness page", "type": "module", "license": "MIT", diff --git a/packages/widget/src/bundle/bundle.test.ts b/packages/widget/src/bundle/bundle.test.ts index 80c488b2..bbf87809 100644 --- a/packages/widget/src/bundle/bundle.test.ts +++ b/packages/widget/src/bundle/bundle.test.ts @@ -80,7 +80,7 @@ describe('bundle on the fixture extension', () => { window.document.body.append(el); (await vi.waitFor(() => shown(el, 'button'))).click(); await vi.waitFor(() => expect(shown(el, 'p').textContent).toBe('pong hi')); - expect(tool).toHaveBeenCalledWith('probe__echo', { msg: 'hi' }); + expect(tool).toHaveBeenCalledWith('probe_echo', { msg: 'hi' }); expect(el.shadowRoot?.adoptedStyleSheets).toHaveLength(1); expect(window.document.head.innerHTML).toBe(''); }); diff --git a/packages/widget/src/host/bridge.test.ts b/packages/widget/src/host/bridge.test.ts index c98b690e..9fb8e033 100644 --- a/packages/widget/src/host/bridge.test.ts +++ b/packages/widget/src/host/bridge.test.ts @@ -9,13 +9,15 @@ describe('createBridge', () => { it('reaches only its own tools and numbers its requests', async () => { const { fetch, calls } = fakeFetch(toolAnswer({ structuredContent: {} }), toolAnswer({})); const host = createBridge({ id: 'probe', version: '0.2.0', fetch }); - await host.tool('probe__echo'); + await host.tool('probe_echo'); await host.tool('probe__echo', { msg: 'x' }); - await expect(host.tool('memory__search')).rejects.toMatchObject({ + await expect(host.tool('memory_search')).rejects.toMatchObject({ code: 'FOREIGN_TOOL', - message: 'a probe widget calls only probe__ tools', + message: 'a probe widget calls only probe_ tools', }); - await expect(host.tool('probex__echo')).rejects.toMatchObject({ code: 'FOREIGN_TOOL' }); + await expect(host.tool('probex_echo')).rejects.toMatchObject({ code: 'FOREIGN_TOOL' }); + for (const name of ['probex__echo', 'probe___echo', 'probe-x_echo']) + await expect(host.tool(name), name).rejects.toMatchObject({ code: 'FOREIGN_TOOL' }); const bodies = calls.map((call) => JSON.parse(String(call.init.body))); expect(bodies.map((body) => body.id)).toEqual([1, 2]); expect(bodies[0].params.arguments).toEqual({}); @@ -51,7 +53,7 @@ describe('createBridge', () => { const host = createBridge({ id: 'probe', version: '0.2.0', fetch, token }); expect(Object.keys(host).sort()).toEqual(['api', 'context', 'tool']); expect(JSON.stringify(host)).not.toContain('aga_secret'); - await host.tool('probe__echo'); + await host.tool('probe_echo'); expect(new Headers(calls[0]?.init.headers).get('authorization')).toBe('Bearer aga_secret'); }); @@ -63,7 +65,7 @@ describe('createBridge', () => { fetch, props: { n: 1 }, }); - await host.tool('probe__echo'); + await host.tool('probe_echo'); await expect(host.api('/two')).resolves.toBe(2); expect(calls.map((call) => call.url)).toEqual([ 'https://probe.next.agentage.io/mcp', diff --git a/packages/widget/src/host/bridge.ts b/packages/widget/src/host/bridge.ts index edd88e42..b9752a3f 100644 --- a/packages/widget/src/host/bridge.ts +++ b/packages/widget/src/host/bridge.ts @@ -21,8 +21,13 @@ export interface BridgeOptions { fetch?: FetchLike; } -const foreign = (id: string) => - hostError('FOREIGN_TOOL', `a ${id} widget calls only ${id}__ tools`); +const foreign = (id: string) => hostError('FOREIGN_TOOL', `a ${id} widget calls only ${id}_ tools`); + +// The kit rule ownsTool, copied: the widget does not depend on the kit. +const OWN_TOOL_REST = /^__?[a-z][a-z0-9_-]*$/; + +const ownsTool = (id: string, name: string): boolean => + name.startsWith(id) && OWN_TOOL_REST.test(name.slice(id.length)); const anonymous: TokenSource = () => Promise.resolve(undefined); @@ -46,7 +51,7 @@ export const createBridge = (options: BridgeOptions): Host => { return { // The cast is the typed view an extension declares through ToolOutputs. tool: (name: N, args: Record = {}) => - (name.startsWith(`${options.id}__`) + (ownsTool(options.id, name) ? callTool(tool, name, args) : Promise.reject(foreign(options.id))) as Promise>, api: (path, init) => callApi(api, path, init), diff --git a/packages/widget/src/host/tool.test.ts b/packages/widget/src/host/tool.test.ts index 8e894b12..f39989e4 100644 --- a/packages/widget/src/host/tool.test.ts +++ b/packages/widget/src/host/tool.test.ts @@ -25,7 +25,7 @@ afterEach(() => vi.restoreAllMocks()); describe('callTool', () => { it('POSTs a 2026-07-28 tools/call and resolves the structuredContent', async () => { const { fetch, calls } = fakeFetch(toolAnswer(echo, 7)); - await expect(callTool(options(fetch), 'probe__echo', { msg: 'hi' })).resolves.toEqual({ + await expect(callTool(options(fetch), 'probe_echo', { msg: 'hi' })).resolves.toEqual({ msg: 'pong hi', }); const [call] = calls; @@ -37,14 +37,14 @@ describe('callTool', () => { accept: 'application/json, text/event-stream', 'mcp-protocol-version': PROTOCOL_VERSION, 'mcp-method': 'tools/call', - 'mcp-name': 'probe__echo', + 'mcp-name': 'probe_echo', }); expect(JSON.parse(String(call?.init.body))).toEqual({ jsonrpc: '2.0', id: 7, method: 'tools/call', params: { - name: 'probe__echo', + name: 'probe_echo', arguments: { msg: 'hi' }, _meta: { 'io.modelcontextprotocol/protocolVersion': '2026-07-28', @@ -57,8 +57,8 @@ describe('callTool', () => { it('sends the token as a bearer only when there is one', async () => { const { fetch, calls } = fakeFetch(toolAnswer(echo), toolAnswer(echo)); - await callTool(options(fetch, 'aga_x'), 'probe__echo', {}); - await callTool(options(fetch), 'probe__echo', {}); + await callTool(options(fetch, 'aga_x'), 'probe_echo', {}); + await callTool(options(fetch), 'probe_echo', {}); expect(new Headers(calls[0]?.init.headers).get('authorization')).toBe('Bearer aga_x'); expect(new Headers(calls[1]?.init.headers).has('authorization')).toBe(false); }); @@ -69,7 +69,7 @@ describe('callTool', () => { structuredContent: { error: { code: 'NOT_FOUND', message: 'gone' } }, }; const { fetch } = fakeFetch(toolAnswer(failed)); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ name: 'HostError', code: 'NOT_FOUND', message: 'gone', @@ -81,11 +81,11 @@ describe('callTool', () => { toolAnswer({ isError: true, content: [{ type: 'image' }, { type: 'text', text: 'boom' }] }), toolAnswer({ isError: true }) ); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code: 'TOOL_ERROR', message: 'boom', }); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code: 'TOOL_ERROR', message: 'the tool reported an error', }); @@ -96,11 +96,11 @@ describe('callTool', () => { jsonResponse({ jsonrpc: '2.0', id: 7, error: { code: -32602, message: 'bad args' } }, 400), toolAnswer({ isError: 'yes' }) ); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code: '-32602', message: 'bad args', }); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code: 'BAD_RESULT', message: 'the tool answered an invalid result', }); @@ -108,7 +108,7 @@ describe('callTool', () => { it('resolves {} for a result without structuredContent', async () => { const { fetch } = fakeFetch(toolAnswer({ content: [] })); - await expect(callTool(options(fetch), 'probe__echo', {})).resolves.toEqual({}); + await expect(callTool(options(fetch), 'probe_echo', {})).resolves.toEqual({}); }); it('accepts a text/event-stream answer and picks the message with its id', async () => { @@ -121,12 +121,12 @@ describe('callTool', () => { '', ].join('\n'); const { fetch } = fakeFetch(jsonResponse(stream, 200, 'text/event-stream')); - await expect(callTool(options(fetch), 'probe__echo', {})).resolves.toEqual({ msg: 'pong hi' }); + await expect(callTool(options(fetch), 'probe_echo', {})).resolves.toEqual({ msg: 'pong hi' }); }); it('rejects with the HTTP status when no JSON-RPC message comes back', async () => { const { fetch } = fakeFetch(jsonResponse('bad gateway', 502, 'text/html')); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code: 'HTTP_502', message: 'MCP answered 502 without a JSON-RPC message', }); @@ -143,7 +143,7 @@ describe('callTool', () => { const { fetch } = fakeFetch( jsonResponse({ success: false, error: { code, message } }, status) ); - await expect(callTool(options(fetch), 'probe__echo', {})).rejects.toMatchObject({ + await expect(callTool(options(fetch), 'probe_echo', {})).rejects.toMatchObject({ code, message, }); @@ -153,19 +153,19 @@ describe('callTool', () => { it('bounds every call at 30 s and names the tool that did not answer', async () => { const { timeout, signal, expire } = controlledTimeout(); const { fetch, calls, called } = hangingFetch(); - const pending = callTool(options(fetch), 'probe__echo', {}); + const pending = callTool(options(fetch), 'probe_echo', {}); await called; expect(timeout).toHaveBeenCalledWith(30_000); expect(calls[0]?.init.signal).toBe(signal); expire(); await expect(pending).rejects.toMatchObject({ code: 'TIMEOUT', - message: 'probe__echo did not answer in 30 s', + message: 'probe_echo did not answer in 30 s', }); }); it('passes a network failure through as it is', async () => { const offline = async () => Promise.reject(new TypeError('Failed to fetch')); - await expect(callTool(options(offline), 'probe__echo', {})).rejects.toThrow('Failed to fetch'); + await expect(callTool(options(offline), 'probe_echo', {})).rejects.toThrow('Failed to fetch'); }); }); diff --git a/packages/widget/src/host/version.ts b/packages/widget/src/host/version.ts index ca88faab..f7bae3c8 100644 --- a/packages/widget/src/host/version.ts +++ b/packages/widget/src/host/version.ts @@ -1 +1 @@ -export const WIDGET_VERSION = '0.4.0'; +export const WIDGET_VERSION = '0.5.0'; diff --git a/packages/widget/src/test-support/fixture/src/ui/echo.tsx b/packages/widget/src/test-support/fixture/src/ui/echo.tsx index e19c95aa..d3c3fd11 100644 --- a/packages/widget/src/test-support/fixture/src/ui/echo.tsx +++ b/packages/widget/src/test-support/fixture/src/ui/echo.tsx @@ -7,7 +7,7 @@ export function Echo() { const [answer, setAnswer] = useState(''); return ( -

{answer}

diff --git a/packages/widget/src/test-support/fixture/src/ui/tools.ts b/packages/widget/src/test-support/fixture/src/ui/tools.ts index 0642096e..3757b6d1 100644 --- a/packages/widget/src/test-support/fixture/src/ui/tools.ts +++ b/packages/widget/src/test-support/fixture/src/ui/tools.ts @@ -1,7 +1,7 @@ -// The probe's tool outputs, so tool('probe__echo') resolves { msg: string }. +// The probe's tool outputs, so tool('probe_echo') resolves { msg: string }. declare module '@agentage/widget' { interface ToolOutputs { - probe__echo: { msg: string }; + probe_echo: { msg: string }; } } diff --git a/template/CLAUDE.md b/template/CLAUDE.md index 79f54c07..3bcc7469 100644 --- a/template/CLAUDE.md +++ b/template/CLAUDE.md @@ -60,7 +60,7 @@ The start steps are in [README.md](README.md#quick-start). After `create`: The scope is `read` (the default), `write`, `admin` or `public` (anonymous). `input` is read from the query on get and delete and from the body otherwise: use `z.coerce` for numbers. The handler returns the data; the kit answers `ok(...)`. -- mcp: give each tool a `scope` beside its schemas. The kit names it `{id}__{name}`. +- mcp: give each tool a `scope` beside its schemas. The kit names it `{id}_{name}`. - The api reads `ctx.extension.store`. Without a store, `/ping` does not query. - store: add a numbered file in `migrations/`. Never edit a migration that ran. - `openapi.json` and `template.mcpc.json` are committed contracts, generated from the routes and diff --git a/template/README.md b/template/README.md index 25356136..3e76152e 100644 --- a/template/README.md +++ b/template/README.md @@ -45,7 +45,7 @@ npx agentage extension down # removes the containers, the network and the vo - `GET /api/template/echo?msg=hi` with a token answers 200; without `msg`, 400. - `GET /api/template/ping` is public and answers 200 with `pong`. - A protected route without a token answers 401. -- The MCP tool `template__echo` is at `POST /mcp`, with the same token. +- The MCP tool `template_echo` is at `POST /mcp`, with the same token. `openapi.json` lists the routes and `template.mcpc.json` lists the tools. More: [answers](docs/run-locally.md#answers) and [health and logs](docs/run-locally.md#health-and-logs). @@ -55,7 +55,7 @@ npx agentage extension down # removes the containers, the network and the vo - pages, `src/pages`: `/` shows the id, the version and the commit. - ui, `src/ui`: the widget ``. - api, `src/api`: `GET /api/template/echo` (scope `template:read`) and `GET /api/template/ping` (public). -- mcp, `src/mcp`: the tool `template__echo` (scope `template:read`). +- mcp, `src/mcp`: the tool `template_echo` (scope `template:read`). - worker, `src/worker`: the job `tick`, every minute. - store, `migrations/` and `seeds/`: postgres. A seed runs once, on an empty store. - cli, `src/cli`: `agentage ping [msg]` prints `pong`. diff --git a/template/src/mcp/index.test.ts b/template/src/mcp/index.test.ts index b3cd71e6..0a9e981a 100644 --- a/template/src/mcp/index.test.ts +++ b/template/src/mcp/index.test.ts @@ -8,7 +8,7 @@ beforeAll(async () => { }); afterAll(() => server.close()); -describe('template__echo', () => { +describe('template_echo', () => { it('declares scope read', () => { const ctx = createTestContext(); create(ctx); diff --git a/template/src/mcp/index.ts b/template/src/mcp/index.ts index 4bb16b12..6a9832b1 100644 --- a/template/src/mcp/index.ts +++ b/template/src/mcp/index.ts @@ -1,7 +1,7 @@ import { type McpContext } from '@agentage/extension'; import { z } from 'zod'; -// The kit serves this tool as {id}__echo on POST /mcp; scope read is {id}:read. +// The kit serves this tool as {id}_echo on POST /mcp; scope read is {id}:read. export function create(ctx: McpContext) { ctx.tool( 'echo', diff --git a/template/src/ui/echo.tsx b/template/src/ui/echo.tsx index a955fcca..e008c7fe 100644 --- a/template/src/ui/echo.tsx +++ b/template/src/ui/echo.tsx @@ -7,7 +7,7 @@ export function Echo() { const [answer, setAnswer] = useState(''); // A refused call (no token on next) shows the host's reason, not an empty card. const ping = () => - tool(`${context.extension}__echo`, { msg: 'hi' }).then( + tool(`${context.extension}_echo`, { msg: 'hi' }).then( ({ msg }) => String(msg), (error: Error) => error.message ); diff --git a/template/template.mcpc.json b/template/template.mcpc.json index c10f616d..c690c046 100644 --- a/template/template.mcpc.json +++ b/template/template.mcpc.json @@ -18,7 +18,7 @@ "required": ["msg"], "type": "object" }, - "name": "template__echo", + "name": "template_echo", "outputSchema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "additionalProperties": false, From 3eb1b20ef73a4ff36c156716ec979171ea76d1db Mon Sep 17 00:00:00 2001 From: Volodymyr Vreshch Date: Mon, 23 Nov 2026 09:52:54 +0100 Subject: [PATCH 2/2] ci: check the template with the candidate kit's own rules The cli bundles the released kit, so its check names tools in the old form. On a kit change the template job now runs the candidate's check. The widget README note moves below its code block. Claude-Session: https://claude.ai/code/session_01XQkodgygL4W8UcLQDwC212 --- .github/workflows/ci.yml | 5 ++++- packages/widget/README.md | 6 +++--- scripts/check-candidate.mjs | 11 +++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 scripts/check-candidate.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17902528..f9b29b17 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -506,9 +506,12 @@ jobs: working-directory: template run: npm run verify + # On the candidate, the kit's own check: the cli bundles the released kit and its rules. - name: Conformance (the kit's six rules; the store rule uses the runner's docker) working-directory: template - run: node_modules/.bin/agentage extension check + run: | + if [ "$CANDIDATE" = true ]; then node "$GITHUB_WORKSPACE/scripts/check-candidate.mjs" + else node_modules/.bin/agentage extension check; fi template-local: name: Template up and the e2e gate on local diff --git a/packages/widget/README.md b/packages/widget/README.md index 2170dcc7..ebf4dd26 100644 --- a/packages/widget/README.md +++ b/packages/widget/README.md @@ -13,9 +13,6 @@ npm install react react-dom This widget from the extension template calls the extension's MCP tool `{id}_echo`: -Since 0.5.0 a widget calls a tool of its own id in the form `{id}_{name}` or the old `{id}__{name}`. -A tool of another id is refused with `FOREIGN_TOOL`. - ```tsx // src/ui/echo.tsx import { useState } from 'react'; @@ -42,6 +39,9 @@ export function Echo() { export const widgets = { echo: Echo }; ``` +Since 0.5.0 a widget calls a tool of its own id in the form `{id}_{name}` or the old `{id}__{name}`. +A tool of another id is refused with `FOREIGN_TOOL`. + ```bash npx agentage-widget bundle # writes dist/ui/{id}.js, widgets.json and the harness page ``` diff --git a/scripts/check-candidate.mjs b/scripts/check-candidate.mjs new file mode 100644 index 00000000..611020b0 --- /dev/null +++ b/scripts/check-candidate.mjs @@ -0,0 +1,11 @@ +import { createRequire } from 'node:module'; +import { join } from 'node:path'; +import { pathToFileURL } from 'node:url'; + +// The check of the kit installed in this folder, as `agentage extension check` prints it. +const dir = process.cwd(); +const entry = createRequire(join(dir, 'package.json')).resolve('@agentage/extension/tool'); +const { check, checkLines } = await import(pathToFileURL(entry).href); +const report = await check(dir); +for (const line of checkLines(report)) console.log(line); +process.exit(report.conforms ? 0 : 1);