@chrischall/warapp-mcp 0.3.1 → 0.4.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.
@@ -17,7 +17,7 @@ import { assumedWarning, awardView, loadAward, openingThreat } from './award.js'
17
17
  import { gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, untrustedText, viewArg } from './common.js';
18
18
  import { lookupMeta } from './hints.js';
19
19
  import { HEADROOM_COMPACT, headroomView, readTripwires, safeHeadroom, teamsOf, tripwireWarnings, untrustedDeploy } from './survival.js';
20
- import { loadLiveGame } from './live-context.js';
20
+ import { loadLiveGame, standInLine, standInOf } from './live-context.js';
21
21
  import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
22
22
  import { mapOf } from './map.js';
23
23
  import { resolveTerritory } from './resolve.js';
@@ -540,6 +540,8 @@ export function registerCheckPlanTool(server, ctx) {
540
540
  // #275 pattern 3: each border these orders leave below what the default plan leaves there (one plan per call).
541
541
  const belowPlan = await bordersBelowPlan(ctx, { game, map, me, turn, territories, info, history, teamsKnown, given: { deploys, moves } });
542
542
  const warnings = [
543
+ // The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
544
+ ...[standInLine(standInOf(ctx))].filter((w) => w !== undefined),
543
545
  // #275 (b): an untrusted estimate is the first thing said (not under an explicit enemy_deploy).
544
546
  ...(enemy_deploy === undefined ? tripwireWarnings(trip.tripwires, (w) => untrustedOf.get(w.player) ?? untrustedDeploy(w, income), (p) => estimates.find((x) => x.playerId === p)?.estimate) : []),
545
547
  ...(award ? assumedWarning(award) : []),
@@ -3,6 +3,7 @@ import { registerAdaptiveHealthcheckTool, } from '@chrischall/mcp-utils/fetchpro
3
3
  import { AUTH_FAILED_HINT, PROBE_GAME_ID, WarappClient } from '../client.js';
4
4
  import { readCredentials, TOKEN_URL, WarappConfigError } from '../config.js';
5
5
  import { readSessionSync } from '../direct/session.js';
6
+ import { HOST_SIGN_IN_ADVICE, SessionExpiredError } from '../direct/transport.js';
6
7
  /**
7
8
  * `warapp_healthcheck` — does war.app accept the configured email + token?
8
9
  *
@@ -21,11 +22,24 @@ import { readSessionSync } from '../direct/session.js';
21
22
  * which is the whole time the direct leg is serving calls ("on direct, the
22
23
  * credential probe"). Either way the result carries which leg is active and
23
24
  * whether a direct session is linked and how old it is — never the token.
25
+ *
26
+ * with a direct session (linked, or captured by mcp-host when hosted) the
27
+ * credential arm also asks war.app whether that SESSION is signed in — one GET
28
+ * of the invite-token page with it (`sessionCheck`: signed-in / signed-out /
29
+ * unknown) — and reports the router's `wall` (why it left the direct leg, when,
30
+ * and when it tries again). A session war.app shows signed out fails the check
31
+ * as `session_expired`, even when the API token is fine: before, a hosted
32
+ * healthcheck said ok while every live tool failed.
24
33
  */
25
34
  export { PROBE_GAME_ID };
26
35
  const PROBE_PATH = `/API/GameFeed?GameID=${PROBE_GAME_ID}&GetMap=false`;
27
36
  /** The page the bridge arm round-trips through the user's war.app tab. */
28
37
  export const BRIDGE_PROBE_PATH = '/';
38
+ /** `health` with the open stand-in window beside it, when one is open. */
39
+ function withStandIn(health, deps) {
40
+ const w = deps.standIn?.();
41
+ return w ? { ...health, standIn: w } : health;
42
+ }
29
43
  /**
30
44
  * The non-secret facts about the linked direct session — never the token. The
31
45
  * session mcp-host captured at sign-in (hosted, #333) is `linked: true` with `linkedBy: 'host'` (`linked` stays a boolean), with
@@ -46,6 +60,33 @@ function transportHealth(status, env, now) {
46
60
  }
47
61
  export function registerHealthcheckTool(server, bridge, direct, deps = {}) {
48
62
  const now = deps.now ?? Date.now;
63
+ /** What this call's session check found, echoed in the result; reset at each check. */
64
+ let lastCheck = {};
65
+ /** Check the direct session when there is one and the router may use it; never throws. */
66
+ const checkSession = async () => {
67
+ lastCheck = {};
68
+ if (!direct.checkSession || direct.status().mode === 'fetchproxy')
69
+ return undefined;
70
+ if (!readSessionSync(deps.env))
71
+ return undefined;
72
+ const verdict = await direct.checkSession().catch(() => 'unknown');
73
+ if (verdict === 'none')
74
+ return undefined;
75
+ const wall = direct.wall?.() ?? null;
76
+ lastCheck = { sessionCheck: verdict, ...(wall ? { wall } : {}) };
77
+ return verdict;
78
+ };
79
+ const health = () => withStandIn({ ...transportHealth(direct.status(), deps.env, now), ...lastCheck }, deps);
80
+ const signedOut = () => new SessionExpiredError({ hostSignIn: readSessionSync(deps.env)?.origin === 'host' });
81
+ const classifySignedOut = (err) => err instanceof SessionExpiredError
82
+ ? {
83
+ kind: 'session_expired',
84
+ hint: 'war.app shows the session the live tools use as signed out. ' +
85
+ (err.hostSignIn ? HOST_SIGN_IN_ADVICE : 'Run warapp_link_session to relink.'),
86
+ }
87
+ : undefined;
88
+ /** The session check this call's resolver made, read by its probe. */
89
+ let resolvedVerdict;
49
90
  registerAdaptiveHealthcheckTool({
50
91
  server,
51
92
  prefix: 'warapp',
@@ -60,36 +101,51 @@ export function registerHealthcheckTool(server, bridge, direct, deps = {}) {
60
101
  bridge: {
61
102
  probePath: BRIDGE_PROBE_PATH,
62
103
  transport: () => bridge.transport(),
63
- path: () => transportHealth(direct.status(), deps.env, now),
104
+ path: health,
64
105
  probeFn: async (path) => {
65
- const res = await (await bridge.ready()).fetch({ method: 'GET', path });
106
+ // Off the direct leg with a session: ask war.app about the session first. Signed
107
+ // out is the answer; signed in lifts the wall, and the probe then rides the direct leg.
108
+ const verdict = await checkSession();
109
+ if (verdict === 'signed-out')
110
+ throw signedOut();
111
+ const viaRouter = verdict === 'signed-in' && direct.ready !== undefined;
112
+ const leg = viaRouter ? await direct.ready() : await bridge.ready();
113
+ const res = await leg.fetch({ method: 'GET', path });
66
114
  if (res.status !== 200) {
67
- throw new McpToolError(`war.app answered HTTP ${res.status} through the bridge.`, {
115
+ throw new McpToolError(`war.app answered HTTP ${res.status}${viaRouter ? '' : ' through the bridge'}.`, {
68
116
  status: res.status,
69
117
  kind: 'http',
70
118
  });
71
119
  }
72
120
  return res.body;
73
121
  },
122
+ classifyThrown: classifySignedOut,
74
123
  },
75
124
  credential: {
76
125
  probePath: PROBE_PATH,
77
126
  resolveCredential: async () => {
78
- const health = transportHealth(direct.status(), deps.env, now);
127
+ resolvedVerdict = await checkSession();
128
+ const detail = health();
79
129
  try {
80
130
  readCredentials(deps.env);
81
- return { source: 'env', detail: health };
131
+ return { source: 'env', detail };
82
132
  }
83
133
  catch (e) {
84
134
  if (e instanceof WarappConfigError)
85
- return { source: null, detail: { ...health, reason: e.message } };
135
+ return { source: null, detail: { ...detail, reason: e.message } };
86
136
  throw e;
87
137
  }
88
138
  },
89
- probeFn: () => new WarappClient(deps).probeAuth(),
139
+ probeFn: async () => {
140
+ const res = await new WarappClient(deps).probeAuth();
141
+ // The API token works; the live tools ride the session, which war.app says is signed out.
142
+ if (resolvedVerdict === 'signed-out')
143
+ throw signedOut();
144
+ return res;
145
+ },
90
146
  classifyThrown: (err) => err instanceof McpToolError && err.kind === 'credential_rejected'
91
147
  ? { kind: 'credential_rejected', hint: AUTH_FAILED_HINT }
92
- : undefined,
148
+ : classifySignedOut(err),
93
149
  hints: { no_credential: `Set WARAPP_EMAIL and WARAPP_API_TOKEN (token from ${TOKEN_URL}).` },
94
150
  },
95
151
  });
@@ -77,7 +77,7 @@ export function registerAllTools(server, deps = {}) {
77
77
  // The cached signed-in account is discarded whenever the account behind the router may have changed.
78
78
  identity: () => bridge.identityState(),
79
79
  });
80
- registerHealthcheckTool(server, fetchproxy, bridge, deps);
80
+ registerHealthcheckTool(server, fetchproxy, bridge, { ...deps, standIn: () => live.decoderReport()?.standIn });
81
81
  // The signed-in account names a finished game's player for its end-of-game pass when no board was cached (#312).
82
82
  registerGameTool(server, client, () => dataDir(deps.env), deps.env, () => live.myInviteToken());
83
83
  registerMapTool(server, client, live);
@@ -142,6 +142,7 @@ export function registerAllTools(server, deps = {}) {
142
142
  transport: {
143
143
  activeLeg: () => bridge.status().transport,
144
144
  sessionStale: () => bridge.sessionStale(),
145
+ wall: () => bridge.wall(),
145
146
  sessionLinked: () => bridge.sessionLinked(),
146
147
  },
147
148
  pushTransport: () => push.status().transport,
@@ -3,10 +3,12 @@
3
3
  // and the client bundle whose readers decode the board.
4
4
  import { McpToolError } from '@chrischall/mcp-utils';
5
5
  import { dataDir } from '../config.js';
6
- import { inGameId, readLatestGameInfo, standingFromInfo } from '../live.js';
6
+ import { inGameId, LiveBoardFormatError, readLatestGameInfo, standingFromInfo } from '../live.js';
7
7
  import { BUNDLE_FETCH_TIMEOUT_MS, BUNDLE_MAX_BYTES, BundleProvider } from '../protocol/bundle.js';
8
+ import { ProtocolError } from '../protocol/codec.js';
9
+ import { InterpError } from '../protocol/interp.js';
8
10
  import { Method, readTerritoryPicks, writeGetLatestGameInfoParams, writeGetTerritoryPicksParams, } from '../protocol/methods.js';
9
- import { WarappRpc } from '../protocol/rpc.js';
11
+ import { ProtocolVersionError, WarappRpc } from '../protocol/rpc.js';
10
12
  import { BRIDGE_DOMAINS } from '../transport-bridge.js';
11
13
  import { hostedSession } from '../direct/session.js';
12
14
  import { isHosted } from '../hosted.js';
@@ -319,12 +321,75 @@ function beginFirstError(game) {
319
321
  export async function loadLiveTerritories(ctx, game) {
320
322
  return (await loadLiveGame(ctx, game)).territories;
321
323
  }
324
+ /** The issue tracking the move to the client war.app now serves (protocol 243), named in the window-closed error. */
325
+ export const PROTOCOL_UPDATE_ISSUE = 'https://github.com/chrischall/warapp-mcp/issues/340';
326
+ /**
327
+ * One line for a tool's warnings while a stand-in decodes: war.app ships a client this server cannot read
328
+ * yet, so an older build it still answers is decoding, since when. `undefined` without a stand-in.
329
+ */
330
+ export function standInLine(w) {
331
+ if (!w)
332
+ return undefined;
333
+ return (`war.app ships a client this server cannot read yet (${w.refusedVersion}), so the client build ${w.version}, ` +
334
+ `which war.app still answers, stands in and decodes the board (since ${w.since}). Boards still decode exactly; ` +
335
+ `war.app may stop answering the old build at any time, and this server then needs its update (#340, ${PROTOCOL_UPDATE_ISSUE}).`);
336
+ }
337
+ /** The stand-in window of the bundle this process decodes with, if one stands in (never loads one). */
338
+ export function standInOf(ctx) {
339
+ return ctx.decoderReport()?.standIn;
340
+ }
341
+ /**
342
+ * war.app no longer answers the build that stands in: its reply did not decode with it (bytes left over, an
343
+ * unknown frame) or came in another protocol version. Nothing was decoded.
344
+ */
345
+ export class StandInClosedError extends McpToolError {
346
+ window;
347
+ name = 'StandInClosedError';
348
+ constructor(window, cause) {
349
+ const why = cause instanceof Error ? cause.message : String(cause);
350
+ super(`war.app no longer answers the client build ${window.version} this server has decoded with since ${window.since} ` +
351
+ `(standing in for ${window.refusedVersion}, which this server cannot read yet): ${why} Nothing was decoded; ` +
352
+ 'the old client is no longer accepted, so this server needs the protocol update (#340).', {
353
+ kind: 'unknown',
354
+ hint: `The old client is no longer accepted: this server needs the protocol update (${PROTOCOL_UPDATE_ISSUE}). Play in the war.app web client until then.`,
355
+ cause,
356
+ });
357
+ this.window = window;
358
+ }
359
+ }
360
+ /** A failure that says the reply and the decoder disagree on the layout (or the protocol). */
361
+ const isLayoutFailure = (e) => e instanceof ProtocolVersionError || e instanceof LiveBoardFormatError || e instanceof ProtocolError || e instanceof InterpError;
362
+ /** `e`, or the window-closed error when it is a layout failure while a stand-in decodes. */
363
+ async function windowClosed(ctx, bundle, e) {
364
+ if (!isLayoutFailure(e))
365
+ return e;
366
+ const b = bundle ?? (await ctx.bundle().catch(() => undefined));
367
+ const w = b?.report?.().standIn;
368
+ return w ? new StandInClosedError(w, e) : e;
369
+ }
370
+ /**
371
+ * GetLatestGameInfo for a game, decoded: the info (`null` when war.app sent none) and its current standing.
372
+ * A standing that decodes with every byte read records the bundle as a build that works; a layout failure
373
+ * while a stand-in decodes is the window-closed error.
374
+ */
375
+ export async function readLatestBoard(ctx, gameId) {
376
+ let bundle;
377
+ try {
378
+ const env = await ctx.rpc.call('GetLatestGameInfo', Method.GetLatestGameInfo, (w) => writeGetLatestGameInfoParams(w, gameId));
379
+ bundle = await ctx.bundle();
380
+ const info = readLatestGameInfo(bundle, env.body);
381
+ const territories = standingFromInfo(info);
382
+ if (territories)
383
+ await bundle.markDecoded?.();
384
+ return { info, territories };
385
+ }
386
+ catch (e) {
387
+ throw await windowClosed(ctx, bundle, e);
388
+ }
389
+ }
322
390
  /** The live board plus the decoded LatestGameInfo (cards live there); throws when war.app has no board. */
323
391
  export async function loadLiveGame(ctx, game) {
324
- const env = await ctx.rpc.call('GetLatestGameInfo', Method.GetLatestGameInfo, (w) => writeGetLatestGameInfoParams(w, game.id));
325
- const bundle = await ctx.bundle();
326
- const info = readLatestGameInfo(bundle, env.body);
327
- const territories = standingFromInfo(info);
392
+ const { info, territories } = await readLatestBoard(ctx, game.id);
328
393
  if (!territories) {
329
394
  if (awaitsBegin(game))
330
395
  throw beginFirstError(game);
@@ -70,9 +70,14 @@ export function registerSessionTools(server, deps) {
70
70
  return {
71
71
  decoder: {
72
72
  ...d,
73
- ...(d.fallback
74
- ? { note: "A cached copy of war.app's client is decoding boards: the current version could not be looked up." }
75
- : {}),
73
+ ...(d.standInFor
74
+ ? {
75
+ note: `war.app's current client (${d.standInFor.version}) cannot be read by this server, so the client release ` +
76
+ 'it was written for (still served by war.app) is decoding boards; war.app answers this server in that layout.',
77
+ }
78
+ : d.fallback
79
+ ? { note: "A cached copy of war.app's client is decoding boards: the current version could not be looked up." }
80
+ : {}),
76
81
  },
77
82
  };
78
83
  };
@@ -102,11 +107,13 @@ export function registerSessionTools(server, deps) {
102
107
  }, async () => {
103
108
  if (hosted && hostToken === 'ok') {
104
109
  const pt = deps.pushTransport?.();
110
+ const wall = deps.transport.wall?.() ?? null;
105
111
  const base = {
106
112
  hosted: true,
107
113
  linked: true,
108
114
  linkedBy: 'host',
109
115
  activeTransport: deps.transport.activeLeg(),
116
+ ...(wall ? { wall } : {}),
110
117
  ...(pt ? { pushTransport: pt } : {}),
111
118
  ...decoderView(),
112
119
  hostedNote: NOTE_HOSTED_DIRECT,
@@ -132,7 +139,16 @@ export function registerSessionTools(server, deps) {
132
139
  if (!session)
133
140
  return { linked: false, activeTransport, ...push, hint: HINT_NOT_LINKED };
134
141
  const ageSeconds = Math.max(0, Math.round((now() - Date.parse(session.capturedAt)) / 1000));
135
- const base = { linked: true, host: session.host, capturedAt: session.capturedAt, ageSeconds, activeTransport, ...push };
142
+ const wall = deps.transport.wall?.() ?? null;
143
+ const base = {
144
+ linked: true,
145
+ host: session.host,
146
+ capturedAt: session.capturedAt,
147
+ ageSeconds,
148
+ activeTransport,
149
+ ...(wall ? { wall } : {}),
150
+ ...push,
151
+ };
136
152
  return deps.transport.sessionStale() ? { ...base, sessionExpired: true, hint: HINT_EXPIRED } : base;
137
153
  });
138
154
  });
@@ -21,7 +21,7 @@ import { currentTurn, turnsCompleted, gameIdArg, graphOf, namer, readAnnotations
21
21
  import { lookupMeta, mintMeta } from './hints.js';
22
22
  import { chatSummary } from './chat.js';
23
23
  import { readPendingSurrenders, surrenderOwedLine } from './surrender-pending.js';
24
- import { failureText, loadLiveGame, requireApprovedAccount, writeAccount } from './live-context.js';
24
+ import { failureText, loadLiveGame, requireApprovedAccount, standInLine, standInOf, writeAccount } from './live-context.js';
25
25
  import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
26
26
  import { guessOrdersOf, guessView } from './guess-view.js';
27
27
  import { guessSalt, peekGuessSalt } from '../guess-salt.js';
@@ -1904,6 +1904,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
1904
1904
  const owedLine = surrenderOwedLine(surrenders);
1905
1905
  if (owedLine)
1906
1906
  warnings.unshift(owedLine);
1907
+ // The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
1908
+ const standInNote = standInLine(standInOf(ctx));
1909
+ if (standInNote)
1910
+ warnings.unshift(standInNote);
1907
1911
  // #312 E3: after turns 4 and 8, my income beside the pace my finished games on this map set
1908
1912
  // (reported only: read after the plan is made, never an input to it).
1909
1913
  const paceRecord = PACE_TURNS.includes(turnsCompleted(game))
@@ -2669,6 +2673,10 @@ export function registerTurnTools(server, ctx, opts = {}) {
2669
2673
  }));
2670
2674
  if (belowPlan)
2671
2675
  warnings.push(belowPlan);
2676
+ // The owner, 2026-11-17: while an older build stands in for a client this server cannot read, say so first.
2677
+ const standInNote = standInLine(standInOf(ctx));
2678
+ if (standInNote)
2679
+ warnings.unshift(standInNote);
2672
2680
  // Deploys first (as the client sends them), merged per territory.
2673
2681
  const merged = new Map();
2674
2682
  for (const d of deploys) {
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Single source of truth for the server version. release-please bumps the
2
2
  // literal on the marked line (registered in release-please-config.json
3
3
  // extra-files); every other module imports VERSION from here.
4
- export const VERSION = '0.3.1'; // x-release-please-version
4
+ export const VERSION = '0.4.0'; // x-release-please-version
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "warapp-mcp",
5
5
  "display_name": "war.app (Warzone)",
6
- "version": "0.3.1",
6
+ "version": "0.4.0",
7
7
  "description": "war.app (Warzone) game advisor for Claude — your games, maps, bonuses, board analysis and routes via the GameFeed API, plus your games list (waiting on you first), opponent scouting with your head-to-head, the live board, territory picks, cards, turn planning and submission, turn notifications, and chat through your signed-in war.app tab (ContextMint Bridge). Joining, leaving or surrendering a game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications and linking a session (local only) are confirm-gated.",
8
8
  "author": {
9
9
  "name": "Chris Hall",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrischall/warapp-mcp",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "mcpName": "io.github.chrischall/warapp-mcp",
5
5
  "description": "war.app (Warzone) game advisor MCP server for Claude — games, maps, bonuses and board analysis via the GameFeed API, plus your games list, opponent scouting, the live board, territory picks, cards, turn planning and submission, turn notifications and chat through your signed-in war.app tab. Developed and maintained by AI (Claude Code).",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "url": "https://github.com/chrischall/warapp-mcp",
7
7
  "source": "github"
8
8
  },
9
- "version": "0.3.1",
9
+ "version": "0.4.0",
10
10
  "packages": [
11
11
  {
12
12
  "registryType": "npm",
13
13
  "identifier": "@chrischall/warapp-mcp",
14
- "version": "0.3.1",
14
+ "version": "0.4.0",
15
15
  "transport": {
16
16
  "type": "stdio"
17
17
  },