@missing-elements/h5p-mcp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/lib/server.mjs +67 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
`@missing-elements/h5p-mcp` lets an AI app make H5P content on your computer: quizzes, fill in the
|
|
4
4
|
blanks, flash cards, presentations, interactive books, branching scenarios and the rest of the 53
|
|
5
5
|
content types the H5P hub serves. It writes a playable `.h5p` that carries its libraries, checks
|
|
6
|
-
that it plays in a real H5P player, and opens it in your browser.
|
|
6
|
+
that it plays in a real H5P player, and opens it in your browser. It reads a `.h5p` you have back
|
|
7
|
+
into its source too, to change it and build it again. No H5P site, server or account.
|
|
7
8
|
|
|
8
9
|
It is a local [MCP](https://modelcontextprotocol.io) server: your app starts it on your computer,
|
|
9
10
|
and it sends nothing to a server of ours. It needs Node 22 or newer, and for the check Chrome or
|
|
@@ -46,6 +47,9 @@ gets a number, and it says which.
|
|
|
46
47
|
problems is refused, each problem named. It checks the package and says what it holds.
|
|
47
48
|
- `h5p_preview`: opens a package in your browser, in the real player, served from your computer
|
|
48
49
|
until its tab is closed.
|
|
50
|
+
- `h5p_read`: a package back into its source, with its pictures and other files, in a new folder
|
|
51
|
+
beside it, to change and build again. It reads content made for the library pack's versions of
|
|
52
|
+
its libraries, and says what a source cannot hold, such as the author's comments.
|
|
49
53
|
|
|
50
54
|
## What leaves your computer
|
|
51
55
|
|
package/lib/server.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { basename, dirname, join, resolve } from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import { McpServer } from '@modelcontextprotocol/server'
|
|
6
6
|
import { z } from 'zod'
|
|
7
|
-
import { SourceError, buildPackage, contentTypes, inside, openPack, publicFetch, schemaOf, sourceSchema, sourceType } from '@missing-elements/h5p-author'
|
|
7
|
+
import { SourceError, buildPackage, contentTypes, inside, openPack, publicFetch, readPackage, schemaOf, sourceSchema, sourceType } from '@missing-elements/h5p-author'
|
|
8
8
|
import { VerifyError, openBrowser, previewPackage, summarize, verifyPackage } from '@missing-elements/h5p-verify'
|
|
9
9
|
import { defaultFolders, fileStem, rootFolders } from './folders.mjs'
|
|
10
10
|
|
|
@@ -23,7 +23,10 @@ const INSTRUCTIONS = `Builds H5P content as a .h5p file from a short JSON source
|
|
|
23
23
|
2. Call h5p_types with the type and write the source from its notes, example and fields: only what differs from the defaults.
|
|
24
24
|
3. Call h5p_build. Where it lists problems, fix each at its path and build again.
|
|
25
25
|
4. Tell the person where the file is and what the check found, and offer h5p_preview.
|
|
26
|
-
The author and the licence are what the person gave; otherwise the name you know them by, or "Unknown", and the licence "U". Say which you used
|
|
26
|
+
The author and the licence are what the person gave; otherwise the name you know them by, or "Unknown", and the licence "U". Say which you used.
|
|
27
|
+
To change a .h5p the person has, h5p_read it, change its source as asked, and h5p_build that.`
|
|
28
|
+
|
|
29
|
+
const READ = `Reads a .h5p package back into its source, to change it and build it again with h5p_build: its type, title, language, licence, authors, and the params that differ from the defaults. Writes the source and the package's media into a new folder beside it, and answers with the source, each file named where it was written. Reads content made for the library pack's versions of its libraries.`
|
|
27
30
|
|
|
28
31
|
const TYPES = `The H5P content types and how to write a source for one. With no type: the list, and how to write good content. With a type: its notes, a tested example and its fields. Read the type's answer before writing its source.`
|
|
29
32
|
|
|
@@ -65,8 +68,25 @@ const OUTLINE_LINES = 80
|
|
|
65
68
|
const sourceBeside = (path) => path.replace(/\.h5p$/i, '.source.json')
|
|
66
69
|
|
|
67
70
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
71
|
+
* A read source's files named in the folder it was read into, so that a build looks for each there
|
|
72
|
+
* and nowhere else: one the read wrote, where it is, and one the package lacks, where the person can
|
|
73
|
+
* put it. Every file a read source names, but by a web address, is under its folder by its path
|
|
74
|
+
* (`readPackage`); a path is a field of a file alone in every content type.
|
|
75
|
+
* @param {unknown} value
|
|
76
|
+
* @param {string} folder
|
|
77
|
+
* @returns {unknown}
|
|
78
|
+
*/
|
|
79
|
+
function located(value, folder) {
|
|
80
|
+
if (Array.isArray(value)) return value.map((each) => located(each, folder))
|
|
81
|
+
if (!value || typeof value !== 'object') return value
|
|
82
|
+
const local = (/** @type {unknown} */ each) => typeof each === 'string' && !/^[a-z][a-z0-9+.-]*:/i.test(each)
|
|
83
|
+
const entries = Object.entries(value).map(([key, each]) => [key, key === 'path' && local(each) ? join(folder, ...String(each).split('/')) : located(each, folder)])
|
|
84
|
+
return Object.fromEntries(entries)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The server and its four tools. It holds no rules of its own: the build, the read, their checks
|
|
89
|
+
* and the confinement to folders are h5p-author's, the check and the preview h5p-verify's.
|
|
70
90
|
* @param {ServerOptions} [options]
|
|
71
91
|
*/
|
|
72
92
|
export async function createServer(options = {}) {
|
|
@@ -134,6 +154,22 @@ export async function createServer(options = {}) {
|
|
|
134
154
|
}
|
|
135
155
|
}
|
|
136
156
|
|
|
157
|
+
/**
|
|
158
|
+
* A new folder beside a package for what a read writes, named after it, with a number added where
|
|
159
|
+
* the name is taken, as a build's package takes one; held while the read runs.
|
|
160
|
+
* @param {string} parent
|
|
161
|
+
* @param {string} stem
|
|
162
|
+
*/
|
|
163
|
+
async function freeFolder(parent, stem) {
|
|
164
|
+
for (let n = 1; ; n++) {
|
|
165
|
+
const path = join(parent, n === 1 ? stem : `${stem}-${n}`)
|
|
166
|
+
const taken = await lstat(path).then(() => true, () => false)
|
|
167
|
+
if (taken || building.has(path.toLowerCase())) continue
|
|
168
|
+
building.add(path.toLowerCase())
|
|
169
|
+
return path
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
137
173
|
server.registerTool('h5p_types', {
|
|
138
174
|
title: 'H5P content types',
|
|
139
175
|
description: TYPES,
|
|
@@ -219,6 +255,33 @@ export async function createServer(options = {}) {
|
|
|
219
255
|
return { content: [{ type: /** @type {const} */ ('text'), text: lines.join('\n') }, ...images] }
|
|
220
256
|
})
|
|
221
257
|
|
|
258
|
+
server.registerTool('h5p_read', {
|
|
259
|
+
title: 'Read an H5P package',
|
|
260
|
+
description: READ,
|
|
261
|
+
inputSchema: z.object({ package: z.string().describe('The .h5p by its file name alone, as the person names it, or its path in a folder this server may use') }),
|
|
262
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }
|
|
263
|
+
}, async ({ package: file }) => {
|
|
264
|
+
const allowed = await folders()
|
|
265
|
+
// A name alone is the first folder's, as a source's file is.
|
|
266
|
+
const path = resolve(allowed[0] ?? '.', file)
|
|
267
|
+
if (!allowed.length || !(await inside(path, allowed))) return refusal(`${file} is not in a folder this server may use.${allowed.length ? ` ${whereFiles(allowed)}` : ''}`)
|
|
268
|
+
const folder = await freeFolder(dirname(path), fileStem(basename(path).replace(/\.h5p$/i, '')))
|
|
269
|
+
let result
|
|
270
|
+
try {
|
|
271
|
+
result = await readPackage(path, folder, { within: allowed, libraries: options.libraries })
|
|
272
|
+
} catch (error) {
|
|
273
|
+
return refusal(error instanceof Error ? error.message : String(error))
|
|
274
|
+
} finally {
|
|
275
|
+
building.delete(folder.toLowerCase())
|
|
276
|
+
}
|
|
277
|
+
const media = result.files.length ? `, with its ${result.files.length} media file${result.files.length === 1 ? '' : 's'} beside it` : ''
|
|
278
|
+
const lines = [`Read ${path}: ${result.source.type}. Its source is in ${result.output}${media}.`]
|
|
279
|
+
for (const { path: at, message } of result.notes) lines.push(`Note: ${at} ${message}`)
|
|
280
|
+
const source = { ...result.source, params: located(result.source.params, folder) }
|
|
281
|
+
lines.push('', 'The source, each file named where it was written: change it as the person asks and pass it to h5p_build.', JSON.stringify(source))
|
|
282
|
+
return answer(lines.join('\n'))
|
|
283
|
+
})
|
|
284
|
+
|
|
222
285
|
server.registerTool('h5p_preview', {
|
|
223
286
|
title: 'Preview an H5P package',
|
|
224
287
|
description: PREVIEW,
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@missing-elements/h5p-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "H5P Author MCP by Missing Elements: a local MCP server that builds playable H5P packages of any content type from a short source, checks them in a real player and opens them in the person's browser. No H5P server needed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/missing-elements/h5p-
|
|
8
|
+
"url": "git+https://github.com/missing-elements/h5p-toolkit.git",
|
|
9
9
|
"directory": "packages/mcp"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/missing-elements/h5p-
|
|
11
|
+
"homepage": "https://github.com/missing-elements/h5p-toolkit/tree/main/packages/mcp#readme",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/missing-elements/h5p-
|
|
13
|
+
"url": "https://github.com/missing-elements/h5p-toolkit/issues"
|
|
14
14
|
},
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
40
40
|
"zod": "^4.6.7",
|
|
41
|
-
"@missing-elements/h5p-author": "^0.
|
|
41
|
+
"@missing-elements/h5p-author": "^0.13.0",
|
|
42
42
|
"@missing-elements/h5p-verify": "^1.6.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|