glitchless-mcp 0.14.0 → 0.14.1

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 CHANGED
@@ -28,7 +28,8 @@ every tool takes `game` (a name or id). The key acts as you, with your role in t
28
28
  or touches billing or people. `npx -y glitchless-mcp whoami` shows where you're signed in, `logout` deletes the saved
29
29
  key, and Settings → Keys & access in the dashboard lists and revokes keys. An agent can also sign in from inside a
30
30
  chat with the `glitchless_sign_in` tool: it shows the link and code, and the running server switches over once you
31
- approve.
31
+ approve. The saved key is only ever sent to the server it was saved for: point `GLITCHLESS_URL` at another one (a
32
+ meetup's own box) and the MCP server connects without it, so set `GLITCHLESS_API_KEY` if that server has a key.
32
33
 
33
34
  ## Serve it over HTTP yourself
34
35
 
@@ -46,7 +47,7 @@ clients send it as `Authorization: Bearer`.
46
47
 
47
48
  | Variable | What |
48
49
  | --- | --- |
49
- | `GLITCHLESS_URL` | Your Glitchless server. Default: the signed-in workspace's, else `http://localhost:7777` |
50
+ | `GLITCHLESS_URL` | Your Glitchless server. Default: the signed-in workspace's, else `http://localhost:7777`. A saved sign-in goes only to the server it was saved for |
50
51
  | `GLITCHLESS_API_KEY` | A key, if the server needs one: a workspace key (`gl_ws_…`) for every game, or a secret key (`gl_sk_…`) for one. Overrides a sign-in. Keep it out of git and out of the game |
51
52
  | `GLITCHLESS_GAME` | With a workspace key, the game to use when a call doesn't name one. Optional |
52
53
  | `GLITCHLESS_SERVICE` | The service to use when a call doesn't name one. Optional |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitchless-mcp",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "mcpName": "io.github.glitchless-gg/glitchless",
5
5
  "description": "Coding agents can build a game. They can't see anyone play it. Glitchless lets them. The MCP server for Glitchless, game observability for coding agents: Claude Code, Codex, Cursor and others read real players' stutters, crashes, custom metrics and ranked findings in Unity, Godot, Unreal, Three.js, Phaser and GameMaker games, build the game's own dashboard, and run playtest bots.",
6
6
  "keywords": [
package/src/context.js CHANGED
@@ -9,7 +9,7 @@ import path from 'node:path';
9
9
  import { McpServer } from '@modelcontextprotocol/server';
10
10
  import { z } from 'zod';
11
11
 
12
- export const VERSION = '0.14.0';
12
+ export const VERSION = '0.14.1';
13
13
 
14
14
  // Where `glitchless-mcp login` keeps its workspace key: { url, token, workspace: { id, name }, scopes }.
15
15
  export const CREDENTIALS_FILE = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'glitchless', 'credentials.json');
@@ -28,15 +28,34 @@ export function connection({ base, apiKey = '', service = '', game = '', fetch =
28
28
  return { base: String(base).replace(/\/$/, ''), apiKey, service, game, fetch, client, games: null };
29
29
  }
30
30
 
31
- // On stdio, the one connection: GLITCHLESS_API_KEY wins; without it, a saved sign-in. Over HTTP each request runs
32
- // with the connection its bearer token gives (createServer's `connection`).
33
- const saved = process.env.GLITCHLESS_API_KEY ? null : readCredentials();
34
- const local = connection({
35
- base: process.env.GLITCHLESS_URL || saved?.url || 'http://localhost:7777',
36
- apiKey: process.env.GLITCHLESS_API_KEY || saved?.token || '',
37
- service: process.env.GLITCHLESS_SERVICE || '',
38
- game: process.env.GLITCHLESS_GAME || '',
39
- });
31
+ const originOf = (u) => {
32
+ try {
33
+ return new URL(u).origin;
34
+ } catch {
35
+ return null;
36
+ }
37
+ };
38
+
39
+ // On stdio, the one connection: GLITCHLESS_URL and GLITCHLESS_API_KEY win, else the saved sign-in. A saved key goes
40
+ // only to the server it was saved for, so pointing GLITCHLESS_URL at a meetup's own server never hands it a Glitchless
41
+ // Cloud key: the connection goes without one (an open self-hosted server needs none), and `savedFor`, the origin the
42
+ // sign-in is for, says why on a 401. Over HTTP each request runs with the connection its bearer token gives
43
+ // (createServer's `connection`).
44
+ export function stdioConnection(env = process.env) {
45
+ const saved = env.GLITCHLESS_API_KEY ? null : readCredentials();
46
+ const savedAt = saved?.token ? originOf(saved.url) : null;
47
+ const fits = Boolean(saved?.token) && (!env.GLITCHLESS_URL || (savedAt !== null && originOf(env.GLITCHLESS_URL) === savedAt));
48
+ return {
49
+ ...connection({
50
+ base: env.GLITCHLESS_URL || (fits ? saved.url : '') || 'http://localhost:7777',
51
+ apiKey: env.GLITCHLESS_API_KEY || (fits ? saved.token : ''),
52
+ service: env.GLITCHLESS_SERVICE || '',
53
+ game: env.GLITCHLESS_GAME || '',
54
+ }),
55
+ savedFor: saved?.token && !fits ? (savedAt ?? String(saved.url)) : null,
56
+ };
57
+ }
58
+ const local = stdioConnection();
40
59
  const connections = new AsyncLocalStorage();
41
60
  const conn = () => connections.getStore() ?? local;
42
61
 
@@ -47,7 +66,13 @@ export const isWorkspace = () => conn().apiKey.startsWith('gl_ws_');
47
66
 
48
67
  // After a sign-in from inside the agent (glitchless_sign_in): the running server switches to the new key.
49
68
  export function useCredentials({ url, token }) {
50
- Object.assign(local, { base: String(url).replace(/\/$/, ''), apiKey: token, games: null });
69
+ Object.assign(local, { base: String(url).replace(/\/$/, ''), apiKey: token, games: null, savedFor: null });
70
+ }
71
+
72
+ // What a 401 adds when the saved sign-in was kept from this server: where it's for, and how to give this one a key.
73
+ function signInHint(status) {
74
+ const { savedFor, base: at } = conn();
75
+ return status === 401 && savedFor ? ` The saved sign-in is for ${savedFor} and isn't sent to another server: set GLITCHLESS_API_KEY for ${at}.` : '';
51
76
  }
52
77
 
53
78
  // The games a workspace key reaches, cached briefly; the game each call names (by name or id), else the one the
@@ -104,7 +129,7 @@ export async function query(name, params = {}) {
104
129
  const qs = new URLSearchParams();
105
130
  for (const [k, v] of Object.entries(params)) if (v != null && v !== '') qs.set(k, String(v));
106
131
  const res = await conn().fetch(`${base()}/v1/query/${name}?${qs}`, { headers: await headers() });
107
- if (!res.ok) throw new Error(`Glitchless API ${name} → HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`);
132
+ if (!res.ok) throw new Error(`Glitchless API ${name} → HTTP ${res.status}: ${(await res.text()).slice(0, 200)}${signInHint(res.status)}`);
108
133
  const data = await res.json();
109
134
  const call = calls.getStore();
110
135
  if (call && data?.meta) Object.assign(call, { meta: data.meta, from: params.from });
@@ -136,7 +161,7 @@ export async function write(method, p, body) {
136
161
  });
137
162
  const data = await res.json().catch(() => ({}));
138
163
  if (res.status === 403) throw new Error(`${data.error || 'forbidden'}. Saving a dashboard needs a key with the dashboard scope (a workspace key from glitchless_sign_in has it).`);
139
- if (!res.ok) throw new Error(`Glitchless API ${method} ${p} → HTTP ${res.status}: ${data.error || ''}`);
164
+ if (!res.ok) throw new Error(`Glitchless API ${method} ${p} → HTTP ${res.status}: ${data.error || ''}${signInHint(res.status)}`);
140
165
  return data;
141
166
  }
142
167