glitchless-mcp 0.21.0 → 0.23.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 +48 -8
- package/package.json +4 -4
- package/src/context.js +180 -38
- package/src/hosted-tools.js +1 -0
- package/src/http.js +8 -6
- package/src/index.js +6 -2
- package/src/login.js +31 -3
- package/src/request-state.js +47 -0
- package/src/served-skills.js +77 -0
- package/src/skills.js +10 -6
- package/src/tasks.js +123 -0
- package/src/tools/analytics.js +1 -1
- package/src/tools/core.js +2 -2
- package/src/tools/dashboard.js +1 -1
- package/src/tools/feedback.js +131 -0
- package/src/tools/multiplayer.js +8 -2
- package/src/tools/playtest.js +29 -15
- package/src/tools/store-reviews.js +2 -2
- package/src/tools/workspace.js +132 -15
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The state a tool hands a client with a question (MCP's requestState, on an input_required answer), sealed so the
|
|
2
|
+
// client can't make it up: the answer comes back as a call of its own with the state echoed, and the tool acts on it
|
|
3
|
+
// only when the seal holds, it hasn't expired and it's for this same request. On stdio the seal's key is a secret of
|
|
4
|
+
// this process, which the client's next call reaches; over HTTP, where each request gets a server of its own, it's
|
|
5
|
+
// derived from the connection's workspace key, which the hosted server holds and its OAuth clients never see.
|
|
6
|
+
import crypto from 'node:crypto';
|
|
7
|
+
import { apiKey, isRemote } from './context.js';
|
|
8
|
+
|
|
9
|
+
const PROCESS_SECRET = crypto.randomBytes(32);
|
|
10
|
+
export const STATE_LIMITS = { ttlMs: 10 * 60_000 };
|
|
11
|
+
|
|
12
|
+
const keyNow = () => (isRemote() && apiKey() ? crypto.createHmac('sha256', apiKey()).update('glitchless-mcp requestState v1').digest() : PROCESS_SECRET);
|
|
13
|
+
const sign = (body) => crypto.createHmac('sha256', keyNow()).update(body).digest('base64url');
|
|
14
|
+
|
|
15
|
+
// payload (JSON) → the state string: its body, then its seal. It carries kind, an expiry and a one-time nonce.
|
|
16
|
+
export function sealState(kind, payload) {
|
|
17
|
+
const body = Buffer.from(JSON.stringify({ ...payload, k: kind, exp: Date.now() + STATE_LIMITS.ttlMs, n: crypto.randomBytes(12).toString('base64url') })).toString('base64url');
|
|
18
|
+
return `${body}.${sign(body)}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The state a call carries → its payload, or null when it's missing, made up, for another kind or expired.
|
|
22
|
+
export function openState(kind, state) {
|
|
23
|
+
if (typeof state !== 'string') return null;
|
|
24
|
+
const [body, seal, extra] = state.split('.');
|
|
25
|
+
if (!body || !seal || extra !== undefined) return null;
|
|
26
|
+
const want = Buffer.from(sign(body));
|
|
27
|
+
const got = Buffer.from(seal);
|
|
28
|
+
if (want.length !== got.length || !crypto.timingSafeEqual(want, got)) return null;
|
|
29
|
+
let payload;
|
|
30
|
+
try {
|
|
31
|
+
payload = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (payload?.k !== kind || !(payload.exp > Date.now())) return null;
|
|
36
|
+
return payload;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A yes counts once: a nonce, once acted on, is spent until its state would have expired anyway. Kept in this
|
|
40
|
+
// process's memory, so over HTTP it holds per server instance; the short expiry bounds the rest.
|
|
41
|
+
const spent = new Map();
|
|
42
|
+
export function spend(payload) {
|
|
43
|
+
for (const [n, exp] of spent) if (exp <= Date.now()) spent.delete(n);
|
|
44
|
+
if (spent.has(payload.n)) return false;
|
|
45
|
+
spent.set(payload.n, payload.exp);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The Glitchless skills over MCP's Skills extension (io.modelcontextprotocol/skills, SEP-2640): a client that loads
|
|
2
|
+
// skills from its MCP servers lists them with skills/list and reads their files as skill:// resources, so an agent
|
|
3
|
+
// connected to the hosted server or to glitchless-mcp gets the skills the Claude Code plugin carries, without the
|
|
4
|
+
// plugin. Claude Code shows them as /<server>:<skill> (/glitchless:triage; a claude.ai connector's as
|
|
5
|
+
// /claude_ai_Glitchless:triage). The text and the list of skills are skills.js, the copy
|
|
6
|
+
// scripts/sync-agent-plugin.mjs writes from plugin/glitchless/skills, so the hosted server reads nothing from disk.
|
|
7
|
+
//
|
|
8
|
+
// A connection is served the skills whose tools it has (SKILLS: instrument needs manage, dashboard the dashboard
|
|
9
|
+
// scope) and, only on this computer, the ones that act on it (deck). Every set a connection can get is built once,
|
|
10
|
+
// when this module loads, and serves every server createServer() builds (one per HTTP request): a catalog keeps each
|
|
11
|
+
// file's size and digest, which clients check every file they read against. Clients without the extension never ask
|
|
12
|
+
// for skills, and get the same text from glitchless_create_game's engine and glitchless_dashboard's guide.
|
|
13
|
+
//
|
|
14
|
+
// The skills never hold the tools up: if the SDK refuses a skill, or a later SDK changed how catalogs load or attach,
|
|
15
|
+
// the server serves none and says why on stderr.
|
|
16
|
+
import { SKILLS, TEXTS } from './skills.js';
|
|
17
|
+
|
|
18
|
+
const FROM = 'plugin/glitchless/skills/';
|
|
19
|
+
const SCOPES = ['read', 'dashboard', 'manage'];
|
|
20
|
+
|
|
21
|
+
// The skills a connection is served: remote and scopes as createServer's.
|
|
22
|
+
export function skillsFor({ remote = false, scopes = null } = {}, skills = SKILLS) {
|
|
23
|
+
return Object.entries(skills)
|
|
24
|
+
.filter(([, s]) => s.scope && !(remote && s.local) && (!scopes || scopes.includes(s.scope)))
|
|
25
|
+
.map(([name]) => name);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A set of skills' files, keyed by their path in the skills folder ("triage/SKILL.md").
|
|
29
|
+
const filesOf = (skills, texts) =>
|
|
30
|
+
Object.fromEntries(
|
|
31
|
+
Object.entries(texts)
|
|
32
|
+
.filter(([p]) => skills.some((s) => p.startsWith(`${FROM}${s}/`)))
|
|
33
|
+
.map(([p, text]) => [p.slice(FROM.length), text]),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const warn = (what, err, log = console.error) => log(`glitchless-mcp: serving no skills: ${what}: ${err?.problems?.map((p) => `${p.path}: ${p.message}`).join('; ') || err?.message || err}`);
|
|
37
|
+
|
|
38
|
+
// Every set a connection can be served, by its skills' names (here and remote, with every combination of scopes), as
|
|
39
|
+
// a catalog: Map { 'instrument,dashboard,triage' → catalog }. strict: a skill the extension would otherwise skip with a
|
|
40
|
+
// warning fails the load (the sync script refuses one first). Any failure gives an empty Map and a warning, never a
|
|
41
|
+
// throw.
|
|
42
|
+
export async function buildCatalogs({ skills = SKILLS, texts = TEXTS, log } = {}) {
|
|
43
|
+
const catalogs = new Map();
|
|
44
|
+
try {
|
|
45
|
+
// Imported here, so an SDK without the extension serves no skills rather than stopping the server loading.
|
|
46
|
+
const { SkillsExtension, memorySkillFiles } = await import('@modelcontextprotocol/server/ext/skills');
|
|
47
|
+
const sets = new Map();
|
|
48
|
+
for (const remote of [false, true])
|
|
49
|
+
for (const scopes of [null, ...Array.from({ length: 2 ** SCOPES.length }, (_, n) => SCOPES.filter((_, i) => n & (1 << i)))]) {
|
|
50
|
+
const set = skillsFor({ remote, scopes }, skills);
|
|
51
|
+
if (set.length) sets.set(set.join(), set);
|
|
52
|
+
}
|
|
53
|
+
for (const [key, set] of sets) catalogs.set(key, await SkillsExtension.load(memorySkillFiles(filesOf(set, texts)), { strict: true }));
|
|
54
|
+
} catch (err) {
|
|
55
|
+
catalogs.clear();
|
|
56
|
+
warn('the skills did not load', err, log);
|
|
57
|
+
}
|
|
58
|
+
return catalogs;
|
|
59
|
+
}
|
|
60
|
+
const catalogs = await buildCatalogs();
|
|
61
|
+
|
|
62
|
+
// The skills a server built with these options serves: { uri, frontmatter, resources }, as skills/list answers.
|
|
63
|
+
export const skillEntries = (options) => catalogs.get(skillsFor(options).join())?.entries ?? [];
|
|
64
|
+
|
|
65
|
+
// Serves a connection's skills on its server, before it connects. They never change while it runs, so it says no
|
|
66
|
+
// resource-list changes come (attaching would say they do): as with tools (createServer), a client that is promised
|
|
67
|
+
// them opens a stream and waits on it. A connection with no skills to serve gets no extension and no resources.
|
|
68
|
+
export function serveSkills(server, options = {}, { from = catalogs, log } = {}) {
|
|
69
|
+
const catalog = from.get(skillsFor(options).join());
|
|
70
|
+
if (!catalog) return;
|
|
71
|
+
try {
|
|
72
|
+
server.server.registerCapabilities({ resources: { listChanged: false } });
|
|
73
|
+
catalog.attach(server);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
warn('attaching them failed', err, log);
|
|
76
|
+
}
|
|
77
|
+
}
|