Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/mcp-worker/scripts/stage.mjs
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'))
Comment thread
alekswebnet marked this conversation as resolved.
Resolved
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))
Expand All @@ -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`)
8 changes: 8 additions & 0 deletions apps/mcp-worker/tests/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/mcp-worker/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
11 changes: 11 additions & 0 deletions design/author.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ 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 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
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,
Expand Down
23 changes: 19 additions & 4 deletions design/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions packages/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions packages/mcp/lib/answers.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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'
import { z } from 'zod'
import { contentTypes, openPack, schemaOf, sourceSchema, sourceType } from '@missing-elements/h5p-author'

Expand Down Expand Up @@ -115,3 +116,48 @@ 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 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<SkillsExtension | null>}
*/
export async function skillCatalog(options = {}) {
const references = options.references ?? installedReferences()
const root = dirname(references)
/** @type {Record<string, Uint8Array>} */
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) => {
// 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 })
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
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
// said as the server starts, and nothing is written to the console.
return SkillsExtension.load(memorySkillFiles(files), { strict: true })
}
8 changes: 6 additions & 2 deletions packages/mcp/lib/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion packages/mcp/lib/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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. */
Expand Down
Loading