glitchless-mcp 0.1.2 → 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.
Files changed (3) hide show
  1. package/README.md +4 -1
  2. package/package.json +4 -2
  3. package/src/index.js +162 -17
package/README.md CHANGED
@@ -64,7 +64,10 @@ above go in its environment.
64
64
  | `glitchless_get_error` | One error issue, with its stack and the gameplay before it |
65
65
  | `glitchless_player_funnel` | Per level: starts, completions, deaths and their causes, rage quits |
66
66
  | `glitchless_death_hotspots` | Where players die on a level, clustered in world coordinates |
67
- | `glitchless_compare_versions` | Two or more versions side by side, to confirm a fix with real players |
67
+ | `glitchless_events` | The game's own events (whatever it sends with `track`): counts, attribute breakdowns and funnels |
68
+ | `glitchless_dashboard` | The game's dashboard: its pages, and one board's panels with their numbers |
69
+ | `glitchless_set_dashboard` | Save the game's pages: boards of panels in its own words, and the built-in views it keeps. Needs a key with the dashboard scope |
70
+ | `glitchless_compare_versions` | Two or more versions side by side, in the game's own stats first, to confirm a fix with real players |
68
71
  | `glitchless_session` | One play session in detail, with its whole event timeline |
69
72
  | `glitchless_playtest` | Autoplay bots play the game and compare with a saved baseline ([glitchless-playtest](https://www.npmjs.com/package/glitchless-playtest); needs Playwright in the game project) |
70
73
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "glitchless-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "mcpName": "io.github.glitchless-gg/glitchless",
5
- "description": "Game observability MCP server: lets coding agents (Claude Code, Codex, Cursor and others) read your game's player telemetry and ranked findings, and run playtest bots.",
5
+ "description": "Game observability MCP server: lets coding agents (Claude Code, Codex, Cursor and others) read your game's player telemetry and ranked findings, design its own dashboard, and run playtest bots.",
6
6
  "keywords": [
7
7
  "mcp",
8
8
  "mcp-server",
@@ -10,6 +10,8 @@
10
10
  "game-observability",
11
11
  "observability",
12
12
  "gamedev",
13
+ "game-analytics",
14
+ "dashboard",
13
15
  "game-development",
14
16
  "threejs",
15
17
  "godot",
package/src/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  //
7
7
  // claude mcp add glitchless -e GLITCHLESS_URL=http://localhost:7777 -- npx -y glitchless-mcp
8
8
 
9
+ import { AsyncLocalStorage } from 'node:async_hooks';
9
10
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
10
11
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
11
12
  import { z } from 'zod';
@@ -16,10 +17,10 @@ const API_KEY = process.env.GLITCHLESS_API_KEY || '';
16
17
  const DEFAULT_SERVICE = process.env.GLITCHLESS_SERVICE || '';
17
18
 
18
19
  const server = new McpServer(
19
- { name: 'glitchless', version: '0.1.2' },
20
+ { name: 'glitchless', version: '0.2.0' },
20
21
  {
21
22
  instructions:
22
- 'Glitchless is observability for games made with Three.js, Phaser, Unity or Godot. Start with glitchless_triage to get ranked, evidence-backed findings for a game, then drill in with glitchless_performance, glitchless_get_error, glitchless_death_hotspots or glitchless_session. Before changing game code, run glitchless_playtest with save_as "baseline"; after the change, run glitchless_playtest again to compare, and treat a FAIL as unfinished work. After shipping a fix (bump the version passed to Glitchless.init), use glitchless_compare_versions to confirm it with real players. If the game is running in a browser with WebMCP connected, its live tools (glitchless_live_performance, glitchless_measure, glitchless_inspect_scene, and game tools such as zoomies_load_level) let you reproduce and measure issues directly. Unity and Godot builds measure themselves when run with --glitchless-measure=SECONDS.',
23
+ 'Glitchless is observability for games made with Three.js, Phaser, Unity or Godot. Start with glitchless_triage to get ranked, evidence-backed findings for a game, then drill in with glitchless_performance, glitchless_get_error, glitchless_death_hotspots or glitchless_session. For metrics the game defines itself (what it sends with track(): plays, purchases, paywall views and so on) and funnels between them, use glitchless_events. Each game has its own dashboard, a list of pages (boards of panels, and built-in views such as Errors, Sessions and Live Tail): read it with glitchless_dashboard, and after instrumenting a game, design one that fits it with glitchless_set_dashboard. Before changing game code, run glitchless_playtest with save_as "baseline"; after the change, run glitchless_playtest again to compare, and treat a FAIL as unfinished work. After shipping a fix (bump the version passed to Glitchless.init), use glitchless_compare_versions to confirm it with real players. If the game is running in a browser with WebMCP connected, its live tools (glitchless_live_performance, glitchless_measure, glitchless_inspect_scene, and game tools such as zoomies_load_level) let you reproduce and measure issues directly. Unity and Godot builds measure themselves when run with --glitchless-measure=SECONDS.',
23
24
  },
24
25
  );
25
26
 
@@ -31,7 +32,39 @@ async function query(name, params = {}) {
31
32
  headers: { 'x-glitchless-client': client, ...(API_KEY ? { 'x-glitchless-api-key': API_KEY } : {}) },
32
33
  });
33
34
  if (!res.ok) throw new Error(`Glitchless API ${name} → HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`);
34
- return res.json();
35
+ const data = await res.json();
36
+ const call = calls.getStore();
37
+ if (call && data?.meta) Object.assign(call, { meta: data.meta, from: params.from });
38
+ return data;
39
+ }
40
+
41
+ // The tool call being answered: the meta of its last query, for windowNote().
42
+ const calls = new AsyncLocalStorage();
43
+
44
+ // How the window was answered, when an agent should know: by day past 31 days, what is estimated, what a
45
+ // view covers, a range cut to the plan's retention.
46
+ function windowNote() {
47
+ const { meta, from } = calls.getStore() || {};
48
+ if (!meta) return '';
49
+ const parts = [];
50
+ if (meta.resolution === 'day') parts.push('answered by day: each session counts on the day it started');
51
+ if (meta.approximate?.length) parts.push(`estimated (sketches or samples): ${meta.approximate.join(', ')}`);
52
+ if (meta.note) parts.push(meta.note);
53
+ if (meta.retention_days && from != null && meta.from - from > 86400e3) parts.push(`the plan keeps ${meta.retention_days} days of data, so the window starts ${new Date(meta.from).toISOString().slice(0, 10)}`);
54
+ return parts.length ? `\n(Note: ${parts.join('; ')}.)` : '';
55
+ }
56
+
57
+ async function write(method, path, body) {
58
+ const client = server.server.getClientVersion?.()?.name || 'mcp';
59
+ const res = await fetch(`${BASE}${path}`, {
60
+ method,
61
+ headers: { 'content-type': 'application/json', 'x-glitchless-client': client, ...(API_KEY ? { 'x-glitchless-api-key': API_KEY } : {}) },
62
+ ...(body ? { body: JSON.stringify(body) } : {}),
63
+ });
64
+ const data = await res.json().catch(() => ({}));
65
+ if (res.status === 403) throw new Error(`${data.error || 'forbidden'}. Saving a dashboard needs a secret key with the dashboard scope (create one in the dashboard's settings).`);
66
+ if (!res.ok) throw new Error(`Glitchless API ${method} ${path} → HTTP ${res.status}: ${data.error || ''}`);
67
+ return data;
35
68
  }
36
69
 
37
70
  async function resolveService(service) {
@@ -48,7 +81,7 @@ function range(hours = 24) {
48
81
  }
49
82
 
50
83
  function reply(title, data) {
51
- return { content: [{ type: 'text', text: `${title}\n\n${JSON.stringify(data, null, 2)}` }] };
84
+ return { content: [{ type: 'text', text: `${title}${windowNote()}\n\n${JSON.stringify(data, null, 2)}` }] };
52
85
  }
53
86
 
54
87
  function fail(err) {
@@ -57,18 +90,25 @@ function fail(err) {
57
90
 
58
91
  const common = {
59
92
  service: z.string().optional().describe('Game service name (defaults to the most recently active game)'),
60
- hours: z.number().min(0.25).max(168).optional().describe('Look-back window in hours (default 24)'),
93
+ hours: z
94
+ .number()
95
+ .min(0.25)
96
+ .max(9600)
97
+ .optional()
98
+ .describe("Look-back window in hours (default 24). Up to the plan's retention on Glitchless Cloud: 336 (14 days) on Free, 2160 (90 days) on Indie, 9600 (400 days) on Studio. Past 744 (31 days) answers are by day."),
61
99
  version: z.string().optional().describe('Only include sessions from this game version'),
62
100
  };
63
101
 
64
102
  function tool(name, description, schema, handler) {
65
- server.registerTool(name, { description, inputSchema: schema, annotations: { readOnlyHint: true } }, async (args) => {
66
- try {
67
- return await handler(args || {});
68
- } catch (err) {
69
- return fail(err);
70
- }
71
- });
103
+ server.registerTool(name, { description, inputSchema: schema, annotations: { readOnlyHint: true } }, async (args) =>
104
+ calls.run({}, async () => {
105
+ try {
106
+ return await handler(args || {});
107
+ } catch (err) {
108
+ return fail(err);
109
+ }
110
+ }),
111
+ );
72
112
  }
73
113
 
74
114
  tool('glitchless_list_games', 'List the games reporting to Glitchless, with their versions, environments and when they were last seen.', {}, async () => {
@@ -138,6 +178,107 @@ tool('glitchless_player_funnel', 'Player experience per level: sessions that sta
138
178
  return reply(`Player funnel for ${svc}`, { kpis: d.kpis, funnel: d.funnel, session_length: d.session_length, recent_rage_quits: d.rage_quits.slice(0, 15) });
139
179
  });
140
180
 
181
+ tool(
182
+ 'glitchless_events',
183
+ "The game's own metrics, from the custom events it sends with track(): each event's count in the window, the sessions and players that sent it, and how its attribute values break down (for example plays by mode, paywall views by placement, purchases started vs done). Give `funnel` to count the sessions that went from one event to the next, in that order.",
184
+ {
185
+ ...common,
186
+ name: z.string().optional().describe('Only this event, e.g. "paywall"'),
187
+ funnel: z.string().optional().describe('Steps in order, comma-separated: "open,paywall,buy". A step can require a value: "buy=done" (any attribute) or "buy:step=done"'),
188
+ },
189
+ async ({ service, hours, version, name, funnel }) => {
190
+ const svc = await resolveService(service);
191
+ const d = await query('events', { service: svc, version, name, funnel, ...range(hours) });
192
+ const brief = d.events
193
+ .slice(0, 15)
194
+ .map((e) => `${e.name}: ${e.count} in ${e.sessions} session(s)`)
195
+ .join('\n');
196
+ return reply(`Custom events for ${svc} (${hours || 24}h, ${d.sessions} sessions):\n${brief || 'None in this window. A game sends them with track(name, attrs).'}`, {
197
+ events: d.events.map(({ series, ...e }) => e),
198
+ ...(d.funnel ? { funnel: d.funnel } : {}),
199
+ });
200
+ },
201
+ );
202
+
203
+ tool(
204
+ 'glitchless_dashboard',
205
+ "The game's dashboard: its pages in order, each a board (panels in the game's own terms) or a built-in view (events, performance, errors, players, heatmaps, sessions, versions, live), and one board's panels with their numbers for the window. `page` picks the board (default: the first). `source` says whether the dashboard was saved (by an agent or a person) or made automatically from what the game sends; `spec` is what to edit and send back to glitchless_set_dashboard.",
206
+ { ...common, page: z.string().optional().describe('Id of the board page to evaluate (default: the first board)') },
207
+ async ({ service, hours, version, page }) => {
208
+ const svc = await resolveService(service);
209
+ const { dashboard } = await query('dashboard', { service: svc, version, ...range(hours) });
210
+ if (!dashboard) return reply(`${svc} has sent no data yet`, {});
211
+ const b = await query('board', { service: svc, version, page, ...range(hours) });
212
+ const pages = dashboard.pages.map((p) => ({ id: p.id, title: p.title, ...(p.view ? { view: p.view, ...(p.options ? { options: p.options } : {}) } : { panels: p.panels }) }));
213
+ const board = b.board ? { page: b.board.page, title: b.board.title, panels: b.board.panels.map(({ ts, series, p50, p95, ...p }) => p) } : { error: b.error };
214
+ return reply(`Dashboard for ${svc} (${dashboard.source}${dashboard.updated_by ? `, saved by ${dashboard.updated_by}` : ''}):`, { pages, board, spec: dashboard.spec });
215
+ },
216
+ );
217
+
218
+ const panelSchema = z
219
+ .object({
220
+ type: z.enum(['stat', 'series', 'breakdown', 'funnel', 'levels', 'frame_time', 'errors', 'deaths', 'events', 'findings', 'sessions', 'versions', 'live']),
221
+ title: z.string().optional().describe("In the game's own words, e.g. \"Stops won vs lost\""),
222
+ note: z.string().optional().describe('One line on why this panel matters'),
223
+ size: z.enum(['s', 'm', 'l']).optional().describe('s = a quarter row (stats), m = half, l = full width'),
224
+ metric: z.string().optional().describe('stat: sessions, players, avg_session_s, crash_free_pct, error_free_pct, frame_p95, avg_fps, hitches_per_min, errors, deaths or rage_quit_pct'),
225
+ event: z.string().optional().describe('stat, series, breakdown: one event, "name", "name=value" or "name:key=value"'),
226
+ per: z.string().optional().describe('stat: divide by this event to get a percentage, e.g. event "buy=done" per "paywall"'),
227
+ by: z.string().optional().describe('series, breakdown: the attribute to split by, e.g. "mode" or "what", or $version / $level'),
228
+ limit: z.number().int().optional(),
229
+ steps: z.string().optional().describe('funnel: events in order, comma-separated, e.g. "paywall,buy=tapped,buy=done"'),
230
+ label: z.string().optional().describe('levels: what the game calls a level, e.g. "Stop" or "Puzzle"'),
231
+ sent: z.string().optional().describe('sessions: only sessions that sent this event, e.g. "buy=done"'),
232
+ events: z.array(z.string()).optional().describe('live: only these event names or types, e.g. ["buy", "paywall", "error"]'),
233
+ })
234
+ .describe('One panel');
235
+
236
+ const pageSchema = z
237
+ .object({
238
+ id: z.string().optional().describe('Short id used in the page address, e.g. "money" (default: from the title)'),
239
+ title: z.string().optional().describe('The name in the sidebar, in the words the game uses (a view keeps its built-in name without one)'),
240
+ icon: z.enum(['board', 'overview', 'events', 'perf', 'errors', 'players', 'heatmap', 'sessions', 'versions', 'live', 'flag', 'bolt', 'play', 'clock']).optional(),
241
+ panels: z.array(panelSchema).optional().describe('A board: its panels, in order'),
242
+ view: z.enum(['events', 'performance', 'errors', 'players', 'heatmaps', 'sessions', 'versions', 'live']).optional().describe('A built-in view instead of panels'),
243
+ options: z.object({ events: z.array(z.string()).optional() }).optional().describe('live view: events, only these event names or types'),
244
+ })
245
+ .describe('One page: either panels (a board) or view (a built-in view)');
246
+
247
+ server.registerTool(
248
+ 'glitchless_set_dashboard',
249
+ {
250
+ description:
251
+ "Save the game's dashboard: its pages, in the order the sidebar shows them. Each page is a board of panels in the game's own words, or a built-in view (events, performance, errors, players, heatmaps, sessions, versions, live) the game keeps, renames or drops. Design it for this game, not for a genre it isn't: a puzzle game cares about solve time and hints, a mobile game about opens, modes, the paywall and purchases, a platformer about deaths per level. The first page opens first. Use the events the game sends (glitchless_events lists them, with their attributes); on a board, stats first, then the game's own events and funnels, then levels, frame_time and errors. Leave out what the game has no data for (no Heatmaps page for a game without positions). Send every page: read the current ones with glitchless_dashboard (its spec), change them, send them all back. Pass reset: true to go back to the automatic dashboard. Needs a secret key with the dashboard scope.",
252
+ inputSchema: {
253
+ service: z.string().optional().describe('Game service name (defaults to the most recently active game)'),
254
+ pages: z.array(pageSchema).optional(),
255
+ reset: z.boolean().optional().describe('Delete the saved dashboard and go back to the automatic one'),
256
+ },
257
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
258
+ },
259
+ async ({ service, pages, reset }) => {
260
+ try {
261
+ const svc = await resolveService(service);
262
+ if (!reset && !pages?.length) throw new Error('give pages, or reset: true');
263
+ const res = await write(reset ? 'DELETE' : 'PUT', `/v1/dashboard?service=${encodeURIComponent(svc)}`, reset ? null : { pages });
264
+ if (reset) return reply(`Dashboard for ${svc} reset to automatic.`, {});
265
+ // How each board looks with the last 7 days, so empty panels show up now rather than in the dashboard.
266
+ const lines = [];
267
+ for (const p of res.dashboard.pages) {
268
+ if (p.view) {
269
+ lines.push(`${p.title} (built-in ${p.view} view)`);
270
+ continue;
271
+ }
272
+ const { board } = await query('board', { service: svc, page: p.id, ...range(168) });
273
+ lines.push(`${p.title}:`, ...board.panels.map((x) => ` - ${x.title}${x.empty ? ` (no data yet: ${x.why})` : ''}`));
274
+ }
275
+ return reply(`Saved the dashboard for ${svc} (${res.dashboard.pages.length} pages). How it looks with the last 7 days:\n${lines.join('\n')}`, {});
276
+ } catch (err) {
277
+ return fail(err);
278
+ }
279
+ },
280
+ );
281
+
141
282
  tool(
142
283
  'glitchless_death_hotspots',
143
284
  'Where players die on a level: clustered death positions in world coordinates (x range, share of the level’s deaths, top cause, rage quits at that spot), plus the level bounds and completion stats. Use it to find difficulty spikes, then look up the level data around those coordinates.',
@@ -151,19 +292,23 @@ tool(
151
292
 
152
293
  tool(
153
294
  'glitchless_compare_versions',
154
- 'Compare game versions side by side: p50/p95/p99 frame time (overall and per level), hitches/min, crash-free and error-free sessions, errors per session, level completion, rage-quit rate, deaths per session and geometry growth per level load. Use it to confirm a fix after shipping a new version.',
295
+ 'Compare game versions side by side, in the game\'s own terms first: the stats on its boards (glitchless_dashboard) and its own events per session, then the built-in measures it reports (frame time overall and per level, hitches/min, crash-free and error-free sessions, errors per session, level completion, rage-quit rate, deaths per session, geometry growth). Use it to confirm a fix or a design change after shipping a new version.',
155
296
  { service: common.service, hours: common.hours, a: z.string().optional().describe('Baseline version (default: second newest)'), b: z.string().optional().describe('New version (default: newest)') },
156
297
  async ({ service, hours, a, b }) => {
157
298
  const svc = await resolveService(service);
158
- const { versions } = await query('versions', { service: svc, ...range(hours || 72) });
299
+ const { versions, has = {}, board = [] } = await query('versions', { service: svc, ...range(hours || 72) });
159
300
  if (versions.length < 2 && !(a && b)) return reply(`Only one version of ${svc} has reported in this window`, versions);
160
301
  const va = versions.find((v) => v.version === a) || versions.at(-2);
161
302
  const vb = versions.find((v) => v.version === b) || versions.at(-1);
162
- const keys = ['frame_p50', 'frame_p95', 'frame_p99', 'hitches_per_min', 'crash_free_pct', 'error_free_pct', 'errors_per_session', 'level_completion_pct', 'rage_quit_pct', 'deaths_per_session', 'geometries_growth_per_level_load'];
163
- const delta = Object.fromEntries(keys.map((k) => [k, { [va.version]: va[k], [vb.version]: vb[k], change: va[k] != null && vb[k] != null ? Math.round((vb[k] - va[k]) * 100) / 100 : null }]));
303
+ const pair = (x, y) => ({ [va.version]: x ?? null, [vb.version]: y ?? null, change: x != null && y != null ? Math.round((y - x) * 100) / 100 : null });
304
+ // Only the measures this game reports: no frame times for a game that sends none.
305
+ const keys = [...(has.frames ? ['frame_p50', 'frame_p95', 'frame_p99', 'hitches_per_min'] : []), 'crash_free_pct', 'error_free_pct', 'errors_per_session', ...(has.levels ? ['level_completion_pct'] : []), ...(has.deaths || has.fails ? ['rage_quit_pct'] : []), ...(has.deaths ? ['deaths_per_session'] : []), ...(has.geometry ? ['geometries_growth_per_level_load'] : [])];
306
+ const delta = Object.fromEntries(keys.map((k) => [k, pair(va[k], vb[k])]));
307
+ const own = Object.fromEntries(board.map((s, i) => [s.unit === 'per session' ? `${s.title} (per session)` : s.title, pair(va.board?.[i], vb.board?.[i])]));
308
+ const events = Object.fromEntries(Object.keys(vb.events || va.events || {}).map((n) => [n, pair(va.events?.[n], vb.events?.[n])]));
164
309
  const levels = [...new Set([...Object.keys(va.level_p95 || {}), ...Object.keys(vb.level_p95 || {})])];
165
310
  const level_p95 = Object.fromEntries(levels.map((l) => [l, { [va.version]: va.level_p95?.[l] ?? null, [vb.version]: vb.level_p95?.[l] ?? null }]));
166
- return reply(`${svc}: ${va.version} (${va.sessions} sessions) vs ${vb.version} (${vb.sessions} sessions)`, { delta, level_p95, all_versions: versions.map((v) => ({ version: v.version, sessions: v.sessions, first_seen: new Date(v.first_seen).toISOString() })) });
311
+ return reply(`${svc}: ${va.version} (${va.sessions} sessions) vs ${vb.version} (${vb.sessions} sessions)`, { board: own, events_per_session: events, delta, level_p95, all_versions: versions.map((v) => ({ version: v.version, sessions: v.sessions, first_seen: new Date(v.first_seen).toISOString() })) });
167
312
  },
168
313
  );
169
314