catence 0.2.1-beta.14 → 0.2.1-beta.15

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
@@ -120,7 +120,7 @@ Optional local Streamable HTTP MCP and HTTP APIs:
120
120
  catence serve --host 127.0.0.1 --port 8787
121
121
  ```
122
122
 
123
- `GET /api/v1/athletes` returns IDs and labels only. `GET /api/v1/dashboard` requires `athleteId`, for example `http://127.0.0.1:8787/api/v1/dashboard?athleteId=alex&days=28`. Browser origins must be listed with `--allow-origin`; the packaged Console instead proxies the dashboard through its authenticated same-origin route. `POST /api/v1/athletes` creates a catalog athlete (`{"id": "sam", "label": "Sam", "setDefault": false}`); the packaged Console exposes the same call to admins from **Settings → Athletes**. The MCP server has no authentication of its own unless `--auth-token-file` (or `CATENCE_MCP_TOKEN_FILE`) requires a bearer token on every endpoint except the health probes.
123
+ `GET /api/v1/athletes` returns IDs and labels only. `GET /api/v1/dashboard` requires `athleteId`, for example `http://127.0.0.1:8787/api/v1/dashboard?athleteId=alex&days=28`. Browser origins must be listed with `--allow-origin`; the packaged Console instead proxies the dashboard through its authenticated same-origin route. `POST /api/v1/athletes` creates a catalog athlete (`{"id": "sam", "label": "Sam", "setDefault": false}`); the packaged Console exposes the same call to admins from **Settings → Athletes**. The MCP server has no authentication of its own beyond the optional bearer-token gate: `catence-data mcp enable` generates a token at `<home>/mcp-token` and every endpoint except the health probes then requires `Authorization: Bearer <token>`; `mcp status`/`mcp token`/`mcp disable` manage it, and the Console Settings expose the same controls to admins.
124
124
 
125
125
  ## Configuration
126
126
 
@@ -3,7 +3,7 @@
3
3
  * Keep these values synchronized with release/manifest.json; release checks
4
4
  * deliberately reject drift before a package can be published.
5
5
  */
6
- export declare const CATENCE_RUNTIME_VERSION = "0.2.1-beta.14";
6
+ export declare const CATENCE_RUNTIME_VERSION = "0.2.1-beta.15";
7
7
  export declare const CATENCE_PROTOCOL_VERSION = 1;
