@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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,125 @@ All notable changes to `@cognium/mcp-server` are documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.2.1] - 2026-10-02
8
+
9
+ Tested against `circle-ir` **4.9.29** (range `4.9`), MCP SDK **^1.30.1** and the
10
+ `circle-ir-ai/mcp` module **4.17.0**. No tool was added, removed or renamed and
11
+ no schema changed: `tools/list` is identical to 0.2.0.
12
+
13
+ ### Changed
14
+ - **The package moved to its own repository,
15
+ [cogniumhq/cognium-mcp](https://github.com/cogniumhq/cognium-mcp)**, with its
16
+ history. The npm name, the bin name and everything the package exports are
17
+ unchanged; only `repository`, `homepage` and `bugs` in the manifest point
18
+ somewhere new. Issue numbers in earlier entries of this file refer to
19
+ [cogniumhq/cognium-dev](https://github.com/cogniumhq/cognium-dev), where the
20
+ package lived until 0.2.0.
21
+
22
+ ### Added
23
+ - A test that sends one fixed set of requests over stdio and over streamable
24
+ HTTP and compares the responses byte for byte, with an optional module loaded
25
+ on both.
26
+
27
+ ### Fixed
28
+ - The README told a reader running from a clone to start `dist/index.js`. Since
29
+ 0.2.0 that file is the side-effect-free library entry and starts nothing; the
30
+ binary is `dist/bin.js`.
31
+
32
+ ## [0.2.0] - 2026-10-01
33
+
34
+ Tested against `circle-ir` **4.9.29** (range `4.9`) and MCP SDK **^1.30.1**. No
35
+ tool was added, removed or renamed, and no response schema changed: `tools/list`
36
+ on a default install is the same eleven tools it was on 0.1.21.
37
+
38
+ ### Added
39
+ - **The package is importable.** `dist/index.js` is now a side-effect-free
40
+ library entry exporting `buildServer`, `createServer`, `ProjectCache` and the
41
+ types below. A host can build a server and mount it over its own transport
42
+ without spawning a subprocess.
43
+ - **Optional tool modules.** `buildServer({ modules })` takes an array of
44
+ `ToolModule` — `{ id, version, licence, circleIrRange, register(server, ctx) }`
45
+ — and registers each after the eleven built-in tools. A module receives
46
+ `ctx = { cache, enablement }`: the server's own analysis cache, so a module
47
+ need not parse a project twice, and what the install is allowed to offer.
48
+ - **`createServer()`** resolves the optional modules, computes enablement once
49
+ per process, and returns both the server and what it found.
50
+ - **Three states, reported not enforced.** `floor` (this package alone),
51
+ `extended` (an optional module loaded) and `commercial` (a licence token that
52
+ verified). The state is computed once from the environment and the user config
53
+ directory, and it decides what is *listed*; it locks no feature, and a module
54
+ that is installed stays installed whatever the state.
55
+ - **Offline licence verification** (`verifyLicence`): Ed25519 over a compact
56
+ signed token, with no network, no cache and nothing written. Verdicts are
57
+ `valid`, `expired`, `invalid-signature`, `malformed`, `no-key` and `absent`.
58
+ A wrong key and an altered payload are indistinguishable offline and both
59
+ report `invalid-signature`, which the tests assert rather than paper over.
60
+ No verification key is published yet, so tokens currently report `no-key`.
61
+ - **The token format.** `cognium-lic-v1.<base64url payload>.<base64url
62
+ signature>`, payload `{ kid, org, tier, iat, expiry, entitlements? }`. The
63
+ signature covers the payload's **canonical** form (RFC 8785), not the bytes
64
+ it arrived in, so a token survives being re-encoded in transit. `kid` names
65
+ the signing key and is itself signed, so keys rotate without invalidating
66
+ tokens already issued — a verifier keeps the retired key while tokens signed
67
+ by it are in date. The prefix is versioned, so a change to the shape is a
68
+ prefix bump rather than a silent break. The signature covers every member of
69
+ the payload, including ones this version does not read, so an issuer can add
70
+ a field without breaking verifiers already installed. A date-only `expiry`
71
+ is in date through the whole of that UTC day.
72
+ - **`canonicalise()`** — RFC 8785 JSON canonicalisation, forty lines and no new
73
+ dependency, tested against the RFC's own key-ordering vector.
74
+ - **One startup line** on stderr naming the version, the `circle-ir` it is
75
+ running against, the state, and any module loaded. Never the token, and never
76
+ the endpoint's value.
77
+
78
+ ### Changed
79
+ - **The bin moved from `dist/index.js` to `dist/bin.js`.** The bin *name*,
80
+ `mcp-server-cognium-dev`, is unchanged, so `npx @cognium/mcp-server` and every
81
+ existing client configuration keep working. This is the breaking part of the
82
+ minor bump: anything that executed the file path directly must point at
83
+ `dist/bin.js`. Importing the package no longer attaches a transport to the
84
+ importing process's stdin and stdout.
85
+ - **Server name and version come from the manifest.** They were string literals
86
+ and had drifted to `0.1.0` while the package was at `0.1.21`, so the
87
+ `initialize` handshake under-reported the version. It now reports the real one.
88
+ - Coverage thresholds ratcheted to the newly measured values (94 statements,
89
+ 84 branches, 96 functions, 96 lines).
90
+
91
+ ### Fixed
92
+ - A module that is absent, broken, wrongly shaped, built against another
93
+ `circle-ir` minor, or throwing from `register` can no longer take the server
94
+ down. Each case is refused on one stderr line and the eleven built-in tools
95
+ serve as normal. A patch-level `circle-ir` difference is accepted on purpose:
96
+ that is the release-time pin check's job, not the loader's.
97
+ - **#409: `.ts` files are parsed with the TypeScript grammar.** The server passed
98
+ `circle-ir` an explicit grammar map that loaded the JavaScript grammar for
99
+ `typescript`, overriding the library's own default. TypeScript-only syntax then
100
+ parsed as error-recovered garbage: an interface method signature
101
+ `query(text: string): Promise<T>;` became a `query(...)` call and was reported
102
+ as `sql_injection` and `missing-await` on the signature line. `.js` files are
103
+ unaffected, and `.tsx` already used its own grammar.
104
+
105
+ This also removes an order dependence. Another library in the same process
106
+ that initialised `circle-ir` first, with the TypeScript grammar, decided how
107
+ every later tool parsed `.ts` — so the same call could answer differently
108
+ depending on what had run before it.
109
+
110
+ #### Consumer Impact
111
+ - **Results for TypeScript files change, in both directions, with no error.**
112
+ Applies to every tool that analyses a project: `scan`, `taint_paths`,
113
+ `list_entry_points`, `attack_surface_summary`, `list_reachable_sinks`,
114
+ `explain_finding`, `find_similar`. On 20,988 `.ts` files from public
115
+ repositories, comparing the two grammars: **550 taint flows removed and 502
116
+ added**; sinks 1,433 removed and 1,953 added. Sampled removals were misparses
117
+ of casts, generics and type annotations read as calls. They were not all
118
+ labelled, so a removed flow is not guaranteed to have been a false positive.
119
+ - **Many more note-level findings on TypeScript**: 38,437 added against 2,432
120
+ removed on that corpus, mostly `missing-public-doc`, `variable-shadowing` and
121
+ `leaked-global`. The JavaScript grammar dropped whole functions and classes
122
+ that used TypeScript-only syntax, so those passes never saw them.
123
+ - A consumer holding a baseline of TypeScript findings should regenerate it.
124
+ JavaScript, and every other language, is unchanged.
125
+
7
126
  ## [0.1.21] - 2026-09-30
8
127
 
9
128
  ### Changed
package/README.md CHANGED
@@ -14,12 +14,12 @@ Ships every deterministic capability of circle-ir — polyglot taint analysis, c
14
14
  npm install -g @cognium/mcp-server
15
15
  ```
16
16
 
17
- Or run in-place from this monorepo:
17
+ Or run in place from a clone of this repository:
18
18
 
19
19
  ```bash
20
- cd packages/mcp-server
20
+ npm install
21
21
  npm run build
22
- node dist/index.js
22
+ node packages/mcp-server/dist/bin.js
23
23
  ```
24
24
 
25
25
  ## Client configuration
@@ -96,14 +96,85 @@ The same stdio config is bundled in the [Cognium SAST plugin](../../plugins/cogn
96
96
  4. `find_similar` to catch the same pattern elsewhere.
97
97
  5. Before proposing a fix, `check_sanitizer` any proposed wrapper against the target sink type.
98
98
 
99
+ ## Using it as a library
100
+
101
+ The package is side-effect free to import: nothing is built, read or connected
102
+ until you ask for it. The stdio binary is a separate file, so mounting the
103
+ server over your own transport does not spawn a subprocess.
104
+
105
+ ```ts
106
+ import { createServer } from '@cognium/mcp-server';
107
+
108
+ // Floor plus whatever optional modules this install has.
109
+ const { server, discovery } = await createServer();
110
+ console.error(discovery.enablement.state); // 'floor' | 'extended' | 'commercial'
111
+ await server.connect(myTransport);
112
+ ```
113
+
114
+ `buildServer(options)` is the synchronous form: it registers exactly what you
115
+ pass and resolves nothing.
116
+
117
+ ## Optional tool modules
118
+
119
+ The eleven tools above are always present. A separate package may add more by
120
+ exporting a `ToolModule`:
121
+
122
+ ```ts
123
+ export default {
124
+ id: 'example/mcp',
125
+ version: '1.0.0',
126
+ licence: 'MIT',
127
+ circleIrRange: '4.9', // the circle-ir major.minor it was built against
128
+ register(server, ctx) {
129
+ // ctx.cache — the server's analysis cache, shared with every tool
130
+ // ctx.enablement — what this install may offer; the module decides what
131
+ // to register, and checks again at call time
132
+ },
133
+ };
134
+ ```
135
+
136
+ Set `COGNIUM_MCP_MODULES` to a comma-separated list of specifiers to control
137
+ what is looked for, or to `none` to look for nothing.
138
+
139
+ **The server comes up either way.** A module that is absent, broken, wrongly
140
+ shaped or built against a different `circle-ir` minor is refused on one line of
141
+ stderr, and the eleven built-in tools serve as normal.
142
+
143
+ | Variable | Effect |
144
+ |---|---|
145
+ | `COGNIUM_MCP_MODULES` | Which module specifiers to look for. `none` disables. |
146
+ | `COGNIUM_ENDPOINT` | An opaque endpoint passed through to modules. The server never parses or connects to it. |
147
+ | `COGNIUM_LICENSE` | A licence token, verified offline. Also read from `$COGNIUM_CONFIG_DIR/license`, default `~/.cognium/license`. |
148
+ | `COGNIUM_LICENSE_PUBKEY` | Extra verification keys as `kid=key[,kid=key]`, base64url raw Ed25519, merged over the published ones. A bare key with no `kid=` matches any token, which is a development convenience and not for production. |
149
+
150
+ A token is `cognium-lic-v1.<base64url payload>.<base64url Ed25519 signature>`.
151
+ The payload is `{ kid, org, tier, iat, expiry, entitlements? }` and the
152
+ signature covers its **canonical** form (RFC 8785), so a token survives being
153
+ re-encoded in transit. `kid` names the signing key, so keys rotate without
154
+ invalidating tokens already issued: a verifier holds the old key as long as
155
+ tokens signed by it are still in date. An `expiry` given as a bare date is good
156
+ through the whole of that UTC day. A field the verifier does not know is still
157
+ covered by the signature; a known field of the wrong shape is `malformed`.
158
+
159
+ Verification is offline — a published key, no network, nothing cached or
160
+ written. No key is baked in yet, so tokens currently report `no-key`.
161
+
162
+ No telemetry, no phone-home, and no feature is locked behind a token: the state
163
+ decides what is *listed*, and the terms carry the grant.
164
+
99
165
  ## Development
100
166
 
101
167
  ```bash
102
- npm run build # tsc + chmod +x dist/index.js
168
+ npm run build # tsc + chmod +x dist/bin.js
103
169
  npm run typecheck # tsc --noEmit
104
- npm test # vitest run (unit + smoke)
170
+ npm test # vitest run (unit, three-state matrix, one answer, stdio smoke)
105
171
  ```
106
172
 
173
+ Two suites drive the built binary, so build before testing. From the repository
174
+ root, `npm run check:pins` checks the `circle-ir` pin and
175
+ `node scripts/verify-install.mjs <tarball>` installs a packed build into an
176
+ empty directory and checks what it serves.
177
+
107
178
  ## License
108
179
 
109
180
  MIT
package/dist/bin.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `@cognium/mcp-server` binary. Wires the server to stdio — the
4
+ * transport every MCP client (Claude Desktop, Claude Code, Cursor) speaks by
5
+ * default.
6
+ *
7
+ * This file is the bin and nothing else, so it may run `main()`
8
+ * unconditionally. The library entry is `index.ts`, which has no side
9
+ * effects: importing the package no longer attaches a transport to the host
10
+ * process's stdin and stdout, which is what made the package impossible to
11
+ * mount over HTTP before.
12
+ *
13
+ * WASM initialization stays deferred to the first tool invocation so
14
+ * `--version` and the initial handshake do not pay the ~200 ms tree-sitter
15
+ * cost.
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG"}
package/dist/bin.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `@cognium/mcp-server` binary. Wires the server to stdio — the
4
+ * transport every MCP client (Claude Desktop, Claude Code, Cursor) speaks by
5
+ * default.
6
+ *
7
+ * This file is the bin and nothing else, so it may run `main()`
8
+ * unconditionally. The library entry is `index.ts`, which has no side
9
+ * effects: importing the package no longer attaches a transport to the host
10
+ * process's stdin and stdout, which is what made the package impossible to
11
+ * mount over HTTP before.
12
+ *
13
+ * WASM initialization stays deferred to the first tool invocation so
14
+ * `--version` and the initial handshake do not pay the ~200 ms tree-sitter
15
+ * cost.
16
+ */
17
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
18
+ import { createServer } from './server.js';
19
+ import { startupLines } from './startup.js';
20
+ async function main() {
21
+ const { server, discovery } = await createServer();
22
+ for (const line of startupLines(discovery)) {
23
+ process.stderr.write(`${line}\n`);
24
+ }
25
+ const transport = new StdioServerTransport();
26
+ await server.connect(transport);
27
+ }
28
+ main().catch((err) => {
29
+ // stderr is safe for stdio-transport servers (stdout is reserved for MCP
30
+ // messages).
31
+ process.stderr.write(`[@cognium/mcp-server] fatal: ${err.stack ?? err}\n`);
32
+ process.exit(1);
33
+ });
34
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,KAAK,UAAU,IAAI;IACjB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,YAAY,EAAE,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,yEAAyE;IACzE,aAAa;IACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAiC,GAAa,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC;IACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Enablement — what this install is allowed to offer, computed once.
3
+ *
4
+ * Three states, and only three:
5
+ *
6
+ * floor the server alone. Deterministic tools, MIT, always.
7
+ * extended an optional tool module resolved and loaded.
8
+ * commercial extended, plus a licence token that verified.
9
+ *
10
+ * Two rules worth stating because they are easy to get wrong:
11
+ *
12
+ * - A token that verifies but with no module loaded is **not** commercial.
13
+ * Commercial is extended *plus* a token; with nothing extra installed
14
+ * there is nothing extra to licence, so the state is floor and the token
15
+ * is simply recorded.
16
+ * - Past expiry the install behaves as `extended`, never worse. Expiry
17
+ * removes commercial rights; it does not take away code the user already
18
+ * has, and it does not switch anything off.
19
+ *
20
+ * `endpoint` is an opaque string. The server records only *whether* one is
21
+ * configured and passes it through untouched; it never parses it, connects to
22
+ * it, or learns what is on the other end. That is the module's business.
23
+ *
24
+ * Computed once per process and memoized, because the HTTP host builds a
25
+ * fresh server per request (stateless transport) and so has no startup of its
26
+ * own to compute this at. Recomputing per request would re-read the
27
+ * environment and the config file on every call and could report two
28
+ * different states inside one process.
29
+ */
30
+ import { type LicenceVerdict } from './licence.js';
31
+ export type LicenceState = 'floor' | 'extended' | 'commercial';
32
+ export interface Enablement {
33
+ /** At least one optional tool module resolved and loaded. */
34
+ readonly installed: boolean;
35
+ /** A configured endpoint, verbatim and opaque, if there is one. */
36
+ readonly endpoint?: string;
37
+ /** The verdict on the configured token, or `absent` if there was none. */
38
+ readonly licence: LicenceVerdict;
39
+ readonly state: LicenceState;
40
+ }
41
+ /** Environment variables this module reads. Nothing else is consulted. */
42
+ export declare const ENV_ENDPOINT = "COGNIUM_ENDPOINT";
43
+ export declare const ENV_LICENSE = "COGNIUM_LICENSE";
44
+ export declare const ENV_LICENSE_PUBKEY = "COGNIUM_LICENSE_PUBKEY";
45
+ export declare const ENV_CONFIG_DIR = "COGNIUM_CONFIG_DIR";
46
+ /** Where `cognium license set` writes, when no config dir is given. */
47
+ export declare function configDir(env?: NodeJS.ProcessEnv): string;
48
+ export interface ComputeEnablementInput {
49
+ /** Whether an optional module loaded. Decided by the loader, not here. */
50
+ readonly installed: boolean;
51
+ readonly env?: NodeJS.ProcessEnv;
52
+ /** Clock injection point for expiry tests. */
53
+ readonly now?: Date;
54
+ }
55
+ /** Compute enablement from the environment and the user config dir. */
56
+ export declare function computeEnablement(input: ComputeEnablementInput): Enablement;
57
+ /**
58
+ * The process-wide enablement. First call computes it; every later call —
59
+ * including every request-scoped server the HTTP host builds — gets the same
60
+ * object back.
61
+ */
62
+ export declare function enablementForProcess(input: ComputeEnablementInput): Enablement;
63
+ /** Drop the memo. For tests; nothing in the server calls this. */
64
+ export declare function resetEnablementForTests(): void;
65
+ /** The floor state, for a server built with no modules at all. */
66
+ export declare function floorEnablement(): Enablement;
67
+ //# sourceMappingURL=enablement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enablement.d.ts","sourceRoot":"","sources":["../src/enablement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAKH,OAAO,EAAoC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAErF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,YAAY,CAAC;AAE/D,MAAM,WAAW,UAAU;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B;AAED,0EAA0E;AAC1E,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAC/C,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAC7C,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,cAAc,uBAAuB,CAAC;AAEnD,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAEtE;AAaD,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;CACrB;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAuB3E;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAG9E;AAED,kEAAkE;AAClE,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED,kEAAkE;AAClE,wBAAgB,eAAe,IAAI,UAAU,CAM5C"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Enablement — what this install is allowed to offer, computed once.
3
+ *
4
+ * Three states, and only three:
5
+ *
6
+ * floor the server alone. Deterministic tools, MIT, always.
7
+ * extended an optional tool module resolved and loaded.
8
+ * commercial extended, plus a licence token that verified.
9
+ *
10
+ * Two rules worth stating because they are easy to get wrong:
11
+ *
12
+ * - A token that verifies but with no module loaded is **not** commercial.
13
+ * Commercial is extended *plus* a token; with nothing extra installed
14
+ * there is nothing extra to licence, so the state is floor and the token
15
+ * is simply recorded.
16
+ * - Past expiry the install behaves as `extended`, never worse. Expiry
17
+ * removes commercial rights; it does not take away code the user already
18
+ * has, and it does not switch anything off.
19
+ *
20
+ * `endpoint` is an opaque string. The server records only *whether* one is
21
+ * configured and passes it through untouched; it never parses it, connects to
22
+ * it, or learns what is on the other end. That is the module's business.
23
+ *
24
+ * Computed once per process and memoized, because the HTTP host builds a
25
+ * fresh server per request (stateless transport) and so has no startup of its
26
+ * own to compute this at. Recomputing per request would re-read the
27
+ * environment and the config file on every call and could report two
28
+ * different states inside one process.
29
+ */
30
+ import { readFileSync } from 'node:fs';
31
+ import { homedir } from 'node:os';
32
+ import { join } from 'node:path';
33
+ import { verifyLicence, parsePublicKeyEnv } from './licence.js';
34
+ /** Environment variables this module reads. Nothing else is consulted. */
35
+ export const ENV_ENDPOINT = 'COGNIUM_ENDPOINT';
36
+ export const ENV_LICENSE = 'COGNIUM_LICENSE';
37
+ export const ENV_LICENSE_PUBKEY = 'COGNIUM_LICENSE_PUBKEY';
38
+ export const ENV_CONFIG_DIR = 'COGNIUM_CONFIG_DIR';
39
+ /** Where `cognium license set` writes, when no config dir is given. */
40
+ export function configDir(env = process.env) {
41
+ return env[ENV_CONFIG_DIR] ?? join(homedir(), '.cognium');
42
+ }
43
+ function tokenFromDisk(env) {
44
+ try {
45
+ const text = readFileSync(join(configDir(env), 'license'), 'utf8').trim();
46
+ return text === '' ? undefined : text;
47
+ }
48
+ catch {
49
+ // No file, no permission, a directory where a file should be — all mean
50
+ // the same thing to us: no token on disk.
51
+ return undefined;
52
+ }
53
+ }
54
+ /** Compute enablement from the environment and the user config dir. */
55
+ export function computeEnablement(input) {
56
+ const env = input.env ?? process.env;
57
+ const rawEndpoint = env[ENV_ENDPOINT]?.trim();
58
+ const endpoint = rawEndpoint === '' ? undefined : rawEndpoint;
59
+ const token = env[ENV_LICENSE]?.trim() || tokenFromDisk(env);
60
+ const licence = verifyLicence(token, {
61
+ publicKeys: parsePublicKeyEnv(env[ENV_LICENSE_PUBKEY]),
62
+ ...(input.now ? { now: input.now } : {}),
63
+ });
64
+ let state = 'floor';
65
+ if (input.installed) {
66
+ state = licence.status === 'valid' ? 'commercial' : 'extended';
67
+ }
68
+ return {
69
+ installed: input.installed,
70
+ ...(endpoint ? { endpoint } : {}),
71
+ licence,
72
+ state,
73
+ };
74
+ }
75
+ let memoized;
76
+ /**
77
+ * The process-wide enablement. First call computes it; every later call —
78
+ * including every request-scoped server the HTTP host builds — gets the same
79
+ * object back.
80
+ */
81
+ export function enablementForProcess(input) {
82
+ memoized ??= computeEnablement(input);
83
+ return memoized;
84
+ }
85
+ /** Drop the memo. For tests; nothing in the server calls this. */
86
+ export function resetEnablementForTests() {
87
+ memoized = undefined;
88
+ }
89
+ /** The floor state, for a server built with no modules at all. */
90
+ export function floorEnablement() {
91
+ return {
92
+ installed: false,
93
+ licence: { status: 'absent', detail: 'no licence token configured' },
94
+ state: 'floor',
95
+ };
96
+ }
97
+ //# sourceMappingURL=enablement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enablement.js","sourceRoot":"","sources":["../src/enablement.ts"],"names":[],"mappings":"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"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,17 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * Entry point for the `@cognium/mcp-server` binary. Wires the MCP
4
- * server to stdio transport — the transport every MCP client (Claude
5
- * Desktop, Claude Code, Cursor) speaks by default.
2
+ * The library entry for `@cognium/mcp-server`.
6
3
  *
7
- * WASM initialization is deferred to first tool invocation so that
8
- * `mcp-server-cognium-dev --version` and the initial handshake do not
9
- * pay the ~200ms tree-sitter cost.
4
+ * Side-effect free by design: importing this package builds nothing, reads
5
+ * nothing and connects nothing. A host that wants a server calls
6
+ * `createServer()` (floor plus whatever optional modules are installed) or
7
+ * `buildServer()` (exactly what it passes in). The stdio binary is `bin.ts`.
10
8
  */
11
- export {};
9
+ export { buildServer, createServer, discoverModules, resetDiscoveryForTests, SERVER_NAME, SERVER_VERSION, type BuildServerOptions, type Discovery, } from './server.js';
10
+ export { startupLines } from './startup.js';
11
+ export { loadModules, moduleSpecifiers, circleIrVersion, checkCircleIrRange, majorMinor, isToolModule, DEFAULT_MODULE_SPECIFIERS, ENV_MODULES, type ToolModule, type ModuleRefusal, type LoadModulesOptions, type LoadModulesResult, } from './modules.js';
12
+ export { computeEnablement, enablementForProcess, resetEnablementForTests, floorEnablement, configDir, ENV_ENDPOINT, ENV_LICENSE, ENV_LICENSE_PUBKEY, ENV_CONFIG_DIR, type Enablement, type LicenceState, } from './enablement.js';
13
+ export { verifyLicence, encodeLicence, parsePublicKeyEnv, TOKEN_PREFIX, BUILTIN_PUBLIC_KEYS, ANY_KID, type LicencePayload, type LicenceStatus, type LicenceVerdict, type VerifyOptions, } from './licence.js';
14
+ export { canonicalise, canonicalBytes, JcsError } from './jcs.js';
15
+ export { ProjectCache, type ProjectScanOptions } from './cache.js';
16
+ export { type ToolContext, type ToolResult } from './tools/types.js';
12
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,yBAAyB,EACzB,WAAW,EACX,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,24 +1,16 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * Entry point for the `@cognium/mcp-server` binary. Wires the MCP
4
- * server to stdio transport — the transport every MCP client (Claude
5
- * Desktop, Claude Code, Cursor) speaks by default.
2
+ * The library entry for `@cognium/mcp-server`.
6
3
  *
7
- * WASM initialization is deferred to first tool invocation so that
8
- * `mcp-server-cognium-dev --version` and the initial handshake do not
9
- * pay the ~200ms tree-sitter cost.
4
+ * Side-effect free by design: importing this package builds nothing, reads
5
+ * nothing and connects nothing. A host that wants a server calls
6
+ * `createServer()` (floor plus whatever optional modules are installed) or
7
+ * `buildServer()` (exactly what it passes in). The stdio binary is `bin.ts`.
10
8
  */
11
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
12
- import { buildServer } from './server.js';
13
- async function main() {
14
- const server = buildServer();
15
- const transport = new StdioServerTransport();
16
- await server.connect(transport);
17
- }
18
- main().catch((err) => {
19
- // stderr is safe for stdio-transport servers (stdout is reserved for
20
- // MCP messages).
21
- process.stderr.write(`[mcp-server-cognium-dev] fatal: ${err.stack ?? err}\n`);
22
- process.exit(1);
23
- });
9
+ export { buildServer, createServer, discoverModules, resetDiscoveryForTests, SERVER_NAME, SERVER_VERSION, } from './server.js';
10
+ export { startupLines } from './startup.js';
11
+ export { loadModules, moduleSpecifiers, circleIrVersion, checkCircleIrRange, majorMinor, isToolModule, DEFAULT_MODULE_SPECIFIERS, ENV_MODULES, } from './modules.js';
12
+ export { computeEnablement, enablementForProcess, resetEnablementForTests, floorEnablement, configDir, ENV_ENDPOINT, ENV_LICENSE, ENV_LICENSE_PUBKEY, ENV_CONFIG_DIR, } from './enablement.js';
13
+ export { verifyLicence, encodeLicence, parsePublicKeyEnv, TOKEN_PREFIX, BUILTIN_PUBLIC_KEYS, ANY_KID, } from './licence.js';
14
+ export { canonicalise, canonicalBytes, JcsError } from './jcs.js';
15
+ export { ProjectCache } from './cache.js';
24
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,qEAAqE;IACrE,iBAAiB;IACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAoC,GAAa,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC;IACzF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,WAAW,EACX,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,cAAc,GAGf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,yBAAyB,EACzB,WAAW,GAKZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,cAAc,GAGf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,OAAO,GAKR,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAElE,OAAO,EAAE,YAAY,EAA2B,MAAM,YAAY,CAAC"}
package/dist/jcs.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * JSON Canonicalization Scheme (RFC 8785).
3
+ *
4
+ * One byte sequence per JSON value, so a signature over a payload survives
5
+ * being re-encoded by anything that handles it on the way. The licence token
6
+ * signs the canonical form rather than the bytes it happened to arrive in.
7
+ *
8
+ * Implemented here rather than taken as a dependency: it is forty lines, and
9
+ * this package keeps its dependency list short on purpose.
10
+ *
11
+ * Two pieces come free from the platform and are worth stating so nobody
12
+ * "fixes" them later:
13
+ *
14
+ * - `JSON.stringify` on a string already produces JCS-conformant escaping.
15
+ * It escapes only `"`, `\` and the C0 controls, uses the short forms
16
+ * (`\b \t \n \f \r`) where RFC 8785 requires them, `\uXXXX` for the rest,
17
+ * leaves every other code point as literal UTF-8, and escapes lone
18
+ * surrogates — all exactly as the RFC specifies.
19
+ * - `Array.prototype.sort()` with no comparator orders strings by UTF-16
20
+ * code unit, which is the ordering RFC 8785 §3.2.3 mandates for keys.
21
+ */
22
+ /** Thrown for input JSON cannot represent canonically. */
23
+ export declare class JcsError extends Error {
24
+ }
25
+ export declare function canonicalise(value: unknown): string;
26
+ /** The canonical form as the bytes a signature covers. */
27
+ export declare function canonicalBytes(value: unknown): Buffer;
28
+ //# sourceMappingURL=jcs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jcs.d.ts","sourceRoot":"","sources":["../src/jcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,0DAA0D;AAC1D,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAoCnD;AAED,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
package/dist/jcs.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * JSON Canonicalization Scheme (RFC 8785).
3
+ *
4
+ * One byte sequence per JSON value, so a signature over a payload survives
5
+ * being re-encoded by anything that handles it on the way. The licence token
6
+ * signs the canonical form rather than the bytes it happened to arrive in.
7
+ *
8
+ * Implemented here rather than taken as a dependency: it is forty lines, and
9
+ * this package keeps its dependency list short on purpose.
10
+ *
11
+ * Two pieces come free from the platform and are worth stating so nobody
12
+ * "fixes" them later:
13
+ *
14
+ * - `JSON.stringify` on a string already produces JCS-conformant escaping.
15
+ * It escapes only `"`, `\` and the C0 controls, uses the short forms
16
+ * (`\b \t \n \f \r`) where RFC 8785 requires them, `\uXXXX` for the rest,
17
+ * leaves every other code point as literal UTF-8, and escapes lone
18
+ * surrogates — all exactly as the RFC specifies.
19
+ * - `Array.prototype.sort()` with no comparator orders strings by UTF-16
20
+ * code unit, which is the ordering RFC 8785 §3.2.3 mandates for keys.
21
+ */
22
+ /** Thrown for input JSON cannot represent canonically. */
23
+ export class JcsError extends Error {
24
+ }
25
+ export function canonicalise(value) {
26
+ if (value === null)
27
+ return 'null';
28
+ switch (typeof value) {
29
+ case 'boolean':
30
+ return value ? 'true' : 'false';
31
+ case 'number':
32
+ // RFC 8785 §3.2.2.3 defers number serialization to ECMAScript's
33
+ // Number-to-String, which is what JSON.stringify applies. Non-finite
34
+ // values have no JSON form at all.
35
+ if (!Number.isFinite(value))
36
+ throw new JcsError(`cannot canonicalise ${String(value)}`);
37
+ return JSON.stringify(value);
38
+ case 'string':
39
+ return JSON.stringify(value);
40
+ case 'object':
41
+ break;
42
+ default:
43
+ throw new JcsError(`cannot canonicalise a ${typeof value}`);
44
+ }
45
+ if (Array.isArray(value)) {
46
+ return `[${value.map((v) => canonicalise(v)).join(',')}]`;
47
+ }
48
+ const entries = Object.entries(value)
49
+ // `undefined` is absent rather than null, matching JSON.stringify.
50
+ .filter(([, v]) => v !== undefined);
51
+ // Sort on the key as written: the default comparator is UTF-16 code unit
52
+ // order, which is what the RFC asks for.
53
+ entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
54
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalise(v)}`).join(',')}}`;
55
+ }
56
+ /** The canonical form as the bytes a signature covers. */
57
+ export function canonicalBytes(value) {
58
+ return Buffer.from(canonicalise(value), 'utf8');
59
+ }
60
+ //# sourceMappingURL=jcs.js.map