From 924a3b20f9183091eac9bea41b1de5249caec9de Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 25 Nov 2026 13:34:47 +0200 Subject: [PATCH 1/2] feat(mcp): both servers serve the h5p-author skill over MCP, and the skill builds with their tools (#280) The local server and the app server (and so the Worker) serve the skill as the author package ships it, SKILL.md, LICENSE and references/, over the Skills extension (SEP-2640). The skill gains route 0: where the chat has h5p_build or h5p_play, they build and their answer is the hand-over. --- apps/mcp-worker/scripts/stage.mjs | 18 +++++---- apps/mcp-worker/tests/worker.test.ts | 8 ++++ apps/mcp-worker/wrangler.jsonc | 2 +- design/author.md | 9 +++++ design/mcp.md | 23 +++++++++-- packages/mcp/README.md | 5 +++ packages/mcp/lib/answers.mjs | 45 ++++++++++++++++++++- packages/mcp/lib/app.mjs | 8 +++- packages/mcp/lib/server.mjs | 7 +++- packages/mcp/tests/app.test.ts | 43 ++++++++++++++++---- packages/mcp/tests/server.test.ts | 10 +++++ skills/h5p-author/SKILL.md | 13 ++++-- skills/h5p-author/references/build/tools.md | 12 ++++++ 13 files changed, 176 insertions(+), 27 deletions(-) create mode 100644 skills/h5p-author/references/build/tools.md diff --git a/apps/mcp-worker/scripts/stage.mjs b/apps/mcp-worker/scripts/stage.mjs index 263dda79..8f9fa0aa 100644 --- a/apps/mcp-worker/scripts/stage.mjs +++ b/apps/mcp-worker/scripts/stage.mjs @@ -1,7 +1,8 @@ // Gathers what the Worker carries beside its code into staged/, which wrangler.jsonc attaches -// to it as modules: the library pack's parts, the author package's brief and type files (copied -// into that package from the skill first, by this package's `stage` script), and the card. Only -// what the server reads; the folder is written anew each time and is not in git. +// to it as modules: the library pack's parts, the h5p-author skill as the author package ships it +// (SKILL.md, LICENSE and references/, with the brief and the type files the server answers from, +// copied into that package from the skill first, by this package's `stage` script), and the card. +// Only what the server reads; the folder is written anew each time and is not in git. import { cp, mkdir, readdir, rm, stat } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' @@ -12,13 +13,16 @@ const at = (specifier) => fileURLToPath(import.meta.resolve(specifier)) const parts = dirname(at('@missing-elements/h5p-libraries/parts/index.json')) const references = dirname(at('@missing-elements/h5p-author/references/authoring.md')) +const author = dirname(references) const card = join(dirname(at('@missing-elements/h5p-mcp/package.json')), 'lib', 'card.html') await rm(staged, { recursive: true, force: true }) -await mkdir(join(staged, 'references'), { recursive: true }) +await mkdir(staged, { recursive: true }) await cp(parts, join(staged, 'parts'), { recursive: true }) -await cp(join(references, 'authoring.md'), join(staged, 'references', 'authoring.md')) -await cp(join(references, 'types'), join(staged, 'references', 'types'), { recursive: true }) +// The skill, served over MCP (#280): its references/ whole, and SKILL.md and LICENSE beside it. +await cp(references, join(staged, 'references'), { recursive: true, filter: (from) => !/\.[^/]+$/.test(from) || from.endsWith('.md') }) +await cp(join(author, 'SKILL.md'), join(staged, 'SKILL.md')) +await cp(join(author, 'LICENSE'), join(staged, 'LICENSE')) await cp(card, join(staged, 'card.html')) const names = async (/** @type {string} */ folder, /** @type {string} */ ending) => (await readdir(join(staged, folder))).filter((name) => name.endsWith(ending)) @@ -29,4 +33,4 @@ for (const name of await readdir(staged, { recursive: true })) { const file = await stat(join(staged, name)) if (file.isFile()) bytes += file.size } -console.log(`Staged ${libraries.length} parts, ${types.length} type files, the brief and the card: ${(bytes / 1048576).toFixed(1)} MB`) +console.log(`Staged ${libraries.length} parts, the skill with ${types.length} type files, and the card: ${(bytes / 1048576).toFixed(1)} MB`) diff --git a/apps/mcp-worker/tests/worker.test.ts b/apps/mcp-worker/tests/worker.test.ts index 00446639..be7d5ebc 100644 --- a/apps/mcp-worker/tests/worker.test.ts +++ b/apps/mcp-worker/tests/worker.test.ts @@ -83,6 +83,14 @@ describe('the app server as a Worker', () => { expect((await ask(hosted, 'resources/read', { uri: earlier })).contents[0].text).toBe((await ask(local, 'resources/read', { uri: server.cardUri })).contents[0].text) }) + it('serves the h5p-author skill it carries, as the server on a computer does', async () => { + // Skills over MCP (#280): the same entry, every file listed, and the files read the same. + const listed = await ask(hosted, 'skills/list') + expect(listed).toEqual(await ask(local, 'skills/list')) + expect(listed.skills.map((skill: { uri: string }) => skill.uri)).toEqual(['skill://h5p-author/SKILL.md']) + for (const { uri } of listed.skills[0].resources) expect(await ask(hosted, 'resources/read', { uri })).toEqual(await ask(local, 'resources/read', { uri })) + }) + it('answers the endpoint and nothing else, and no body over 1 MB', async () => { const at = (path: string, init?: RequestInit) => hosted(new Request(`https://host.example${path}`, init)) expect((await at('/')).status).toBe(200) diff --git a/apps/mcp-worker/wrangler.jsonc b/apps/mcp-worker/wrangler.jsonc index 79ce3898..5a4b4570 100644 --- a/apps/mcp-worker/wrangler.jsonc +++ b/apps/mcp-worker/wrangler.jsonc @@ -11,7 +11,7 @@ "base_dir": "staged", "rules": [ { "type": "Data", "globs": ["parts/*.h5p"], "fallthrough": true }, - { "type": "Text", "globs": ["parts/index.json", "references/**/*.md"], "fallthrough": true } + { "type": "Text", "globs": ["parts/index.json", "references/**/*.md", "SKILL.md", "LICENSE"], "fallthrough": true } ], // Workers Logs off: no invocation log and no trace of a call is stored. The test holds the // file to it. What Cloudflare counts for any Worker is not this setting's (design/mcp.md). diff --git a/design/author.md b/design/author.md index e7be5f68..87b49290 100644 --- a/design/author.md +++ b/design/author.md @@ -562,6 +562,15 @@ text to the content check's rules, and `apps/skills` plays every example untrust the build archive attached (route 1, `references/build/archive.md`), npm (route 2, `npm.md`), Node (route 3, `two-files.md`), anything else (route 4, `browser.md`). Routes 1 to 3 hand over by `built-here.md`: the build's problems, the verifier where npm answered, and the hand-over. + - Route 0 (`references/build/tools.md`, #280) comes before that check: where the chat has the + tool `h5p_build` or `h5p_play`, they build, and their answer is the hand-over, with no command, + no npm check and no step 4. Both MCP servers serve the skill, and the skills CLI installs it + beside them, so a chat can hold the skill and the tools. Given both, Haiku in Claude Code, + asked for a True/False question, used the tools without opening the skill in 8 of 8 runs, on + the skill before route 0 and with it. Told to use the skill, the skill before route 0 ran + `npx` and left the tools unused in 3 of 3 runs ($0.007 each); with route 0 it built with the + tools in 9 of 9 ($0.004). Two of the first five also ran the npm check first, since the skill + said to run it early; after "unless route 0's tools build", none of the next four did. - A package the user has is changed by `references/change.md` (#242), in place of steps 1 and 2, asking nothing: read by the tool of the first route that holds (route 3 fetches the bundle of the type the package's `h5p.json` names; route 4 cannot read one), the source changed as asked, diff --git a/design/mcp.md b/design/mcp.md index d668e5c0..76fd706a 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -21,9 +21,23 @@ below. reads one back into its source. The instructions are the flow in a few lines: the type is the one question, its answer is read before the source is written, then the build, where the file is and what the check found, and the preview offered; a package the person has is read, its source - changed, and built. Not `SKILL.md`, whose build routes do not apply here. An app sends the descriptions and the - instructions with every message, so they stay under about 1,500 tokens; `server.test.ts` holds - them under 6,000 characters. + changed, and built. Not `SKILL.md`, which is served as a skill instead (below): it is mostly + build routes for chats without these tools. An app sends the descriptions and the instructions + with every message, so they stay under about 1,500 tokens; `server.test.ts` holds them under + 6,000 characters. +- **Both servers serve the h5p-author skill over MCP, as the author package ships it** (#280). + MCP's Skills extension (SEP-2640, `io.modelcontextprotocol/skills`) has a server serve a skill + folder as `skill://` resources beside its tools, and answer `skills/list` and `skills/get`; a + chat that has it lists the skill and loads `SKILL.md` when it is needed. Both serve + `skill://h5p-author/`: `SKILL.md`, `LICENSE` and the `.md` files under `references/`, nothing + else of the package (`skillCatalog` in `answers.mjs`, the SDK's `SkillsExtension` over files + held in memory, read once as the server starts). The skill's first build route is these tools, + so a model that loaded it from a server, or that has it installed beside them, builds with them + and runs nothing (the skill's rule in [author.md](author.md)). A chat without the extension sees + nothing new, so the instructions and `h5p_types` stay. The other half of the pattern is the + skill installed in the agent, by the skills CLI, which writes it where each agent reads skills. + Not seen loaded anywhere yet: Claude Code 2.1.331 has the client and never called + `skills/list`, on the 2025 protocol or 2026-07-28, on Haiku, Sonnet or Opus (2026-11-25). - **`h5p_build` shows a source's own fields; the build checks them.** Its `source` carries the fields of the author package's `sourceSchema` as JSON Schema properties (#230), so a model writes the authors and the licence right before its first build: without them, Haiku wrote @@ -209,7 +223,8 @@ command is that handler on a port. Its endpoint is `/mcp`. endpoint with no sign-in lets anyone bring about. - **The Worker is the same handler, and carries what the server reads.** `createApp()`, the package's `./app`, takes as options what `import.meta` cannot find in a bundle: `version`, - `card`, `references`. The library pack's parts, the brief with the type files and the card are + `card`, `references`. The library pack's parts, the h5p-author skill (its `references/`, with + `SKILL.md` and `LICENSE` beside it, which `references` names) and the card are gathered into `staged/` by `scripts/stage.mjs` and ride in the Worker as modules (`find_additional_modules`), which its file system shows under `/bundle`: the server's Node entry reads them there as on a computer (`nodejs_compat`). 17 MB of the 64 MiB a Worker may be. diff --git a/packages/mcp/README.md b/packages/mcp/README.md index d737d65d..1bccafa2 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -53,6 +53,11 @@ gets a number, and it says which. beside it, to change and build again. It reads content made for the library pack's versions of its libraries, and says what a source cannot hold, such as the author's comments. +Both servers also serve the [h5p-author skill](https://github.com/missing-elements/h5p-toolkit/tree/main/skills/h5p-author) over MCP's +Skills extension (SEP-2640), for an app that loads skills from a server. Installed in your agent +instead, with `npx skills add missing-elements/h5p-toolkit --skill h5p-author`, the same skill +builds with these tools wherever they are connected. + ## What leaves your computer The build downloads each picture, video, recording or other file your content names by web diff --git a/packages/mcp/lib/answers.mjs b/packages/mcp/lib/answers.mjs index af7d3c50..c2b4b30f 100644 --- a/packages/mcp/lib/answers.mjs +++ b/packages/mcp/lib/answers.mjs @@ -1,6 +1,7 @@ -import { readdir, readFile } from 'node:fs/promises' +import { readdir, readFile, stat } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' +import { SkillsExtension, memorySkillFiles } from '@modelcontextprotocol/server/ext/skills' import { z } from 'zod' import { contentTypes, openPack, schemaOf, sourceSchema, sourceType } from '@missing-elements/h5p-author' @@ -115,3 +116,45 @@ export function typeAnswers(options = {}) { } } } + +/** The author package's `references/` folder, as installed. */ +const installedReferences = () => join(dirname(fileURLToPath(import.meta.resolve('@missing-elements/h5p-author/package.json'))), 'references') + +/** + * The h5p-author skill, for a server to serve over MCP (#280): the Skills extension, SEP-2640, + * which a chat that has it lists beside the server's tools and loads when it is needed. The skill + * as the author package ships it, and nothing else of the package: `SKILL.md` and `LICENSE` + * beside `references/`, and the `.md` files under it. Read once, as the server starts, and held + * in memory: a file read from a chat is one of these, whatever it names. + * + * A folder a host named must hold the skill, and a problem in it is said as the server starts, + * as with `typeAnswers`. The installed package's is taken as it is found: in this repository it + * is copied in by a build step, and where it is not there yet no skill is served. + * @param {{ references?: string }} [options] the author package's `references/`, as `typeAnswers` takes it; the installed package's by default + * @returns {Promise} + */ +export async function skillCatalog(options = {}) { + const references = options.references ?? installedReferences() + const root = dirname(references) + /** @type {Record} */ + const files = {} + try { + files['h5p-author/SKILL.md'] = await readFile(join(root, 'SKILL.md')) + files['h5p-author/LICENSE'] = await readFile(join(root, 'LICENSE')) + /** @param {string} folder @param {string} under */ + const gather = async (folder, under) => { + for (const name of (await readdir(folder)).sort()) { + const path = join(folder, name) + if ((await stat(path)).isDirectory()) await gather(path, `${under}${name}/`) + else if (name.endsWith('.md')) files[`h5p-author/references/${under}${name}`] = await readFile(path) + } + } + await gather(references, '') + } catch (error) { + if (options.references !== undefined) throw new Error(`${root} does not hold the h5p-author skill: SKILL.md, LICENSE and references/`, { cause: error }) + return null + } + // Strict: what would be a warning, a skill over the limits or a SKILL.md that does not read, is + // said as the server starts, and nothing is written to the console. + return SkillsExtension.load(memorySkillFiles(files), { strict: true }) +} diff --git a/packages/mcp/lib/app.mjs b/packages/mcp/lib/app.mjs index 704bb6d6..ba5f3d82 100644 --- a/packages/mcp/lib/app.mjs +++ b/packages/mcp/lib/app.mjs @@ -3,7 +3,7 @@ import { readFile } from 'node:fs/promises' import { McpServer, ResourceNotFoundError, ResourceTemplate, createMcpHandler } from '@modelcontextprotocol/server' import { z } from 'zod' import { SourceError, buildPackage } from '@missing-elements/h5p-author' -import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, typeAnswers } from './answers.mjs' +import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, skillCatalog, typeAnswers } from './answers.mjs' /** * The app server (#210, #270): an MCP server over HTTP for a chat app that shows a card in its @@ -20,7 +20,7 @@ import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, typeAnswers } fro * @typedef {object} AppOptions * @property {string} [site] the origin of the site whose play page the card frames; `https://missing-elements.github.io` by default * @property {string} [libraries] the pack's `parts/` folder to check with; the installed pack by default - * @property {string} [references] the folder of the author package's type files and brief, its `references/`; the installed package's by default + * @property {string} [references] the folder of the author package's type files and brief, its `references/`, with the skill's `SKILL.md` and `LICENSE` beside it, as in the package; the installed package's by default * @property {string} [card] the card's text, `lib/card.html`; read from beside this file by default * @property {string} [version] the version the server names itself with; this package's by default * @@ -117,6 +117,9 @@ export async function createApp(options = {}) { const about = typeAnswers({ libraries: options.libraries, references: options.references }) // Said as the server starts, not found out by whoever reads its answers. await about.held() + // The h5p-author skill, served beside the tools to a chat that loads skills from a server + // (#280): its first build route is h5p_play. Read once, here; one catalog serves every request. + const skills = await skillCatalog({ references: options.references }) // The card's policy: the one site it frames, and the chat's file store, which it asks for the // attached file. Written twice, as the MCP Apps specification places it and as ChatGPT reads it. const cardMeta = { @@ -214,6 +217,7 @@ export async function createApp(options = {}) { if (typeof hash !== 'string' || !/^[0-9a-f]{12}$/.test(hash)) throw new ResourceNotFoundError(uri.href) return { contents: [{ uri: uri.href, mimeType: CARD_TYPE, text: card, _meta: cardMeta }] } }) + skills?.attach(mcp) return mcp } diff --git a/packages/mcp/lib/server.mjs b/packages/mcp/lib/server.mjs index 36f0e7ed..03612f3e 100644 --- a/packages/mcp/lib/server.mjs +++ b/packages/mcp/lib/server.mjs @@ -5,7 +5,7 @@ import { McpServer } from '@modelcontextprotocol/server' import { z } from 'zod' import { SourceError, buildPackage, coreApiLine, inside, publicFetch, readPackage } from '@missing-elements/h5p-author' import { VerifyError, openBrowser, previewPackage, summarize, verifyPackage } from '@missing-elements/h5p-verify' -import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, typeAnswers } from './answers.mjs' +import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, skillCatalog, typeAnswers } from './answers.mjs' import { defaultFolders, fileStem, rootFolders } from './folders.mjs' /** @@ -254,6 +254,11 @@ export async function createServer(options = {}) { return answer(`${opened ? `Opened ${basename(path)} in the browser at ${address}.` : `The preview of ${basename(path)} is at ${address}: open it in a browser.`} It is served from this computer until its tab is closed.`) }) + // The h5p-author skill, for a chat that loads skills from a server (#280): its first build route + // is this server's h5p_build. A chat without the Skills extension sees no change. + const skills = await skillCatalog() + skills?.attach(server) + return { server, /** Ends every preview still open, as the server stops. */ diff --git a/packages/mcp/tests/app.test.ts b/packages/mcp/tests/app.test.ts index 230a0422..ea0927da 100644 --- a/packages/mcp/tests/app.test.ts +++ b/packages/mcp/tests/app.test.ts @@ -1,8 +1,9 @@ import { spawn, type ChildProcess } from 'node:child_process' -import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises' import { createServer, type AddressInfo, type Server } from 'node:net' import { tmpdir } from 'node:os' -import { join, resolve } from 'node:path' +import { dirname, join, resolve, sep } from 'node:path' +import { fileURLToPath } from 'node:url' import { Client } from '@modelcontextprotocol/client' import { StreamableHTTPClientTransport } from '@modelcontextprotocol/client' import { afterAll, beforeAll, describe, expect, it } from 'vitest' @@ -114,8 +115,8 @@ describe('the app server', () => { expect(earlier.contents[0]).toMatchObject({ uri: 'ui://h5p-play/card-df8ccbdd2aa8.html', mimeType: 'text/html;profile=mcp-app', text: card.text }) expect((earlier.contents[0] as { _meta: unknown })._meta).toEqual(card._meta) await expect(client.readResource({ uri: 'ui://h5p-play/card-latest.html' })).rejects.toThrow(/not found/i) - // One card is listed. - expect((await client.listResources()).resources.map((resource) => resource.uri)).toEqual([uri]) + // One card is listed, beside the skill's SKILL.md (#280). + expect((await client.listResources()).resources.map((resource) => resource.uri).sort()).toEqual(['skill://h5p-author/SKILL.md', uri]) expect(card.text).toContain("const SITE = 'https://missing-elements.github.io'") expect(card.text).not.toContain('__SITE__') expect(card._meta.ui.csp.frameDomains).toEqual(['https://missing-elements.github.io']) @@ -132,6 +133,25 @@ describe('the app server', () => { expect(same.cardUri).toBe(uri) }) + it('serves the h5p-author skill as the author package ships it, and no other file of the package', async () => { + // MCP's Skills extension, SEP-2640 (#280). + expect(client.getServerCapabilities()?.extensions).toHaveProperty(['io.modelcontextprotocol/skills']) + const listed = await fetch(address, { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'skills/list', params: {} }) }) + const text = await listed.text() + const { skills } = JSON.parse(text.split('\n').find((line) => line.startsWith('data: '))?.slice(6) ?? text).result as { skills: { uri: string, frontmatter: Record, resources: { uri: string }[] }[] } + expect(skills).toHaveLength(1) + expect(skills[0]).toMatchObject({ uri: 'skill://h5p-author/SKILL.md', frontmatter: { name: 'h5p-author', description: expect.stringMatching(/^Create H5P content/) } }) + // SKILL.md, LICENSE and every .md under references/: nothing else of the package. + const author = dirname(fileURLToPath(import.meta.resolve('@missing-elements/h5p-author/package.json'))) + const own = (await readdir(join(author, 'references'), { recursive: true })).filter((name) => name.endsWith('.md')).map((name) => `references/${name.split(sep).join('/')}`) + expect(skills[0]!.resources.map((resource) => resource.uri.replace('skill://h5p-author/', '')).sort()).toEqual(['LICENSE', 'SKILL.md', ...own].sort()) + expect(own).toContain('references/build/tools.md') + // Read as the package has it. + const read = await client.readResource({ uri: 'skill://h5p-author/SKILL.md' }) + expect((read.contents[0] as { text: string }).text).toBe(await readFile(join(author, 'SKILL.md'), 'utf8')) + await expect(client.readResource({ uri: 'skill://h5p-author/package.json' })).rejects.toThrow() + }) + it('lists the content types and answers for one, with no word of folders', async () => { const list = textOf(await call('h5p_types')) expect(list).toMatch(/^\* H5P\.MultiChoice: /m) @@ -263,11 +283,15 @@ describe('the app server', () => { it('takes its card, its version and its type files from a host that carries them', async () => { // A bundle has no package folder beside the code, so its host names what it carries (#272). - const references = await mkdtemp(join(tmpdir(), 'h5p-mcp-references-')) + const carried = await mkdtemp(join(tmpdir(), 'h5p-mcp-carried-')) + const references = join(carried, 'references') try { - await mkdir(join(references, 'types')) + await mkdir(join(references, 'types'), { recursive: true }) await writeFile(join(references, 'types', 'H5P.TrueFalse.md'), "# The host's own notes on a statement\n") await writeFile(join(references, 'authoring.md'), "The host's own brief.\n") + // The skill beside it, as in the author package (#280). + await writeFile(join(carried, 'SKILL.md'), "---\nname: h5p-author\ndescription: The host's own copy of the skill.\n---\n\nBuild with the tools.\n") + await writeFile(join(carried, 'LICENSE'), 'MIT\n') const app = await createApp({ version: '9.9.9', card: "

A host's card for __SITE__

", references }) const ask = async (method: string, params: unknown) => { const response = await app.fetch(new Request('https://host.example/mcp', { @@ -286,11 +310,16 @@ describe('the app server', () => { expect(list).toContain("The host's own brief.") expect(list).toMatch(/^\* H5P\.TrueFalse\b/m) expect(list).not.toMatch(/^\* H5P\.MultiChoice\b/m) + // The skill it serves is the host's copy. + expect((await ask('skills/list', {})).skills.map((skill: { frontmatter: { description: string } }) => skill.frontmatter.description)).toEqual(["The host's own copy of the skill."]) await app.close() // A folder that is not the author package's is said at the start, not by thinner answers. await expect(createApp({ references: join(references, 'types') })).rejects.toThrow(/is not the author package's references\/ folder/) + // And so is one with no skill beside it. + await rm(join(carried, 'SKILL.md')) + await expect(createApp({ references })).rejects.toThrow(/does not hold the h5p-author skill/) } finally { - await rm(references, { recursive: true, force: true }) + await rm(carried, { recursive: true, force: true }) } }) diff --git a/packages/mcp/tests/server.test.ts b/packages/mcp/tests/server.test.ts index 79bdc1a3..971dec5d 100644 --- a/packages/mcp/tests/server.test.ts +++ b/packages/mcp/tests/server.test.ts @@ -4,6 +4,7 @@ import { basename, join, resolve } from 'node:path' import { Client } from '@modelcontextprotocol/client' import { StdioClientTransport } from '@modelcontextprotocol/client/stdio' import { afterAll, beforeAll, describe, expect, it } from 'vitest' +import { z } from 'zod' /** * The server as an app runs it: the command the package ships, started over standard input and @@ -66,6 +67,15 @@ describe('the server', () => { }) describe('h5p_types', () => { + it('serves the h5p-author skill beside its tools, with a first route for them', async () => { + // MCP's Skills extension, SEP-2640 (#280), as the app server serves it too. + expect(client.getServerCapabilities()?.extensions).toHaveProperty(['io.modelcontextprotocol/skills']) + const { skills } = await client.request({ method: 'skills/list', params: {} }, z.object({ skills: z.array(z.object({ uri: z.string() }).loose()) }).loose()) + expect(skills.map((skill) => skill.uri)).toEqual(['skill://h5p-author/SKILL.md']) + const route = await client.readResource({ uri: 'skill://h5p-author/references/build/tools.md' }) + expect((route.contents[0] as { text: string }).text).toMatch(/h5p_build/) + }) + it('lists the pack\'s content types, marking those with a type file, and how to write good content', async () => { const answer = await call('h5p_types') const text = textOf(answer) diff --git a/skills/h5p-author/SKILL.md b/skills/h5p-author/SKILL.md index df2b0ebf..529edcb4 100644 --- a/skills/h5p-author/SKILL.md +++ b/skills/h5p-author/SKILL.md @@ -56,8 +56,9 @@ choose, and wait: "a quiz" or "flash cards" says what they want, not which type. | H5P.Audio | an audio player (a recording) | | H5P.GameMap | stages on a map, each with exercises (a map) | -For a type not listed, say it has no notes here, and read its fields with the build tool: -`npx @missing-elements/h5p-author@latest schema ` where npm reaches its registry; otherwise, +For a type not listed, say it has no notes here, and read its fields: with route 0's tools, +`h5p_types` with the type; `npx @missing-elements/h5p-author@latest schema ` where npm +reaches its registry; otherwise, beside the tool and its libraries as route 1 or 3 of step 3 gets them, `node h5p-author.mjs schema --libraries parts`. Never read a library's semantics or code yourself: the type file and `schema` say what a source may write, and an agent that works it out @@ -93,10 +94,14 @@ H5P.Video, H5P.Text. ## 3. Build +Where this chat has the tool `h5p_build` or `h5p_play`, they build: follow +[route 0](./references/build/tools.md), and run nothing below. + Where a command runs here, work in a folder of your own, not the one the user named, with the source as `source.json`. Whether npm reaches its registry picks the route, and later whether the -verifier runs. With no code tool it does not. Otherwise run this once, early, beside the files you -read, since it waits on nothing. It prints a version, or gives up within ten seconds. +verifier runs. With no code tool it does not. Otherwise, unless route 0's tools build, run this +once, early, beside the files you read, since it waits on nothing. It prints a version, or gives +up within ten seconds. ```bash npm view @missing-elements/h5p-author version --fetch-timeout=10000 --fetch-retries=0 diff --git a/skills/h5p-author/references/build/tools.md b/skills/h5p-author/references/build/tools.md new file mode 100644 index 00000000..186f4de4 --- /dev/null +++ b/skills/h5p-author/references/build/tools.md @@ -0,0 +1,12 @@ +# Route 0: this chat's H5P tools + +This chat has the tools of an H5P server: `h5p_build`, which writes the `.h5p` into the user's +folders and checks it, or `h5p_play`, which checks the source and plays the activity in the chat, +with a download of the file. They are the build: run no command and download nothing. + +- A type with no file here: `h5p_types` with the type gives its fields. +- Call the tool with the source. Where it lists problems, fix each at its path and call it again. +- A file the user attached in the chat goes in `h5p_play`'s `file` as it is: do not open it. +- A package the user has is read into its source with `h5p_read`, where this chat has it. +- The tool's answer is the hand-over: give what it says to give, and no other address. Step 4 is + not for this route. From dbd514caee5f06f780792794aacd7a03ded180ae Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 25 Nov 2026 13:41:41 +0200 Subject: [PATCH 2/2] fix(mcp): the skill's folder is read without following links, and only a missing file means no skill (#280) --- design/author.md | 8 +++++--- packages/mcp/lib/answers.mjs | 15 +++++++++------ packages/mcp/tests/app.test.ts | 9 +++++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/design/author.md b/design/author.md index 87b49290..bcfcd080 100644 --- a/design/author.md +++ b/design/author.md @@ -564,9 +564,11 @@ text to the content check's rules, and `apps/skills` plays every example untrust by `built-here.md`: the build's problems, the verifier where npm answered, and the hand-over. - Route 0 (`references/build/tools.md`, #280) comes before that check: where the chat has the tool `h5p_build` or `h5p_play`, they build, and their answer is the hand-over, with no command, - no npm check and no step 4. Both MCP servers serve the skill, and the skills CLI installs it - beside them, so a chat can hold the skill and the tools. Given both, Haiku in Claude Code, - asked for a True/False question, used the tools without opening the skill in 8 of 8 runs, on + no npm check and no step 4. Both MCP servers serve the skill, and an agent that has the skill + installed by the skills CLI may have a server connected too, so a chat can hold the skill and + the tools; without the tools, the skill goes on to step 3's routes. Given both, Haiku in + Claude Code, asked for a True/False question, used the tools without opening the skill in 8 + of 8 runs, on the skill before route 0 and with it. Told to use the skill, the skill before route 0 ran `npx` and left the tools unused in 3 of 3 runs ($0.007 each); with route 0 it built with the tools in 9 of 9 ($0.004). Two of the first five also ran the npm check first, since the skill diff --git a/packages/mcp/lib/answers.mjs b/packages/mcp/lib/answers.mjs index c2b4b30f..74580154 100644 --- a/packages/mcp/lib/answers.mjs +++ b/packages/mcp/lib/answers.mjs @@ -1,4 +1,4 @@ -import { readdir, readFile, stat } from 'node:fs/promises' +import { readdir, readFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { SkillsExtension, memorySkillFiles } from '@modelcontextprotocol/server/ext/skills' @@ -129,7 +129,8 @@ const installedReferences = () => join(dirname(fileURLToPath(import.meta.resolve * * A folder a host named must hold the skill, and a problem in it is said as the server starts, * as with `typeAnswers`. The installed package's is taken as it is found: in this repository it - * is copied in by a build step, and where it is not there yet no skill is served. + * is copied in by a build step, and where a file of it is not there yet no skill is served; any + * other error reading it is said. * @param {{ references?: string }} [options] the author package's `references/`, as `typeAnswers` takes it; the installed package's by default * @returns {Promise} */ @@ -143,15 +144,17 @@ export async function skillCatalog(options = {}) { files['h5p-author/LICENSE'] = await readFile(join(root, 'LICENSE')) /** @param {string} folder @param {string} under */ const gather = async (folder, under) => { - for (const name of (await readdir(folder)).sort()) { - const path = join(folder, name) - if ((await stat(path)).isDirectory()) await gather(path, `${under}${name}/`) - else if (name.endsWith('.md')) files[`h5p-author/references/${under}${name}`] = await readFile(path) + // Real folders and files only: a link, which could lead out of the folder, is not followed. + for (const entry of (await readdir(folder, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : 1))) { + const path = join(folder, entry.name) + if (entry.isDirectory()) await gather(path, `${under}${entry.name}/`) + else if (entry.isFile() && entry.name.endsWith('.md')) files[`h5p-author/references/${under}${entry.name}`] = await readFile(path) } } await gather(references, '') } catch (error) { if (options.references !== undefined) throw new Error(`${root} does not hold the h5p-author skill: SKILL.md, LICENSE and references/`, { cause: error }) + if (/** @type {NodeJS.ErrnoException} */ (error).code !== 'ENOENT') throw error return null } // Strict: what would be a warning, a skill over the limits or a SKILL.md that does not read, is diff --git a/packages/mcp/tests/app.test.ts b/packages/mcp/tests/app.test.ts index ea0927da..60631cfd 100644 --- a/packages/mcp/tests/app.test.ts +++ b/packages/mcp/tests/app.test.ts @@ -1,5 +1,5 @@ import { spawn, type ChildProcess } from 'node:child_process' -import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises' +import { mkdir, mkdtemp, readdir, readFile, rm, symlink, writeFile } from 'node:fs/promises' import { createServer, type AddressInfo, type Server } from 'node:net' import { tmpdir } from 'node:os' import { dirname, join, resolve, sep } from 'node:path' @@ -292,6 +292,9 @@ describe('the app server', () => { // The skill beside it, as in the author package (#280). await writeFile(join(carried, 'SKILL.md'), "---\nname: h5p-author\ndescription: The host's own copy of the skill.\n---\n\nBuild with the tools.\n") await writeFile(join(carried, 'LICENSE'), 'MIT\n') + // A link in the folder, to a file outside it, is not followed. + await writeFile(join(carried, 'outside.md'), 'Not the skill.\n') + await symlink(join(carried, 'outside.md'), join(references, 'linked.md')) const app = await createApp({ version: '9.9.9', card: "

A host's card for __SITE__

", references }) const ask = async (method: string, params: unknown) => { const response = await app.fetch(new Request('https://host.example/mcp', { @@ -311,7 +314,9 @@ describe('the app server', () => { expect(list).toMatch(/^\* H5P\.TrueFalse\b/m) expect(list).not.toMatch(/^\* H5P\.MultiChoice\b/m) // The skill it serves is the host's copy. - expect((await ask('skills/list', {})).skills.map((skill: { frontmatter: { description: string } }) => skill.frontmatter.description)).toEqual(["The host's own copy of the skill."]) + const [skill] = (await ask('skills/list', {})).skills as { frontmatter: { description: string }, resources: { uri: string }[] }[] + expect(skill!.frontmatter.description).toBe("The host's own copy of the skill.") + expect(skill!.resources.map((resource) => resource.uri.replace('skill://h5p-author/', '')).sort()).toEqual(['LICENSE', 'SKILL.md', 'references/authoring.md', 'references/types/H5P.TrueFalse.md']) await app.close() // A folder that is not the author package's is said at the start, not by thinner answers. await expect(createApp({ references: join(references, 'types') })).rejects.toThrow(/is not the author package's references\/ folder/)