8
8
  export type CatenceRuntimeCapabilities = {
9
9
  mcp: true;
@@ -3,7 +3,7 @@
3
3
  * Keep these values synchronized with release/manifest.json; release checks
4
4
  * deliberately reject drift before a package can be published.
5
5
  */
6
- export const CATENCE_RUNTIME_VERSION = '0.2.1-beta.14';
6
+ export const CATENCE_RUNTIME_VERSION = '0.2.1-beta.15';
7
7
  export const CATENCE_PROTOCOL_VERSION = 1;
8
8
  export function catenceRuntimeHealth() {
9
9
  return {
@@ -2,6 +2,7 @@
2
2
  import { createInterface } from 'node:readline/promises';
3
3
  import { stdin as input, stdout as output } from 'node:process';
4
4
  import { Command } from 'commander';
5
+ import { defaultBearerTokenPath, disableBearerToken, ensureBearerToken, mcpExposureStatus, readBearerToken, } from '../http/cli-options.js';
5
6
  import { addAthlete, athleteStorePaths, CATENCE_RUNTIME_VERSION, CatenceDatabase, channelForVersion, createDemoStore, dataStatus, deleteAthleteSecret, defaultCatalogHome, disconnectStravaAccount, fetchNpmDistTags, fetchPypiReleases, hasCommand, importStagedFile, initializeCatalog, isGlobalNpmInstall, linkActivity, loadCatalog, npmGlobalPrefix, planSelfUpdate, readInstalledConsoleVersion, rebuildRetrievalIndex, reimportNutrition, reimportWeight, resolveExtractionErrors, resolveAthlete, resolveCatalogPaths, retryDataSync, runSelfUpdateCommand, setAthleteSecret, syncData, syncProgress, connectStrava, connectStravaWithCallback, unlinkActivity, } from '../../runtime/index.js';
6
7
  const program = new Command()
7
8
  .name('catence-data')
@@ -37,6 +38,41 @@ async function stdinSecret() {
37
38
  throw new Error('--value-stdin received an empty secret.');
38
39
  return value;
39
40
  }
41
+ const mcpCommand = program.command('mcp').description('Manage Streamable HTTP MCP exposure: the bearer-token gate, its token, and endpoint URLs.');
42
+ const mcpLocalEndpoint = () => `http://127.0.0.1:${process.env.CATENCE_HTTP_PORT ?? '8787'}`;
43
+ mcpCommand.command('status')
44
+ .description('Report whether the bearer-token gate is enabled, the token, and the endpoint URLs.')
45
+ .option('--file <path>', 'non-default token file path')
46
+ .action(async (options) => {
47
+ const tokenFile = options.file ?? defaultBearerTokenPath(currentCatalog().root);
48
+ process.stdout.write(`${JSON.stringify(mcpExposureStatus(tokenFile, mcpLocalEndpoint()), null, 2)}\n`);
49
+ });
50
+ mcpCommand.command('enable')
51
+ .description('Enable the bearer-token gate: generate the token file (mode 0600) if it does not exist.')
52
+ .option('--file <path>', 'non-default token file path')
53
+ .action(async (options) => {
54
+ const tokenFile = options.file ?? defaultBearerTokenPath(currentCatalog().root);
55
+ ensureBearerToken(tokenFile);
56
+ process.stdout.write(`${JSON.stringify(mcpExposureStatus(tokenFile, mcpLocalEndpoint()), null, 2)}\n`);
57
+ });
58
+ mcpCommand.command('disable')
59
+ .description('Disable the bearer-token gate by removing the token file. Remote access is refused again.')
60
+ .option('--file <path>', 'non-default token file path')
61
+ .action(async (options) => {
62
+ const tokenFile = options.file ?? defaultBearerTokenPath(currentCatalog().root);
63
+ disableBearerToken(tokenFile);
64
+ process.stdout.write(`${JSON.stringify(mcpExposureStatus(tokenFile, mcpLocalEndpoint()), null, 2)}\n`);
65
+ });
66
+ mcpCommand.command('token')
67
+ .description('Print only the bearer token for pasting into an MCP client credential flow.')
68
+ .option('--file <path>', 'non-default token file path')
69
+ .action(async (options) => {
70
+ const tokenFile = options.file ?? defaultBearerTokenPath(currentCatalog().root);
71
+ const token = readBearerToken(tokenFile);
72
+ if (token === null)
73
+ throw new Error(`MCP exposure is not enabled; run 'catence-data mcp enable' first.`);
74
+ process.stdout.write(`${token}\n`);
75
+ });
40
76
  program.command('setup')
41
77
  .description('Create a home catalog and its first athlete store. Existing 0.1 stores must be re-synced.')
42
78
  .option('--athlete <id>', 'first athlete ID')
@@ -6,7 +6,34 @@ export type ServeCliOptions = {
6
6
  authTokenFile?: string;
7
7
  help: boolean;
8
8
  };
9
- export declare const SERVE_USAGE = "Usage: catence serve [options]\n\nRun Catence as a local Streamable HTTP MCP server.\n\nOptions:\n --home <directory> Catence catalog home. Defaults to CATENCE_HOME or ~/.catence.\n --host <host> Listener host. Defaults to 127.0.0.1.\n --port <port> Listener port. Defaults to 8787.\n --allow-origin <origin> Browser origin allowed to call Catence APIs. May be repeated.\n --auth-token-file <path> Require 'Authorization: Bearer <token>' on every request except\n the health endpoints. Defaults to CATENCE_MCP_TOKEN_FILE.\n -h, --help Show this help text.";
10
- /** Read and validate the bearer token from a file: trimmed, non-empty, or fail loudly. */
9
+ export declare const SERVE_USAGE = "Usage: catence serve [options]\n\nRun Catence as a local Streamable HTTP MCP server.\n\nOptions:\n --home <directory> Catence catalog home. Defaults to CATENCE_HOME or ~/.catence.\n --host <host> Listener host. Defaults to 127.0.0.1.\n --port <port> Listener port. Defaults to 8787.\n --allow-origin <origin> Browser origin allowed to call Catence APIs. May be repeated.\n --auth-token-file <path> Bearer-token file for the HTTP gate. Its presence switches authentication on;\n generate/inspect it with 'catence-data mcp enable|token'.\n Defaults to CATENCE_MCP_TOKEN_FILE or <catalog-home>/mcp-token.\n -h, --help Show this help text.";
10
+ /** The canonical token location inside a catalog home. */
11
+ export declare function defaultBearerTokenPath(catalogRoot: string): string;
12
+ /** Read and validate a stored bearer token: trimmed, non-empty, or fail loudly. */
11
13
  export declare function loadBearerToken(filePath: string): string;
14
+ /**
15
+ * The bearer token for the server: the stored one, or a freshly generated
16
+ * token written to the file (mode 0600) when it does not exist yet. Users
17
+ * never hand-craft tokens; they enable auth and read the result with
18
+ * `catence-data mcp-token`.
19
+ */
20
+ export declare function ensureBearerToken(filePath: string): string;
21
+ export declare function disableBearerToken(filePath: string): void;
22
+ /** The bearer token when exposure is enabled, or null when no token file exists. */
23
+ export declare function readBearerToken(filePath: string): string | null;
24
+ /**
25
+ * The currently active bearer token for the HTTP gate, cached by the token
26
+ * file's mtime so enabling or disabling is picked up without a restart. A
27
+ * missing file disables the gate; an existing but unreadable or empty file
28
+ * fails closed (the gate rejects everything except health probes).
29
+ */
30
+ export declare function activeBearerToken(filePath: string): string | null | 'invalid';
31
+ export type McpExposureStatus = {
32
+ enabled: boolean;
33
+ tokenFile: string;
34
+ endpoint: string;
35
+ healthEndpoint: string;
36
+ token?: string;
37
+ };
38
+ export declare function mcpExposureStatus(filePath: string, endpointBase: string): McpExposureStatus;
12
39
  export declare function parseServeCliOptions(arguments_: readonly string[]): ServeCliOptions;
@@ -1,4 +1,5 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { randomBytes } from 'node:crypto';
2
+ import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
3
  export const SERVE_USAGE = `Usage: catence serve [options]
3
4
 
4
5
  Run Catence as a local Streamable HTTP MCP server.
@@ -8,10 +9,15 @@ Options:
8
9
  --host <host> Listener host. Defaults to 127.0.0.1.
9
10
  --port <port> Listener port. Defaults to 8787.
10
11
  --allow-origin <origin> Browser origin allowed to call Catence APIs. May be repeated.
11
- --auth-token-file <path> Require 'Authorization: Bearer <token>' on every request except
12
- the health endpoints. Defaults to CATENCE_MCP_TOKEN_FILE.
12
+ --auth-token-file <path> Bearer-token file for the HTTP gate. Its presence switches authentication on;
13
+ generate/inspect it with 'catence-data mcp enable|token'.
14
+ Defaults to CATENCE_MCP_TOKEN_FILE or <catalog-home>/mcp-token.
13
15
  -h, --help Show this help text.`;
14
- /** Read and validate the bearer token from a file: trimmed, non-empty, or fail loudly. */
16
+ /** The canonical token location inside a catalog home. */
17
+ export function defaultBearerTokenPath(catalogRoot) {
18
+ return `${catalogRoot.replace(/[/\\]+$/, '')}/mcp-token`;
19
+ }
20
+ /** Read and validate a stored bearer token: trimmed, non-empty, or fail loudly. */
15
21
  export function loadBearerToken(filePath) {
16
22
  let token;
17
23
  try {
@@ -24,6 +30,68 @@ export function loadBearerToken(filePath) {
24
30
  throw new Error(`The auth token file ${filePath} is empty.`);
25
31
  return token;
26
32
  }
33
+ /**
34
+ * The bearer token for the server: the stored one, or a freshly generated
35
+ * token written to the file (mode 0600) when it does not exist yet. Users
36
+ * never hand-craft tokens; they enable auth and read the result with
37
+ * `catence-data mcp-token`.
38
+ */
39
+ export function ensureBearerToken(filePath) {
40
+ if (existsSync(filePath))
41
+ return loadBearerToken(filePath);
42
+ const token = randomBytes(32).toString('hex');
43
+ writeFileSync(filePath, token, { mode: 0o600 });
44
+ return token;
45
+ }
46
+ export function disableBearerToken(filePath) {
47
+ if (existsSync(filePath))
48
+ rmSync(filePath);
49
+ }
50
+ /** The bearer token when exposure is enabled, or null when no token file exists. */
51
+ export function readBearerToken(filePath) {
52
+ return existsSync(filePath) ? loadBearerToken(filePath) : null;
53
+ }
54
+ const tokenCache = new Map();
55
+ /**
56
+ * The currently active bearer token for the HTTP gate, cached by the token
57
+ * file's mtime so enabling or disabling is picked up without a restart. A
58
+ * missing file disables the gate; an existing but unreadable or empty file
59
+ * fails closed (the gate rejects everything except health probes).
60
+ */
61
+ export function activeBearerToken(filePath) {
62
+ let mtimeMs = 0;
63
+ try {
64
+ mtimeMs = statSync(filePath).mtimeMs;
65
+ }
66
+ catch {
67
+ tokenCache.set(filePath, { mtimeMs: 0, token: null });
68
+ return null;
69
+ }
70
+ const cached = tokenCache.get(filePath);
71
+ if (cached && cached.mtimeMs === mtimeMs) {
72
+ return cached.token === null ? 'invalid' : cached.token;
73
+ }
74
+ try {
75
+ const token = loadBearerToken(filePath);
76
+ tokenCache.set(filePath, { mtimeMs, token });
77
+ return token;
78
+ }
79
+ catch {
80
+ tokenCache.set(filePath, { mtimeMs, token: null });
81
+ return 'invalid';
82
+ }
83
+ }
84
+ export function mcpExposureStatus(filePath, endpointBase) {
85
+ const token = readBearerToken(filePath);
86
+ const base = endpointBase.replace(/\/+$/, '');
87
+ return {
88
+ enabled: token !== null,
89
+ tokenFile: filePath,
90
+ endpoint: `${base}/mcp`,
91
+ healthEndpoint: `${base}/health`,
92
+ ...(token !== null ? { token } : {}),
93
+ };
94
+ }
27
95
  function requiredValue(arguments_, index, option) {
28
96
  const value = arguments_[index + 1];
29
97
  if (!value || value.startsWith('-'))
@@ -7,12 +7,20 @@ export type CatenceHttpServerOptions = {
7
7
  paths?: CatencePaths;
8
8
  allowedOrigins?: readonly string[];
9
9
  /**
10
- * When set, every request except the health endpoints and CORS preflights
11
- * must present `Authorization: Bearer <token>`. The MCP server has no
12
- * authentication of its own; this gates it (and the JSON APIs) for
13
- * non-loopback exposure such as a Cloudflare Tunnel to an MCP client.
10
+ * Static bearer token for the gate (tests and embedded single-store callers).
11
+ * Mutually exclusive with bearerTokenFile.
14
12
  */
15
13
  bearerToken?: string;
14
+ /**
15
+ * Token file whose presence switches the gate on: every request except the
16
+ * health endpoints and CORS preflights must present
17
+ * `Authorization: Bearer <token>`. The file is re-read on mtime change, so
18
+ * `catence-data mcp enable|disable` (and the /api/v1/mcp-exposure route)
19
+ * take effect without a restart. The MCP server has no other
20
+ * authentication; this gates it (and the JSON APIs) for non-loopback
21
+ * exposure such as a Cloudflare Tunnel to an MCP client.
22
+ */
23
+ bearerTokenFile?: string;
16
24
  /** Internal compatibility hook for tests: override the detached sync spawner. */
17
25
  startSync?: typeof startDetachedSync;
18
26
  /** Internal compatibility hook for tests: passed into the default startDetachedSync. */
@@ -3,15 +3,19 @@ import { createServer } from 'node:http';
3
3
  import path from 'node:path';
4
4
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
5
  import { addAthlete, AthleteFileConflictError, AthleteFileTooLargeError, AthleteFileValidationError, catenceRuntimeHealth, DashboardSnapshotService, deleteAthleteSecret, describeAthleteSecrets, DetachedSyncBusyError, DETACHED_SYNC_PROVIDERS, jsonSafe, listAthleteFileRevisions, loadCatalog, mergeOpenCodeGoConsoleProfiles, openReadOnlyRepository, readAthleteFile, readAthleteFileRevision, resolveAthlete, resolveCatalogPaths, setAthleteSecret, startDetachedSync, syncProgress, updateAthleteFile, } from '../../runtime/index.js';
6
+ import { activeBearerToken, ensureBearerToken, disableBearerToken, mcpExposureStatus } from './cli-options.js';
6
7
  import { createCatenceMcpServer } from '../mcp/server.js';
7
8
  import { generationStatus } from './generation-status.js';
8
9
  const MAX_REQUEST_BYTES = 1_000_000;
9
10
  /** Endpoints that stay open when bearer authentication is enabled: they carry
10
11
  * no personal data and must answer unauthenticated readiness probes. */
11
12
  const UNAUTHENTICATED_PATHS = new Set(['/health', '/api/v1/health']);
12
- function isAuthorized(request, bearerToken) {
13
- if (!bearerToken)
13
+ function isAuthorized(request, options) {
14
+ const bearerToken = options.bearerToken !== undefined ? options.bearerToken : options.bearerTokenFile !== undefined ? activeBearerToken(options.bearerTokenFile) : undefined;
15
+ if (bearerToken === undefined || bearerToken === null)
14
16
  return true;
17
+ if (bearerToken === 'invalid')
18
+ return false;
15
19
  const received = Buffer.from(request.headers.authorization ?? '');
16
20
  const expected = Buffer.from(`Bearer ${bearerToken}`);
17
21
  // timingSafeEqual throws on length mismatch, so compare sizes first.
@@ -325,7 +329,7 @@ export function createCatenceHttpServer(options = {}) {
325
329
  response.writeHead(204).end();
326
330
  return;
327
331
  }
328
- if (!UNAUTHENTICATED_PATHS.has(pathname) && !isAuthorized(request, options.bearerToken)) {
332
+ if (!UNAUTHENTICATED_PATHS.has(pathname) && !isAuthorized(request, options)) {
329
333
  // No WWW-Authenticate on purpose: MCP connector auto-detection treats a
330
334
  // plain 401 as a bearer gate rather than an OAuth server.
331
335
  json(response, 401, { error: { code: 'unauthorized', message: 'A valid Authorization: Bearer token is required.' } });
@@ -599,6 +603,35 @@ export function createCatenceHttpServer(options = {}) {
599
603
  }
600
604
  return;
601
605
  }
606
+ if (pathname === '/api/v1/mcp-exposure' && request.method === 'GET') {
607
+ if (!options.bearerTokenFile) {
608
+ json(response, 400, { error: { code: 'exposure_not_configured', message: 'This server was started without a bearer-token file; restart it with --auth-token-file to manage MCP exposure.' } });
609
+ return;
610
+ }
611
+ json(response, 200, mcpExposureStatus(options.bearerTokenFile, `http://${request.headers.host ?? '127.0.0.1:8787'}`));
612
+ return;
613
+ }
614
+ if (pathname === '/api/v1/mcp-exposure' && request.method === 'POST') {
615
+ if (!options.bearerTokenFile) {
616
+ json(response, 400, { error: { code: 'exposure_not_configured', message: 'This server was started without a bearer-token file; restart it with --auth-token-file to manage MCP exposure.' } });
617
+ return;
618
+ }
619
+ try {
620
+ const body = await readJsonBody(request);
621
+ if (typeof body !== 'object' || body === null || Array.isArray(body) || !('enabled' in body) || typeof body.enabled !== 'boolean') {
622
+ throw new Error('Request body must be a JSON object with a boolean "enabled" field.');
623
+ }
624
+ if (body.enabled)
625
+ ensureBearerToken(options.bearerTokenFile);
626
+ else
627
+ disableBearerToken(options.bearerTokenFile);
628
+ json(response, 200, mcpExposureStatus(options.bearerTokenFile, `http://${request.headers.host ?? '127.0.0.1:8787'}`));
629
+ }
630
+ catch (error) {
631
+ json(response, 400, { error: { code: 'exposure_update_failed', message: error instanceof Error ? error.message : String(error) } });
632
+ }
633
+ return;
634
+ }
602
635
  if (pathname === '/mcp') {
603
636
  await handleMcpRequest(request, response, catalogPaths ?? staticPaths ?? resolveCatalogPaths());
604
637
  return;
@@ -2,7 +2,7 @@
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { existsSync } from 'node:fs';
4
4
  import { addAthlete, athleteStorePaths, CatenceDatabase, createDemoStore, defaultCatalogHome, initializeCatalog, loadCatalog, resolveCatalogPaths } from '../../runtime/index.js';
5
- import { loadBearerToken, parseServeCliOptions, SERVE_USAGE } from '../http/cli-options.js';
5
+ import { defaultBearerTokenPath, parseServeCliOptions, SERVE_USAGE } from '../http/cli-options.js';
6
6
  import { createCatenceHttpServer } from '../http/server.js';
7
7
  import { MCP_USAGE, parseMcpCliOptions } from './cli-options.js';
8
8
  import { createCatenceMcpServer } from './server.js';
@@ -46,11 +46,13 @@ async function run() {
46
46
  return;
47
47
  }
48
48
  await migrateCatalogStores(options.home);
49
- const bearerToken = options.authTokenFile ? loadBearerToken(options.authTokenFile) : undefined;
49
+ const catalogPaths = resolveCatalogPaths(options.home);
50
50
  const httpServer = createCatenceHttpServer({
51
- catalogPaths: resolveCatalogPaths(options.home),
51
+ catalogPaths,
52
52
  allowedOrigins: options.allowedOrigins,
53
- bearerToken,
53
+ // The token file's presence switches authentication on; enable it with
54
+ // `catence-data mcp enable` (or the Console Settings / exposure API).
55
+ bearerTokenFile: options.authTokenFile ?? defaultBearerTokenPath(catalogPaths.root),
54
56
  });
55
57
  await new Promise((resolve, reject) => {
56
58
  httpServer.once('error', reject);
@@ -60,8 +62,7 @@ async function run() {
60
62
  });
61
63
  });
62
64
  console.error(`Catence Streamable HTTP server is listening at http://${options.host}:${options.port}/mcp`);
63
- if (bearerToken)
64
- console.error('Bearer-token authentication is enabled; health endpoints stay open for readiness probes.');
65
+ console.error(`Bearer-token authentication is armed at ${options.authTokenFile ?? defaultBearerTokenPath(catalogPaths.root)}; enable it with 'catence-data mcp enable'. Health endpoints stay open for readiness probes.`);
65
66
  const close = () => {
66
67
  httpServer.close(() => process.exit(0));
67
68
  };
@@ -247,7 +247,7 @@ profiles and preserve existing ones, limits, and `defaultProfile` unless
247
247
  | --- | --- |
248
248
  | `CATENCE_HOME` | Catalog home (default `~/.catence`); equivalent to `--home` |
249
249
  | `CATENCE_HTTP_HOST` / `CATENCE_HTTP_PORT` | Defaults for `catence serve --host/--port` (host `127.0.0.1`, port `8787`) |
250
- | `CATENCE_MCP_TOKEN_FILE` | Default for `catence serve --auth-token-file`; when set, every endpoint except `/health` and `/api/v1/health` requires `Authorization: Bearer <token>` |
250
+ | `CATENCE_MCP_TOKEN_FILE` | Overrides the bearer-token file path for `catence serve` (default `<catalog-home>/mcp-token`); the file's presence switches the gate on, managed with `catence-data mcp enable/disable` or the Console Settings |
251
251
 
252
252
  Provider credentials are stored per athlete, either with `catence-data secret
253
253
  set` (see [`local-mcp.md`](deployment/local-mcp.md#3-store-provider-credentials-stdin-only-never-shell-history))
@@ -509,30 +509,43 @@ claude mcp add --transport http catence -- http://<tailscale-ip>:8787/mcp
509
509
  ### Bearer-token authentication for remote MCP clients
510
510
 
511
511
  To serve the MCP endpoint to a remote MCP client (for example a Mistral Work
512
- custom connector) over a Cloudflare Tunnel, enable bearer-token
513
- authentication instead of leaving the runtime unauthenticated. Set
514
- `CATENCE_MCP_TOKEN_FILE` in `catence-deploy/.env` to a host file holding one
515
- token (`openssl rand -hex 32`); the deploy script bind-mounts that file
516
- read-only into the container at the same path:
512
+ custom connector) over a Cloudflare Tunnel, switch on the native
513
+ bearer-token gate. The deploy scaffold arms it at `/data/mcp-token` (inside
514
+ the data volume, so it survives rebuilds); the file's presence is the switch
515
+ and Catence generates the token itself:
517
516
 
518
517
  ```sh
519
- # once, when the stack is already deployed:
520
- printf %s "$(openssl rand -hex 32)" > /srv/catence-mcp-token # mode 0600, outside the data volume
521
- echo "CATENCE_MCP_TOKEN_FILE=/srv/catence-mcp-token" >> catence-deploy/.env
522
- ./scripts/deploy-console.sh beta # re-renders compose with the token mount
518
+ # enable from the host (or use the Console Settings once logged in):
519
+ docker compose -f catence-deploy/docker-compose.yml --env-file catence-deploy/.env \
520
+ exec console catence-data --home /data mcp enable
521
+
522
+ # print the token for the client's credential flow:
523
+ docker compose -f catence-deploy/docker-compose.yml --env-file catence-deploy/.env \
524
+ exec console catence-data --home /data mcp token
525
+
526
+ # disable again:
527
+ docker compose -f catence-deploy/docker-compose.yml --env-file catence-deploy/.env \
528
+ exec console catence-data --home /data mcp disable
523
529
  ```
524
530
 
525
- With the token configured, every runtime endpoint except `/health` and
531
+ With the gate enabled, every runtime endpoint except `/health` and
526
532
  `/api/v1/health` answers `401` without an exact `Authorization: Bearer
527
- <token>` header — including `/mcp` and the JSON APIs. The Console attaches
528
- the header automatically to its own runtime calls, and refuses to start when
529
- the configured file is unreadable or empty.
533
+ <token>` header — including `/mcp` and the JSON APIs. Toggling takes effect
534
+ without a restart; the Console attaches the header automatically to its own
535
+ runtime calls.
530
536
 
531
537
  Keep `CATENCE_MCP_BIND=127.0.0.1` (the default): the tunnel client on the
532
538
  host forwards to the host-loopback mapping, so the port still never binds a
533
539
  LAN interface. Point the tunnel ingress for the MCP hostname at
534
540
  `http://127.0.0.1:8787` and complete the client's credential flow with the
535
- same token. Rotate by rewriting the file and restarting the stack.
541
+ token from `mcp token`. Rotate with `mcp disable && mcp enable` and
542
+ re-authenticate the client. The only additional setup the tunnel needs is
543
+ the ingress rule for the MCP hostname.
544
+
545
+ A custom host-side token file is still possible: set
546
+ `CATENCE_MCP_TOKEN_FILE=<host path>` in `.env`. The file is then bind-mounted
547
+ read-only at the same path, so it must already exist on the host — enabling
548
+ from the Console cannot create it.
536
549
 
537
550
  ## Exposing the Console safely
538
551
 
@@ -306,26 +306,40 @@ override the host and port when the flags are omitted.
306
306
 
307
307
  The server has no authentication of its own; when it must be reachable beyond
308
308
  loopback (for example through a Cloudflare Tunnel to an MCP client such as
309
- Mistral Work), require a bearer token with `--auth-token-file <path>`
310
- (environment equivalent: `CATENCE_MCP_TOKEN_FILE`):
309
+ Mistral Work), switch on the bearer-token gate. The gate is armed at a token
310
+ file — `<catalog-home>/mcp-token` by default, or the path given by
311
+ `--auth-token-file` (environment equivalent: `CATENCE_MCP_TOKEN_FILE`) — and
312
+ the **file's presence is the switch**: create it to enable, remove it to
313
+ disable, no restart needed.
314
+
315
+ Catence generates the token itself; never hand-craft one:
311
316
 
312
317
  ```sh
313
- catence serve --host 127.0.0.1 --port 8787 --auth-token-file /path/to/token
318
+ catence-data mcp status # enabled, token file, endpoint URLs
319
+ catence-data mcp enable # generate the token file (mode 0600) if missing
320
+ catence-data mcp token # print the token for the client credential flow
321
+ catence-data mcp disable # remove the file; remote access is refused again
314
322
  ```
315
323
 
316
- - The file holds one token (whitespace-trimmed); generate one with
317
- `openssl rand -hex 32`. An unreadable or empty file aborts startup.
318
324
  - Every endpoint except `/health` and `/api/v1/health` (kept open for readiness
319
- probes) then answers `401` without an exact
320
- `Authorization: Bearer <token>` header. The `401` deliberately carries no
325
+ probes) answers `401` without an exact `Authorization: Bearer <token>`
326
+ header while the gate is on. The `401` deliberately carries no
321
327
  `WWW-Authenticate`, so MCP clients with auth auto-detection (Mistral Work)
322
328
  classify the server as bearer-auth rather than OAuth.
323
329
  - CORS preflights (`OPTIONS`) pass through without a token.
324
- - Rotation: rewrite the file and restart the server. Keep the token out of
330
+ - An existing but unreadable or empty token file fails closed: the gate
331
+ rejects everything except the health probes until the file is fixed or
332
+ removed.
333
+ - `GET /api/v1/mcp-exposure` reports the same status the Console Settings page
334
+ shows (including the token); `POST /api/v1/mcp-exposure` with
335
+ `{"enabled": true|false}` toggles the gate. The Console exposes both to
336
+ admins only.
337
+ - Rotation: `catence-data mcp disable && catence-data mcp enable` (or rewrite
338
+ the file), then re-authenticate the MCP client. Keep the token out of
325
339
  `.env`, `config.json`, shell history, and repositories.
326
- - The Console attaches the same header automatically to its runtime calls when
327
- `CATENCE_MCP_TOKEN_FILE` is set, and refuses to start if the file is
328
- unreadable.
340
+ - The Console attaches the same header automatically to its runtime calls and
341
+ reads the token file lazily, so enabling the gate from the Console or CLI
342
+ needs no Console restart either.
329
343
 
330
344
  - `GET /api/v1/athletes` returns IDs and labels only.
331
345
  - `POST /api/v1/athletes` creates a catalog athlete from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catence",
3
- "version": "0.2.1-beta.14",
3
+ "version": "0.2.1-beta.15",
4
4
  "description": "Local MCP access to normalized Garmin, Intervals.icu, and targeted Strava fitness data.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {