@cognium/mcp-server 0.1.21 → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jcs.js","sourceRoot":"","sources":["../src/jcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,0DAA0D;AAC1D,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAElC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAElC,KAAK,QAAQ;YACX,gEAAgE;YAChE,qEAAqE;YACrE,mCAAmC;YACnC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,MAAM,IAAI,QAAQ,CAAC,uBAAuB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACxF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE/B,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE/B,KAAK,QAAQ;YACX,MAAM;QAER;YACE,MAAM,IAAI,QAAQ,CAAC,yBAAyB,OAAO,KAAK,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC5D,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;QAC9D,mEAAmE;SAClE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IACtC,yEAAyE;IACzE,yCAAyC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC7F,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Offline licence-token verification.
3
+ *
4
+ * A token is a compact, signed, self-describing string:
5
+ *
6
+ * cognium-lic-v1.<base64url(JCS payload)>.<base64url(Ed25519 signature)>
7
+ *
8
+ * The signature covers the **canonical** payload (RFC 8785, `./jcs.ts`), not
9
+ * the bytes the payload happened to arrive in, so a token survives being
10
+ * re-encoded on the way. The same token is the api.cognium.net key and the
11
+ * hosted proxy credential, so the format is a cross-surface contract: the
12
+ * prefix is versioned, and a change to the shape is a prefix bump.
13
+ *
14
+ * `kid` names the key that signed it, so keys can be rotated without
15
+ * invalidating tokens signed by the previous one — a verifier simply keeps
16
+ * both. It is inside the payload, and therefore signed.
17
+ *
18
+ * Verification is **offline and read-only**: an Ed25519 public key, no
19
+ * network, no cache, no state written anywhere. Nothing here phones home,
20
+ * and nothing here is secret — a verification key is published on purpose.
21
+ * The private half never appears in this repository or in any published
22
+ * package.
23
+ *
24
+ * Deliberately *not* here: entitlement enforcement, metering and revocation.
25
+ * Those live at the issuer and the hosted endpoints, never in a binary the
26
+ * user runs.
27
+ */
28
+ /** Token prefix. A version bump here is a format break, not a key rotation. */
29
+ export declare const TOKEN_PREFIX = "cognium-lic-v1";
30
+ /** What a verified token asserts. Unknown fields are preserved but ignored. */
31
+ export interface LicencePayload {
32
+ /** Identifies the signing key, so keys can be rotated. */
33
+ readonly kid: string;
34
+ /** Organisation the token was issued to. */
35
+ readonly org: string;
36
+ /** Issuer-defined tier name. The server never branches on this. */
37
+ readonly tier: string;
38
+ /** Issued-at, ISO-8601. */
39
+ readonly iat: string;
40
+ /** Expiry, ISO-8601. A date with no time is good through that whole UTC day. */
41
+ readonly expiry: string;
42
+ /** Issuer-defined entitlement names. The server never branches on these. */
43
+ readonly entitlements?: readonly string[];
44
+ }
45
+ export type LicenceStatus =
46
+ /** Signature checks out and the token is in date. */
47
+ 'valid'
48
+ /** Signature checks out; `expiry` has passed. */
49
+ | 'expired'
50
+ /**
51
+ * The signature did not verify. A token signed by a different key and a
52
+ * token whose payload was altered are **indistinguishable** offline — both
53
+ * land here, by construction, and no amount of local checking separates
54
+ * them.
55
+ */
56
+ | 'invalid-signature'
57
+ /** Not a token of this format: wrong prefix, bad base64url, or bad JSON. */
58
+ | 'malformed'
59
+ /** No key is known for this token's `kid`, so no verdict is possible. */
60
+ | 'no-key'
61
+ /** No token was configured at all. */
62
+ | 'absent';
63
+ export interface LicenceVerdict {
64
+ readonly status: LicenceStatus;
65
+ /** Present for `valid` and `expired` only — never trust it otherwise. */
66
+ readonly payload?: LicencePayload;
67
+ /** One line, safe to print. Never contains the token or any key material. */
68
+ readonly detail: string;
69
+ }
70
+ /**
71
+ * The published verification keys, by `kid`, as base64url-encoded raw 32-byte
72
+ * Ed25519 public keys.
73
+ *
74
+ * Empty until the production key pair exists. Generating it is a credential
75
+ * operation, done by hand on the owner's machine — a placeholder that looked
76
+ * real would be worse than none, so every token verifies to `no-key` until a
77
+ * key is added here. Rotation adds a `kid` and keeps the old one as long as
78
+ * tokens signed by it are still in date.
79
+ *
80
+ * `COGNIUM_LICENSE_PUBKEY` adds to this map at runtime, which is how a key is
81
+ * rotated ahead of a release and how the tests supply a throwaway key.
82
+ */
83
+ export declare const BUILTIN_PUBLIC_KEYS: Readonly<Record<string, string>>;
84
+ /**
85
+ * A `kid` of `*` in the key map matches any token.
86
+ *
87
+ * For development and tests only: it defeats the point of `kid`, so it is
88
+ * never written into `BUILTIN_PUBLIC_KEYS`.
89
+ */
90
+ export declare const ANY_KID = "*";
91
+ /**
92
+ * Parse `COGNIUM_LICENSE_PUBKEY`.
93
+ *
94
+ * Either `kid=key,kid=key` for real rotation, or a bare key, which registers
95
+ * under `*` and matches any token — the development form.
96
+ */
97
+ export declare function parsePublicKeyEnv(raw: string | undefined): Record<string, string>;
98
+ export interface VerifyOptions {
99
+ /**
100
+ * Verification keys by `kid`, base64url raw Ed25519. Merged over the
101
+ * built-in map, so a caller can add a key without replacing the published
102
+ * ones. Pass `{}` explicitly to verify against nothing.
103
+ */
104
+ readonly publicKeys?: Readonly<Record<string, string>>;
105
+ /** Clock injection point for the expiry test. */
106
+ readonly now?: Date;
107
+ }
108
+ /**
109
+ * Verify a token. Never throws, never reaches the network, and returns one
110
+ * line of detail that is always safe to print.
111
+ */
112
+ export declare function verifyLicence(token: string | undefined, opts?: VerifyOptions): LicenceVerdict;
113
+ /**
114
+ * Mint a token. Exported for the issuer and the tests; the server itself
115
+ * never calls it, and the private key it needs lives only where tokens are
116
+ * issued.
117
+ */
118
+ export declare function encodeLicence(payload: LicencePayload, sign: (bytes: Buffer) => Buffer): string;
119
+ //# sourceMappingURL=licence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"licence.d.ts","source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CAWjF;AAuFD,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,iDAAiD;IACjD,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,GAAE,aAAkB,GAAG,cAAc,CAiEjG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAI9F"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Offline licence-token verification.
3
+ *
4
+ * A token is a compact, signed, self-describing string:
5
+ *
6
+ * cognium-lic-v1.<base64url(JCS payload)>.<base64url(Ed25519 signature)>
7
+ *
8
+ * The signature covers the **canonical** payload (RFC 8785, `./jcs.ts`), not
9
+ * the bytes the payload happened to arrive in, so a token survives being
10
+ * re-encoded on the way. The same token is the api.cognium.net key and the
11
+ * hosted proxy credential, so the format is a cross-surface contract: the
12
+ * prefix is versioned, and a change to the shape is a prefix bump.
13
+ *
14
+ * `kid` names the key that signed it, so keys can be rotated without
15
+ * invalidating tokens signed by the previous one — a verifier simply keeps
16
+ * both. It is inside the payload, and therefore signed.
17
+ *
18
+ * Verification is **offline and read-only**: an Ed25519 public key, no
19
+ * network, no cache, no state written anywhere. Nothing here phones home,
20
+ * and nothing here is secret — a verification key is published on purpose.
21
+ * The private half never appears in this repository or in any published
22
+ * package.
23
+ *
24
+ * Deliberately *not* here: entitlement enforcement, metering and revocation.
25
+ * Those live at the issuer and the hosted endpoints, never in a binary the
26
+ * user runs.
27
+ */
28
+ import { verify as verifySignature, createPublicKey } from 'node:crypto';
29
+ import { canonicalBytes } from './jcs.js';
30
+ /** Token prefix. A version bump here is a format break, not a key rotation. */
31
+ export const TOKEN_PREFIX = 'cognium-lic-v1';
32
+ /**
33
+ * The published verification keys, by `kid`, as base64url-encoded raw 32-byte
34
+ * Ed25519 public keys.
35
+ *
36
+ * Empty until the production key pair exists. Generating it is a credential
37
+ * operation, done by hand on the owner's machine — a placeholder that looked
38
+ * real would be worse than none, so every token verifies to `no-key` until a
39
+ * key is added here. Rotation adds a `kid` and keeps the old one as long as
40
+ * tokens signed by it are still in date.
41
+ *
42
+ * `COGNIUM_LICENSE_PUBKEY` adds to this map at runtime, which is how a key is
43
+ * rotated ahead of a release and how the tests supply a throwaway key.
44
+ */
45
+ export const BUILTIN_PUBLIC_KEYS = Object.freeze({});
46
+ /**
47
+ * A `kid` of `*` in the key map matches any token.
48
+ *
49
+ * For development and tests only: it defeats the point of `kid`, so it is
50
+ * never written into `BUILTIN_PUBLIC_KEYS`.
51
+ */
52
+ export const ANY_KID = '*';
53
+ const RAW_ED25519_PUBLIC_KEY_BYTES = 32;
54
+ /** DER prefix for an Ed25519 SubjectPublicKeyInfo wrapping a raw 32-byte key. */
55
+ const SPKI_ED25519_PREFIX = Buffer.from('302a300506032b6570032100', 'hex');
56
+ /**
57
+ * Parse `COGNIUM_LICENSE_PUBKEY`.
58
+ *
59
+ * Either `kid=key,kid=key` for real rotation, or a bare key, which registers
60
+ * under `*` and matches any token — the development form.
61
+ */
62
+ export function parsePublicKeyEnv(raw) {
63
+ if (!raw || raw.trim() === '')
64
+ return {};
65
+ const out = {};
66
+ for (const part of raw.split(',')) {
67
+ const entry = part.trim();
68
+ if (entry === '')
69
+ continue;
70
+ const eq = entry.indexOf('=');
71
+ if (eq === -1)
72
+ out[ANY_KID] = entry;
73
+ else
74
+ out[entry.slice(0, eq).trim()] = entry.slice(eq + 1).trim();
75
+ }
76
+ return out;
77
+ }
78
+ function decodeBase64Url(segment) {
79
+ // Reject anything outside the base64url alphabet up front: Buffer's decoder
80
+ // is lenient and would silently accept padding and '+/' characters, which
81
+ // would make two different strings decode to the same token.
82
+ if (!/^[A-Za-z0-9_-]+$/.test(segment))
83
+ return null;
84
+ const buf = Buffer.from(segment, 'base64url');
85
+ if (buf.length === 0)
86
+ return null;
87
+ return buf;
88
+ }
89
+ /** Wrap a raw Ed25519 public key so `node:crypto` will accept it. */
90
+ function publicKeyFrom(encoded) {
91
+ const raw = decodeBase64Url(encoded);
92
+ if (!raw || raw.length !== RAW_ED25519_PUBLIC_KEY_BYTES)
93
+ return null;
94
+ try {
95
+ return createPublicKey({
96
+ key: Buffer.concat([SPKI_ED25519_PREFIX, raw]),
97
+ format: 'der',
98
+ type: 'spki',
99
+ });
100
+ }
101
+ catch {
102
+ return null;
103
+ }
104
+ }
105
+ function isIsoDate(value) {
106
+ return !Number.isNaN(new Date(value).getTime());
107
+ }
108
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
109
+ const DAY_MS = 24 * 60 * 60 * 1000;
110
+ /**
111
+ * The first instant at which a token is no longer in date.
112
+ *
113
+ * A date-only `expiry` names a day, and the token is good for the whole of
114
+ * it: `Date` reads `2026-10-15` as that day's UTC midnight, which would end
115
+ * the licence a day before the date it prints. A full timestamp is the
116
+ * instant it says.
117
+ */
118
+ function expiryInstant(expiry) {
119
+ const at = new Date(expiry).getTime();
120
+ return DATE_ONLY.test(expiry) ? at + DAY_MS : at;
121
+ }
122
+ /**
123
+ * Read the payload segment.
124
+ *
125
+ * Returns the object **as parsed**, unknown members included: the signature
126
+ * covers everything the issuer signed, so a field this version does not know
127
+ * has to still be there when the canonical form is rebuilt. A known field of
128
+ * the wrong shape is malformed rather than quietly dropped.
129
+ */
130
+ function parsePayload(segment) {
131
+ const raw = decodeBase64Url(segment);
132
+ if (!raw)
133
+ return null;
134
+ let parsed;
135
+ try {
136
+ parsed = JSON.parse(raw.toString('utf8'));
137
+ }
138
+ catch {
139
+ return null;
140
+ }
141
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
142
+ return null;
143
+ const { kid, org, tier, iat, expiry, entitlements } = parsed;
144
+ if (typeof kid !== 'string' || kid === '' ||
145
+ typeof org !== 'string' ||
146
+ typeof tier !== 'string' ||
147
+ typeof iat !== 'string' ||
148
+ typeof expiry !== 'string') {
149
+ return null;
150
+ }
151
+ if (!isIsoDate(iat) || !isIsoDate(expiry))
152
+ return null;
153
+ if (entitlements !== undefined &&
154
+ !(Array.isArray(entitlements) && entitlements.every((e) => typeof e === 'string'))) {
155
+ return null;
156
+ }
157
+ return parsed;
158
+ }
159
+ /**
160
+ * Verify a token. Never throws, never reaches the network, and returns one
161
+ * line of detail that is always safe to print.
162
+ */
163
+ export function verifyLicence(token, opts = {}) {
164
+ if (!token || token.trim() === '') {
165
+ return { status: 'absent', detail: 'no licence token configured' };
166
+ }
167
+ const parts = token.trim().split('.');
168
+ if (parts.length !== 3 || parts[0] !== TOKEN_PREFIX) {
169
+ return { status: 'malformed', detail: `not a ${TOKEN_PREFIX} token` };
170
+ }
171
+ const [, payloadSegment, signatureSegment] = parts;
172
+ const payload = parsePayload(payloadSegment);
173
+ if (!payload) {
174
+ return { status: 'malformed', detail: 'licence payload is not readable' };
175
+ }
176
+ const signature = decodeBase64Url(signatureSegment);
177
+ if (!signature) {
178
+ return { status: 'malformed', detail: 'licence signature is not readable' };
179
+ }
180
+ const keys = { ...BUILTIN_PUBLIC_KEYS, ...(opts.publicKeys ?? {}) };
181
+ const encodedKey = keys[payload.kid] ?? keys[ANY_KID];
182
+ if (!encodedKey) {
183
+ return {
184
+ status: 'no-key',
185
+ detail: `no verification key for licence key id "${payload.kid}"`,
186
+ };
187
+ }
188
+ const key = publicKeyFrom(encodedKey);
189
+ if (!key) {
190
+ return {
191
+ status: 'no-key',
192
+ detail: `the verification key for key id "${payload.kid}" is unusable`,
193
+ };
194
+ }
195
+ let signatureOk = false;
196
+ try {
197
+ // Over the canonical form of everything that arrived, not the segment's
198
+ // own bytes and not just the fields this version reads.
199
+ signatureOk = verifySignature(null, canonicalBytes(payload), key, signature);
200
+ }
201
+ catch {
202
+ signatureOk = false;
203
+ }
204
+ if (!signatureOk) {
205
+ return {
206
+ status: 'invalid-signature',
207
+ detail: 'licence signature did not verify (wrong key, or the token was altered)',
208
+ };
209
+ }
210
+ const now = opts.now ?? new Date();
211
+ if (expiryInstant(payload.expiry) <= now.getTime()) {
212
+ return {
213
+ status: 'expired',
214
+ payload,
215
+ detail: `licence for ${payload.org} expired on ${payload.expiry}`,
216
+ };
217
+ }
218
+ return {
219
+ status: 'valid',
220
+ payload,
221
+ detail: `licence for ${payload.org} (${payload.tier}) valid to ${payload.expiry}`,
222
+ };
223
+ }
224
+ /**
225
+ * Mint a token. Exported for the issuer and the tests; the server itself
226
+ * never calls it, and the private key it needs lives only where tokens are
227
+ * issued.
228
+ */
229
+ export function encodeLicence(payload, sign) {
230
+ const canonical = canonicalBytes(payload);
231
+ const segment = canonical.toString('base64url');
232
+ return `${TOKEN_PREFIX}.${segment}.${sign(canonical).toString('base64url')}`;
233
+ }
234
+ //# sourceMappingURL=licence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"licence.js","sourceRoot":"","sources":["../src/licence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AA6C7C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEvF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAE3B,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,iFAAiF;AACjF,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,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,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,MAAM,EAAE,mBAAmB;YAC3B,MAAM,EAAE,wEAAwE;SACjF,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IACnC,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;QACnD,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,OAAO;YACP,MAAM,EAAE,eAAe,OAAO,CAAC,GAAG,eAAe,OAAO,CAAC,MAAM,EAAE;SAClE,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE,OAAO;QACf,OAAO;QACP,MAAM,EAAE,eAAe,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,IAAI,cAAc,OAAO,CAAC,MAAM,EAAE;KAClF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAAuB,EAAE,IAA+B;IACpF,MAAM,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChD,OAAO,GAAG,YAAY,IAAI,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Optional tool modules — the one new seam.
3
+ *
4
+ * A module is a package that registers extra tools on this server over its
5
+ * own library's functions. The server loads it, hands it the shared cache and
6
+ * the computed enablement, and then stays out of the way: what a finding is,
7
+ * and which of its own tools a module registers in a given state, are the
8
+ * module's decisions, never the server's.
9
+ *
10
+ * The loader's contract is that **the server comes up either way**. A module
11
+ * that is absent, broken, built against the wrong engine, or wrong in shape
12
+ * is refused with one line on stderr, and the deterministic floor serves as
13
+ * normal. There is no state in which a bad module takes the server down.
14
+ */
15
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
16
+ import type { ToolContext } from './tools/types.js';
17
+ export interface ToolModule {
18
+ /** Stable identifier, used in the startup line and refusal messages. */
19
+ readonly id: string;
20
+ /** The module's own version. */
21
+ readonly version: string;
22
+ /** SPDX-style licence identifier of the module's terms. */
23
+ readonly licence: string;
24
+ /**
25
+ * The `circle-ir` the module was built against, as `major.minor` (a full
26
+ * `major.minor.patch` is accepted and only its `major.minor` is compared).
27
+ */
28
+ readonly circleIrRange: string;
29
+ /** Register the module's tools. Called once, synchronously. */
30
+ register(server: McpServer, ctx: ToolContext): void;
31
+ }
32
+ export interface ModuleRefusal {
33
+ /** The specifier that was tried, which may be all we know. */
34
+ readonly specifier: string;
35
+ /** One line, safe to print. */
36
+ readonly reason: string;
37
+ }
38
+ /**
39
+ * The specifier the server looks for by default. It is data, not a
40
+ * dependency: nothing in this package's manifest requires it, and if it does
41
+ * not resolve the server simply runs at the floor.
42
+ */
43
+ export declare const DEFAULT_MODULE_SPECIFIERS: readonly string[];
44
+ /** Override the specifier list. `none` or an empty value loads nothing. */
45
+ export declare const ENV_MODULES = "COGNIUM_MCP_MODULES";
46
+ export declare function moduleSpecifiers(env?: NodeJS.ProcessEnv): readonly string[];
47
+ /** The `circle-ir` actually installed next to this server. */
48
+ export declare function circleIrVersion(): string;
49
+ /** `4.9.29` → `4.9`; `4.9` → `4.9`; anything else → null. */
50
+ export declare function majorMinor(version: string): string | null;
51
+ export declare function isToolModule(value: unknown): value is ToolModule;
52
+ /**
53
+ * Decide whether a module may load against the installed engine.
54
+ *
55
+ * The comparison is `major.minor`, which is what the published contract
56
+ * promises. Two consequences worth being explicit about: a patch-level
57
+ * difference is accepted here and is caught instead by the pin check at
58
+ * release time; and a module that declares a range this function cannot
59
+ * parse is refused rather than assumed compatible.
60
+ */
61
+ export declare function checkCircleIrRange(declared: string, installed: string): {
62
+ ok: true;
63
+ } | {
64
+ ok: false;
65
+ reason: string;
66
+ };
67
+ export interface LoadModulesResult {
68
+ readonly modules: readonly ToolModule[];
69
+ readonly refusals: readonly ModuleRefusal[];
70
+ }
71
+ export interface LoadModulesOptions {
72
+ readonly specifiers?: readonly string[];
73
+ /** The installed engine version. Injected by the range tests. */
74
+ readonly installedCircleIr?: string;
75
+ /** Import hook. Injected by tests so no fixture package is needed. */
76
+ readonly importer?: (specifier: string) => Promise<unknown>;
77
+ }
78
+ /**
79
+ * Try each specifier in order. Never throws: everything that can go wrong
80
+ * comes back as a refusal.
81
+ */
82
+ export declare function loadModules(opts?: LoadModulesOptions): Promise<LoadModulesResult>;
83
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,aAAa;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+BAA+B;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAAyB,CAAC;AAEjF,2EAA2E;AAC3E,eAAO,MAAM,WAAW,wBAAwB,CAAC;AAEjD,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,SAAS,MAAM,EAAE,CAMxF;AAID,8DAA8D;AAC9D,wBAAgB,eAAe,IAAI,MAAM,CASxC;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGzD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAUhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAY9C;AAaD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,iEAAiE;IACjE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,GAAE,kBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqC3F"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Optional tool modules — the one new seam.
3
+ *
4
+ * A module is a package that registers extra tools on this server over its
5
+ * own library's functions. The server loads it, hands it the shared cache and
6
+ * the computed enablement, and then stays out of the way: what a finding is,
7
+ * and which of its own tools a module registers in a given state, are the
8
+ * module's decisions, never the server's.
9
+ *
10
+ * The loader's contract is that **the server comes up either way**. A module
11
+ * that is absent, broken, built against the wrong engine, or wrong in shape
12
+ * is refused with one line on stderr, and the deterministic floor serves as
13
+ * normal. There is no state in which a bad module takes the server down.
14
+ */
15
+ import { createRequire } from 'node:module';
16
+ /**
17
+ * The specifier the server looks for by default. It is data, not a
18
+ * dependency: nothing in this package's manifest requires it, and if it does
19
+ * not resolve the server simply runs at the floor.
20
+ */
21
+ export const DEFAULT_MODULE_SPECIFIERS = ['circle-ir-ai/mcp'];
22
+ /** Override the specifier list. `none` or an empty value loads nothing. */
23
+ export const ENV_MODULES = 'COGNIUM_MCP_MODULES';
24
+ export function moduleSpecifiers(env = process.env) {
25
+ const raw = env[ENV_MODULES];
26
+ if (raw === undefined)
27
+ return DEFAULT_MODULE_SPECIFIERS;
28
+ const trimmed = raw.trim();
29
+ if (trimmed === '' || trimmed === 'none')
30
+ return [];
31
+ return trimmed.split(',').map((s) => s.trim()).filter((s) => s !== '');
32
+ }
33
+ const require_ = createRequire(import.meta.url);
34
+ /** The `circle-ir` actually installed next to this server. */
35
+ export function circleIrVersion() {
36
+ try {
37
+ return require_('circle-ir/package.json').version;
38
+ }
39
+ catch {
40
+ // circle-ir is a hard dependency, so this should be unreachable; if the
41
+ // install is broken enough to make it reachable, say so rather than
42
+ // claiming a version.
43
+ return 'unknown';
44
+ }
45
+ }
46
+ /** `4.9.29` → `4.9`; `4.9` → `4.9`; anything else → null. */
47
+ export function majorMinor(version) {
48
+ const m = /^(\d+)\.(\d+)(?:\.|$)/.exec(version.trim());
49
+ return m ? `${m[1]}.${m[2]}` : null;
50
+ }
51
+ export function isToolModule(value) {
52
+ if (typeof value !== 'object' || value === null)
53
+ return false;
54
+ const m = value;
55
+ return (typeof m.id === 'string' &&
56
+ typeof m.version === 'string' &&
57
+ typeof m.licence === 'string' &&
58
+ typeof m.circleIrRange === 'string' &&
59
+ typeof m.register === 'function');
60
+ }
61
+ /**
62
+ * Decide whether a module may load against the installed engine.
63
+ *
64
+ * The comparison is `major.minor`, which is what the published contract
65
+ * promises. Two consequences worth being explicit about: a patch-level
66
+ * difference is accepted here and is caught instead by the pin check at
67
+ * release time; and a module that declares a range this function cannot
68
+ * parse is refused rather than assumed compatible.
69
+ */
70
+ export function checkCircleIrRange(declared, installed) {
71
+ const want = majorMinor(declared);
72
+ const have = majorMinor(installed);
73
+ if (!want)
74
+ return { ok: false, reason: `declares an unreadable circle-ir range "${declared}"` };
75
+ if (!have)
76
+ return { ok: false, reason: `the installed circle-ir version "${installed}" is unreadable` };
77
+ if (want !== have) {
78
+ return {
79
+ ok: false,
80
+ reason: `was built against circle-ir ${want}, but circle-ir ${installed} is installed`,
81
+ };
82
+ }
83
+ return { ok: true };
84
+ }
85
+ /** Pull a `ToolModule` out of whatever the specifier exported. */
86
+ function moduleFrom(imported) {
87
+ if (isToolModule(imported))
88
+ return imported;
89
+ const ns = imported;
90
+ if (!ns)
91
+ return null;
92
+ for (const key of ['default', 'toolModule', 'module']) {
93
+ if (isToolModule(ns[key]))
94
+ return ns[key];
95
+ }
96
+ return null;
97
+ }
98
+ /**
99
+ * Try each specifier in order. Never throws: everything that can go wrong
100
+ * comes back as a refusal.
101
+ */
102
+ export async function loadModules(opts = {}) {
103
+ const specifiers = opts.specifiers ?? moduleSpecifiers();
104
+ const installed = opts.installedCircleIr ?? circleIrVersion();
105
+ const importer = opts.importer ?? ((s) => import(/* @vite-ignore */ s));
106
+ const modules = [];
107
+ const refusals = [];
108
+ for (const specifier of specifiers) {
109
+ let imported;
110
+ try {
111
+ imported = await importer(specifier);
112
+ }
113
+ catch (err) {
114
+ const code = err.code;
115
+ // Not installed is the ordinary case, not a fault: the floor is a
116
+ // supported way to run, so it is not reported as a refusal.
117
+ if (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND')
118
+ continue;
119
+ refusals.push({ specifier, reason: `failed to load: ${err.message}` });
120
+ continue;
121
+ }
122
+ const mod = moduleFrom(imported);
123
+ if (!mod) {
124
+ refusals.push({ specifier, reason: 'does not export a tool module' });
125
+ continue;
126
+ }
127
+ const range = checkCircleIrRange(mod.circleIrRange, installed);
128
+ if (!range.ok) {
129
+ refusals.push({ specifier, reason: `${mod.id}@${mod.version} ${range.reason}` });
130
+ continue;
131
+ }
132
+ modules.push(mod);
133
+ }
134
+ return { modules, refusals };
135
+ }
136
+ //# sourceMappingURL=modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA2B5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAsB,CAAC,kBAAkB,CAAC,CAAC;AAEjF,2EAA2E;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAEjD,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IACnE,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,yBAAyB,CAAC;IACxD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC;IACpD,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CA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nC,IAAI,QAAiB,CAAC;QACtB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,GAAI,GAAyB,CAAC,IAAI,CAAC;YAC7C,kEAAkE;YAClE,4DAA4D;YAC5D,IAAI,IAAI,KAAK,sBAAsB,IAAI,IAAI,KAAK,kBAAkB;gBAAE,SAAS;YAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAoB,GAAa,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAClF,SAAS;QACX,CAAC;QAED,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,+BAA+B,EAAE,CAAC,CAAC;YACtE,SAAS;QACX,CAAC;QAED,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAC/D,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;YACd,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACjF,SAAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC"}
package/dist/server.d.ts CHANGED
@@ -1,12 +1,53 @@
1
1
  /**
2
- * MCP server assembly — register every tool + resource on a fresh
3
- * `McpServer` instance. Transport wiring lives in `index.ts` so this
4
- * module stays transport-agnostic and testable.
2
+ * MCP server assembly — register every floor tool + resource on a fresh
3
+ * `McpServer` instance, then let each optional module register its own.
4
+ * Transport wiring lives in `bin.ts` so this module stays transport-agnostic
5
+ * and testable, and `index.ts` exports it so a host can mount it over HTTP
6
+ * without spawning a subprocess.
5
7
  */
6
8
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { type Enablement } from './enablement.js';
10
+ import { type ToolModule, type ModuleRefusal } from './modules.js';
11
+ export declare const SERVER_NAME: string;
12
+ export declare const SERVER_VERSION: string;
7
13
  export interface BuildServerOptions {
8
14
  /** Override the default cache capacity (3 projects). */
9
15
  cacheCapacity?: number;
16
+ /**
17
+ * Optional tool modules to register after the floor. Already loaded and
18
+ * already checked — `buildServer` is synchronous and does no resolution of
19
+ * its own; `discoverModules()` or `createServer()` do that.
20
+ */
21
+ modules?: readonly ToolModule[];
22
+ /**
23
+ * What this install may offer. Defaults to the floor, which is correct for
24
+ * a server built with no modules.
25
+ */
26
+ enablement?: Enablement;
10
27
  }
11
28
  export declare function buildServer(opts?: BuildServerOptions): McpServer;
29
+ export interface Discovery {
30
+ readonly modules: readonly ToolModule[];
31
+ readonly refusals: readonly ModuleRefusal[];
32
+ readonly enablement: Enablement;
33
+ readonly circleIr: string;
34
+ }
35
+ /**
36
+ * Resolve the optional modules and compute enablement, once per process.
37
+ *
38
+ * Memoized on the promise, not the result, so concurrent callers — the HTTP
39
+ * host builds a server per request — share one resolution instead of racing
40
+ * to import the same module several times.
41
+ */
42
+ export declare function discoverModules(): Promise<Discovery>;
43
+ /** Drop the discovery memo. For tests; nothing in the server calls this. */
44
+ export declare function resetDiscoveryForTests(): void;
45
+ /**
46
+ * The server a host should build: floor plus whatever optional modules this
47
+ * install has, with enablement computed once.
48
+ */
49
+ export declare function createServer(opts?: Omit<BuildServerOptions, 'modules' | 'enablement'>): Promise<{
50
+ server: McpServer;
51
+ discovery: Discovery;
52
+ }>;
12
53
  //# sourceMappingURL=server.d.ts.map