@cognium-ai/mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,120 @@
1
+ PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ Required Notice: Copyright (c) 2025 Cognium Labs
6
+
7
+ Acceptance
8
+
9
+ To obtain any license under these terms, you must agree to them as both
10
+ strict obligations and conditions to all your licenses.
11
+
12
+ Copyright License
13
+
14
+ The licensor grants you a copyright license for the software to do
15
+ everything you might do with the software that would otherwise infringe
16
+ the licensor's copyright in it for any permitted purpose. However, you
17
+ may only distribute the software according to Distribution License and
18
+ make changes or new works based on the software according to Changes and
19
+ New Works License.
20
+
21
+ Distribution License
22
+
23
+ The licensor grants you an additional copyright license to distribute
24
+ copies of the software. Your license to distribute covers distributing
25
+ the software with changes and new works permitted by Changes and New
26
+ Works License.
27
+
28
+ Notices
29
+
30
+ You must ensure that anyone who gets a copy of any part of the software
31
+ from you also gets a copy of these terms or the URL for them above, as
32
+ well as copies of any plain-text lines beginning with Required Notice:
33
+ that the licensor provided with the software. For example:
34
+
35
+ Required Notice: Copyright (c) 2025 Cognium Labs
36
+
37
+ Changes and New Works License
38
+
39
+ The licensor grants you an additional copyright license to make changes
40
+ and new works based on the software for any permitted purpose.
41
+
42
+ Patent License
43
+
44
+ The licensor grants you a patent license for the software that covers
45
+ patent claims the licensor can license, or becomes able to license, that
46
+ you would infringe by using the software.
47
+
48
+ Noncommercial Purposes
49
+
50
+ Any noncommercial purpose is a permitted purpose.
51
+
52
+ Personal Uses
53
+
54
+ Personal use for research, experiment, and testing for the benefit of
55
+ public knowledge, personal study, private entertainment, hobby projects,
56
+ amateur pursuits, or religious observance, without any anticipated
57
+ commercial application, is use for a permitted purpose.
58
+
59
+ Noncommercial Organizations
60
+
61
+ Use by any charitable organization, educational institution, public
62
+ research organization, public safety or health organization,
63
+ environmental protection organization, or government institution is use
64
+ for a permitted purpose regardless of the source of funding or
65
+ obligations resulting from the funding.
66
+
67
+ Fair Use
68
+
69
+ You may have "fair use" rights for the software under the law. These
70
+ terms do not limit them.
71
+
72
+ No Other Rights
73
+
74
+ These terms do not allow you to sublicense or transfer any of your
75
+ licenses to anyone else, or prevent the licensor from granting licenses
76
+ to anyone else. These terms do not imply any other licenses.
77
+
78
+ Patent Defense
79
+
80
+ If you make any written claim that the software infringes or contributes
81
+ to infringement of any patent, your patent license for the software
82
+ granted under these terms ends immediately. If your company makes such a
83
+ claim, your patent license ends immediately for work on behalf of your
84
+ company.
85
+
86
+ Violations
87
+
88
+ The first time you are notified in writing that you have violated any of
89
+ these terms, or done anything with the software not covered by your
90
+ licenses, your licenses can nonetheless continue if you come into full
91
+ compliance with these terms, and take practical steps to correct past
92
+ violations, within 32 days of receiving notice. Otherwise, all your
93
+ licenses end immediately.
94
+
95
+ No Liability
96
+
97
+ As far as the law allows, the software comes as is, without any warranty
98
+ or condition, and the licensor will not be liable to you for any damages
99
+ arising out of these terms or the use or nature of the software, under
100
+ any kind of legal claim.
101
+
102
+ Definitions
103
+
104
+ The licensor is the individual or entity offering these terms, and the
105
+ software is the software the licensor makes available under these terms.
106
+
107
+ You refers to the individual or entity agreeing to these terms.
108
+
109
+ Your company is any legal entity, sole proprietorship, or other kind of
110
+ organization that you work for, plus all organizations that have control
111
+ over, are under the control of, or are under common control with that
112
+ organization. Control means ownership of substantially all the assets of
113
+ an entity, or the power to direct its management and policies by vote,
114
+ contract, or otherwise. Control can be direct or indirect.
115
+
116
+ Your licenses are all the licenses granted to you for the software under
117
+ these terms.
118
+
119
+ Use means anything you do with the software requiring one of your
120
+ licenses.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @cognium-ai/mcp-server
2
+
3
+ An [MCP](https://modelcontextprotocol.io) server exposing Cognium's
4
+ spec-conformance, spec-drift, and pattern-search tools over **stdio**. Backed
5
+ by the [`circle-ir-ai`](https://www.npmjs.com/package/circle-ir-ai) engine's
6
+ `analyzeSpecGap`.
7
+
8
+ ## Install & run
9
+
10
+ ```bash
11
+ npm install -g @cognium-ai/mcp-server
12
+ cognium-mcp # speaks MCP JSON-RPC over stdin/stdout
13
+ ```
14
+
15
+ Or wire it into an MCP client config:
16
+
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "cognium": {
21
+ "command": "npx",
22
+ "args": ["-y", "@cognium-ai/mcp-server"]
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ Inspect it interactively:
29
+
30
+ ```bash
31
+ npx @modelcontextprotocol/inspector cognium-mcp
32
+ ```
33
+
34
+ ## Tools
35
+
36
+ ### `verify_spec_conformance`
37
+
38
+ Analyze how well code conforms to its [Specifica](https://www.npmjs.com/package/circle-ir-ai)
39
+ spec.
40
+
41
+ **Input**
42
+
43
+ | field | type | description |
44
+ |-------------|--------|-----------------------------------------------|
45
+ | `spec_dir` | string | Path to the `.specifica/` directory (spec.md) |
46
+ | `code_root` | string | Path to the code root to analyze |
47
+
48
+ **Output**
49
+
50
+ ```jsonc
51
+ {
52
+ "alignment_score": 100, // 0–100
53
+ "requirements": [
54
+ { "id": "REQ-001", "status": "covered", "evidence": { "function": "calculateTotal" } },
55
+ { "id": "REQ-002", "status": "partial", "evidence": { "function": "applyDiscount" } },
56
+ { "id": "REQ-003", "status": "uncovered", "evidence": {} }
57
+ ],
58
+ "summary": "2/3 requirements covered (67%); 0 undocumented behaviors"
59
+ }
60
+ ```
61
+
62
+ `status` is derived from the engine's match confidence:
63
+
64
+ - `covered` — confidence **≥ 0.7**
65
+ - `partial` — matched but confidence **< 0.7**
66
+ - `uncovered` — no matching code behavior
67
+
68
+ > The engine has no native "partial" state; it is a boundary heuristic at
69
+ > confidence 0.7 over the engine's already-filtered match set
70
+ > (min confidence 0.3).
71
+
72
+ ### `find_spec_drift`
73
+
74
+ Report drift in both directions.
75
+
76
+ **Input:** same as above (`spec_dir`, `code_root`).
77
+
78
+ **Output**
79
+
80
+ ```jsonc
81
+ {
82
+ "drifts": [
83
+ { "kind": "code_without_spec", "location": "deleteUser", "suggested_action": "Document deleteUser: ..." },
84
+ { "kind": "spec_without_code", "location": "REQ-004", "suggested_action": "Implement REQ-004: ..." }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ - `code_without_spec` — an undocumented public behavior (engine
90
+ `undocumentedBehaviors`).
91
+ - `spec_without_code` — a requirement with no matching code (engine
92
+ `uncoveredRequirements`).
93
+
94
+ ### `find_pattern`
95
+
96
+ Search file contents under a code root with a JavaScript regular expression.
97
+
98
+ **Input**
99
+
100
+ | field | type | description |
101
+ |-------------|--------|---------------------------------------------------|
102
+ | `pattern` | string | JS `RegExp` source (applied with the global flag) |
103
+ | `code_root` | string | Path to the code root to search |
104
+
105
+ **Output**
106
+
107
+ ```jsonc
108
+ {
109
+ "matches": [
110
+ { "file": "src/cart.ts", "span": [3, 3], "snippet": "return price * quantity;" }
111
+ ]
112
+ }
113
+ ```
114
+
115
+ > `span` is **line-based** `[startLine, endLine]` (1-based), **not** character
116
+ > offsets. Binary/large files (> 1 MiB) and common build/vendor directories are
117
+ > skipped; results are capped at 1000 matches.
118
+
119
+ ## Field mapping (engine → MCP boundary)
120
+
121
+ The engine emits camelCase; this server renames to snake_case at the boundary.
122
+
123
+ | MCP field | engine source (`SpecGapResult`) |
124
+ |----------------------------|---------------------------------------------------------|
125
+ | `alignment_score` | `specAlignmentScore` |
126
+ | `requirements[].id` | `coveredRequirements[].requirement.id` / `uncoveredRequirements[].requirement.id` |
127
+ | `requirements[].status` | derived from `coveredRequirements[].confidence` (≥0.7) |
128
+ | `requirements[].evidence.function` | `coveredRequirements[].matchedFunction` |
129
+ | `drifts` (code_without_spec) | `undocumentedBehaviors[]` → `{functionName, suggestion}` |
130
+ | `drifts` (spec_without_code) | `uncoveredRequirements[]` → `{requirement.id, reason}` |
131
+
132
+ ## Schema stability
133
+
134
+ Tool input/output field names are **draft-stable through 2026-08-31**. Additive
135
+ fields are non-breaking; renames or removals are breaking changes (major bump).
136
+
137
+ ## Runtime support
138
+
139
+ Works under **Node** (≥18) and **Bun**. circle-ir's WASM is resolved via
140
+ `createRequire(import.meta.url)` from `node_modules/circle-ir`, so no symlink is
141
+ required under either runtime. Both are exercised by the CI stdio smoke matrix.
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ npm install # installs deps and builds (prepare → tsc)
147
+ npm run typecheck
148
+ npm test # vitest: mapper unit tests
149
+ npm run smoke # spawn dist/index.js over stdio against the demo fixture
150
+ ```
151
+
152
+ ## License
153
+
154
+ PolyForm Noncommercial License 1.0.0 — see [LICENSE](./LICENSE).
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Circle-IR loading for the MCP server.
3
+ *
4
+ * Wraps circle-ir-ai's analyzer lifecycle: initialize the WASM-backed
5
+ * analyzer once, walk the code root for supported source files, and run
6
+ * circle-ir's `analyze` per file. The resulting `CircleIR[]` is the input to
7
+ * `analyzeSpecGap` (used by the verify/drift tools).
8
+ *
9
+ * Mirrors the wiring recipe in cognium-ai's `spec-diff` command, but depends
10
+ * only on `circle-ir` + `circle-ir-ai` (not the cognium-ai CLI).
11
+ */
12
+ import { type CircleIR } from 'circle-ir';
13
+ import { type WalkOptions } from './walk.js';
14
+ export interface LoadedCircleIR {
15
+ /** Absolute path to the analyzed code root. */
16
+ codePath: string;
17
+ /** Per-file circle-ir analysis results. */
18
+ results: CircleIR[];
19
+ }
20
+ /**
21
+ * Walk `codeRoot`, analyze each supported source file, and return the
22
+ * collected `CircleIR[]` alongside the resolved code path.
23
+ */
24
+ export declare function loadCircleIR(codeRoot: string, options?: WalkOptions): Promise<LoadedCircleIR>;
25
+ //# sourceMappingURL=analysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../src/analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,OAAO,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,cAAc,CAAC,CAwBzB"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Circle-IR loading for the MCP server.
3
+ *
4
+ * Wraps circle-ir-ai's analyzer lifecycle: initialize the WASM-backed
5
+ * analyzer once, walk the code root for supported source files, and run
6
+ * circle-ir's `analyze` per file. The resulting `CircleIR[]` is the input to
7
+ * `analyzeSpecGap` (used by the verify/drift tools).
8
+ *
9
+ * Mirrors the wiring recipe in cognium-ai's `spec-diff` command, but depends
10
+ * only on `circle-ir` + `circle-ir-ai` (not the cognium-ai CLI).
11
+ */
12
+ import * as fs from 'fs';
13
+ import * as path from 'path';
14
+ import { analyze } from 'circle-ir';
15
+ import { ensureAnalyzerInitialized } from 'circle-ir-ai';
16
+ import { collectSourceFiles } from './walk.js';
17
+ /**
18
+ * Walk `codeRoot`, analyze each supported source file, and return the
19
+ * collected `CircleIR[]` alongside the resolved code path.
20
+ */
21
+ export async function loadCircleIR(codeRoot, options = {}) {
22
+ await ensureAnalyzerInitialized();
23
+ const codePath = path.resolve(codeRoot);
24
+ const files = collectSourceFiles(codePath, options);
25
+ const results = [];
26
+ for (const file of files) {
27
+ let content;
28
+ try {
29
+ content = fs.readFileSync(file.absolutePath, 'utf-8');
30
+ }
31
+ catch {
32
+ continue;
33
+ }
34
+ try {
35
+ const ir = await analyze(content, path.basename(file.absolutePath), file.language);
36
+ results.push(ir);
37
+ }
38
+ catch {
39
+ // Skip files circle-ir can't parse; spec-gap tolerates a partial corpus.
40
+ continue;
41
+ }
42
+ }
43
+ return { codePath, results };
44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AAC"}
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Entry point for the Cognium MCP server.
4
+ *
5
+ * Connects the server to stdio so MCP clients (e.g. cognium-code) can spawn
6
+ * it as a subprocess and communicate over stdin/stdout.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Entry point for the Cognium MCP server.
4
+ *
5
+ * Connects the server to stdio so MCP clients (e.g. cognium-code) can spawn
6
+ * it as a subprocess and communicate over stdin/stdout.
7
+ */
8
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
9
+ import { buildServer } from './server.js';
10
+ async function main() {
11
+ const server = buildServer();
12
+ const transport = new StdioServerTransport();
13
+ await server.connect(transport);
14
+ }
15
+ main().catch((err) => {
16
+ // Logging to stderr keeps stdout clean for the JSON-RPC stream.
17
+ console.error('Fatal error in cognium-mcp:', err);
18
+ process.exit(1);
19
+ });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG;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,gEAAgE;IAChE,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Pure mappers from the engine's `SpecGapResult` (camelCase) to the MCP
3
+ * boundary shapes (snake_case). Kept side-effect-free so they can be unit
4
+ * tested without spinning up the analyzer.
5
+ *
6
+ * Schema stability: field names here are draft-stable through 2026-08-31.
7
+ * Additive changes are safe; renames/removals are breaking (bump major).
8
+ */
9
+ import type { SpecGapResult } from 'circle-ir-ai';
10
+ /** Confidence at/above which a covered match is "covered" vs "partial". */
11
+ export declare const PARTIAL_CONFIDENCE_THRESHOLD = 0.7;
12
+ export type RequirementStatus = 'covered' | 'partial' | 'uncovered';
13
+ export interface RequirementEvidence {
14
+ function?: string;
15
+ file?: string;
16
+ span?: [number, number];
17
+ }
18
+ export interface VerifyRequirement {
19
+ id: string;
20
+ status: RequirementStatus;
21
+ evidence: RequirementEvidence;
22
+ }
23
+ export interface VerifyConformanceResult {
24
+ alignment_score: number;
25
+ requirements: VerifyRequirement[];
26
+ summary: string;
27
+ }
28
+ export type DriftKind = 'code_without_spec' | 'spec_without_code';
29
+ export interface Drift {
30
+ kind: DriftKind;
31
+ location: string;
32
+ suggested_action: string;
33
+ }
34
+ export interface FindSpecDriftResult {
35
+ drifts: Drift[];
36
+ }
37
+ /** Map a `SpecGapResult` to the `verify_spec_conformance` output shape. */
38
+ export declare function toVerifyConformance(result: SpecGapResult): VerifyConformanceResult;
39
+ /** Map a `SpecGapResult` to the `find_spec_drift` output shape. */
40
+ export declare function toSpecDrift(result: SpecGapResult): FindSpecDriftResult;
41
+ //# sourceMappingURL=mappers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,2EAA2E;AAC3E,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,SAAS,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAElE,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,uBAAuB,CA6BlF;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,mBAAmB,CAqBtE"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Pure mappers from the engine's `SpecGapResult` (camelCase) to the MCP
3
+ * boundary shapes (snake_case). Kept side-effect-free so they can be unit
4
+ * tested without spinning up the analyzer.
5
+ *
6
+ * Schema stability: field names here are draft-stable through 2026-08-31.
7
+ * Additive changes are safe; renames/removals are breaking (bump major).
8
+ */
9
+ /** Confidence at/above which a covered match is "covered" vs "partial". */
10
+ export const PARTIAL_CONFIDENCE_THRESHOLD = 0.7;
11
+ /** Map a `SpecGapResult` to the `verify_spec_conformance` output shape. */
12
+ export function toVerifyConformance(result) {
13
+ const requirements = [];
14
+ for (const match of result.coveredRequirements) {
15
+ requirements.push({
16
+ id: match.requirement.id,
17
+ status: match.confidence >= PARTIAL_CONFIDENCE_THRESHOLD ? 'covered' : 'partial',
18
+ evidence: { function: match.matchedFunction },
19
+ });
20
+ }
21
+ for (const uncovered of result.uncoveredRequirements) {
22
+ requirements.push({
23
+ id: uncovered.requirement.id,
24
+ status: 'uncovered',
25
+ evidence: {},
26
+ });
27
+ }
28
+ const { covered, totalRequirements, coveragePercent, undocumented } = result.summary;
29
+ const summary = `${covered}/${totalRequirements} requirements covered (${coveragePercent}%); ` +
30
+ `${undocumented} undocumented behaviors`;
31
+ return {
32
+ alignment_score: result.specAlignmentScore,
33
+ requirements,
34
+ summary,
35
+ };
36
+ }
37
+ /** Map a `SpecGapResult` to the `find_spec_drift` output shape. */
38
+ export function toSpecDrift(result) {
39
+ const drifts = [];
40
+ for (const behavior of result.undocumentedBehaviors) {
41
+ drifts.push({
42
+ kind: 'code_without_spec',
43
+ location: behavior.functionName,
44
+ suggested_action: behavior.suggestion,
45
+ });
46
+ }
47
+ for (const uncovered of result.uncoveredRequirements) {
48
+ const { id, description } = uncovered.requirement;
49
+ drifts.push({
50
+ kind: 'spec_without_code',
51
+ location: id,
52
+ suggested_action: uncovered.reason || `Implement ${id}: ${description}`,
53
+ });
54
+ }
55
+ return { drifts };
56
+ }
57
+ //# sourceMappingURL=mappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mappers.js","sourceRoot":"","sources":["../src/mappers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAkChD,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CAAC,MAAqB;IACvD,MAAM,Y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,qBAAqB,EAAE,CAAC;QACrD,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,mBAAmB;YACzB,QAAQ,EAAE,EAAE;YACZ,gBAAgB,EAAE,SAAS,CAAC,MAAM,IAAI,aAAa,EAAE,KAAK,WAAW,EAAE;SACxE,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Builds the Cognium MCP server and registers all tools.
3
+ */
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ export declare function buildServer(): McpServer;
6
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,wBAAgB,WAAW,IAAI,SAAS,CAWvC"}
package/dist/server.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Builds the Cognium MCP server and registers all tools.
3
+ */
4
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { registerVerifySpecConformance } from './tools/verify-spec-conformance.js';
6
+ import { registerFindSpecDrift } from './tools/find-spec-drift.js';
7
+ import { registerFindPattern } from './tools/find-pattern.js';
8
+ export function buildServer() {
9
+ const server = new McpServer({
10
+ name: 'cognium-mcp',
11
+ version: '0.1.0',
12
+ });
13
+ registerVerifySpecConformance(server);
14
+ registerFindSpecDrift(server);
15
+ registerFindPattern(server);
16
+ return server;
17
+ }
18
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,6BAA6B,CAAC,MAAM,CAAC,CAAC;IACtC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9B,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE5B,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `find_pattern` MCP tool (stretch).
3
+ *
4
+ * Runs a JavaScript regular expression over the text contents of files under
5
+ * a code root and returns the matches with a line-based span and a snippet.
6
+ *
7
+ * NOTE: `span` is `[startLine, endLine]` (1-based, line-based — NOT character
8
+ * offsets). Documented in README; adaptable to char offsets additively if a
9
+ * consumer needs them.
10
+ */
11
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
12
+ export declare function registerFindPattern(server: McpServer): void;
13
+ //# sourceMappingURL=find-pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-pattern.d.ts","sourceRoot":"","sources":["../../src/tools/find-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAoCzE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA6D3D"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * `find_pattern` MCP tool (stretch).
3
+ *
4
+ * Runs a JavaScript regular expression over the text contents of files under
5
+ * a code root and returns the matches with a line-based span and a snippet.
6
+ *
7
+ * NOTE: `span` is `[startLine, endLine]` (1-based, line-based — NOT character
8
+ * offsets). Documented in README; adaptable to char offsets additively if a
9
+ * consumer needs them.
10
+ */
11
+ import * as fs from 'fs';
12
+ import { z } from 'zod';
13
+ import { walkFiles } from '../walk.js';
14
+ /** Hard cap on total matches returned across all files. */
15
+ const MAX_MATCHES = 1000;
16
+ const inputSchema = {
17
+ pattern: z.string().describe('JavaScript regular expression (applied with the global flag)'),
18
+ code_root: z.string().describe('Path to the code root to search'),
19
+ };
20
+ const outputSchema = {
21
+ matches: z.array(z.object({
22
+ file: z.string(),
23
+ span: z.tuple([z.number(), z.number()]),
24
+ snippet: z.string(),
25
+ })),
26
+ };
27
+ /** Count newlines in `text` before byte index `end`. */
28
+ function lineAt(text, end) {
29
+ let line = 1;
30
+ for (let i = 0; i < end && i < text.length; i++) {
31
+ if (text[i] === '\n')
32
+ line++;
33
+ }
34
+ return line;
35
+ }
36
+ export function registerFindPattern(server) {
37
+ server.registerTool('find_pattern', {
38
+ title: 'Find Pattern',
39
+ description: 'Search file contents under a code root with a JavaScript regular ' +
40
+ 'expression. Returns matches with a 1-based line span [start, end] and ' +
41
+ 'a trimmed snippet. Skips binary/large files and common excludes.',
42
+ inputSchema,
43
+ outputSchema,
44
+ }, async ({ pattern, code_root }) => {
45
+ const matches = [];
46
+ const files = walkFiles(code_root);
47
+ for (const file of files) {
48
+ if (matches.length >= MAX_MATCHES)
49
+ break;
50
+ let content;
51
+ try {
52
+ content = fs.readFileSync(file.absolutePath, 'utf-8');
53
+ }
54
+ catch {
55
+ continue;
56
+ }
57
+ // Fresh regex per file so lastIndex state never leaks across files.
58
+ let re;
59
+ try {
60
+ re = new RegExp(pattern, 'g');
61
+ }
62
+ catch (err) {
63
+ throw new Error(`Invalid regular expression: ${err.message}`);
64
+ }
65
+ let m;
66
+ while ((m = re.exec(content)) !== null) {
67
+ const startLine = lineAt(content, m.index);
68
+ const matched = m[0];
69
+ const newlines = (matched.match(/\n/g) ?? []).length;
70
+ const endLine = startLine + newlines;
71
+ const snippet = matched.split('\n')[0].trim();
72
+ matches.push({
73
+ file: file.relativePath,
74
+ span: [startLine, endLine],
75
+ snippet,
76
+ });
77
+ if (matches.length >= MAX_MATCHES)
78
+ break;
79
+ // Guard against zero-width matches looping forever.
80
+ if (m.index === re.lastIndex)
81
+ re.lastIndex++;
82
+ }
83
+ }
84
+ const payload = { matches };
85
+ return {
86
+ content: [{ type: 'text', text: JSON.stringify(payload) }],
87
+ structuredContent: payload,
88
+ };
89
+ });
90
+ }
91
+ //# sourceMappingURL=find-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-pattern.js","sourceRoot":"","sources":["../../src/tools/find-pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,2DAA2D;AAC3D,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC;IAC5F,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;CAClE,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,CAAC,CAAC,KAAK,CACd,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB,CAAC,CACH;CACF,CAAC;AAQF,wDAAwD;AACxD,SAAS,MAAM,CAAC,IAAY,EAAE,GAAW;IACvC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAA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vC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBAC3C,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrB,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;gBACrD,MAAM,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;gBACrC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;gBAE/C,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,IAAI,CAAC,YAAY;oBACvB,IAAI,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;oBAC1B,OAAO;iBACR,CAAC,CAAC;gBAEH,IAAI,OAAO,CAAC,MAAM,IAAI,WAAW;oBAAE,MAAM;gBACzC,oDAAoD;gBACpD,IAAI,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,SAAS;oBAAE,EAAE,CAAC,SAAS,EAAE,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,EAAE,OAAO,EAAE,CAAC;QAC5B,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1D,iBAAiB,EAAE,OAA6C;SACjE,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * `find_spec_drift` MCP tool.
3
+ *
4
+ * Reports drift between code and spec: code paths with no matching
5
+ * requirement (code_without_spec) and requirements with no matching code
6
+ * (spec_without_code), each with a suggested remediation.
7
+ */
8
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ export declare function registerFindSpecDrift(server: McpServer): void;
10
+ //# sourceMappingURL=find-spec-drift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-spec-drift.d.ts","sourceRoot":"","sources":["../../src/tools/find-spec-drift.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAoBzE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAsB7D"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `find_spec_drift` MCP tool.
3
+ *
4
+ * Reports drift between code and spec: code paths with no matching
5
+ * requirement (code_without_spec) and requirements with no matching code
6
+ * (spec_without_code), each with a suggested remediation.
7
+ */
8
+ import { z } from 'zod';
9
+ import { analyzeSpecGap } from 'circle-ir-ai';
10
+ import { loadCircleIR } from '../analysis.js';
11
+ import { toSpecDrift } from '../mappers.js';
12
+ const inputSchema = {
13
+ spec_dir: z.string().describe('Path to the .specifica/ directory containing spec.md'),
14
+ code_root: z.string().describe('Path to the code root to analyze'),
15
+ };
16
+ const outputSchema = {
17
+ drifts: z.array(z.object({
18
+ kind: z.enum(['code_without_spec', 'spec_without_code']),
19
+ location: z.string(),
20
+ suggested_action: z.string(),
21
+ })),
22
+ };
23
+ export function registerFindSpecDrift(server) {
24
+ server.registerTool('find_spec_drift', {
25
+ title: 'Find Spec Drift',
26
+ description: 'Find drift between code and spec: undocumented behaviors ' +
27
+ '(code_without_spec) and unimplemented requirements ' +
28
+ '(spec_without_code), each with a suggested action.',
29
+ inputSchema,
30
+ outputSchema,
31
+ }, async ({ spec_dir, code_root }) => {
32
+ const { codePath, results } = await loadCircleIR(code_root);
33
+ const specGap = await analyzeSpecGap(codePath, results, { specDir: spec_dir });
34
+ const payload = toSpecDrift(specGap);
35
+ return {
36
+ content: [{ type: 'text', text: JSON.stringify(payload) }],
37
+ structuredContent: payload,
38
+ };
39
+ });
40
+ }
41
+ //# sourceMappingURL=find-spec-drift.js.map
@@ -0,0 +1 @@
1
+ {"version":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,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QACrC,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1D,iBAAiB,EAAE,OAA6C;SACjE,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `verify_spec_conformance` MCP tool.
3
+ *
4
+ * Runs spec-gap analysis over a code root against a Specifica spec directory
5
+ * and reports an alignment score plus per-requirement coverage status.
6
+ */
7
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8
+ export declare function registerVerifySpecConformance(server: McpServer): void;
9
+ //# sourceMappingURL=verify-spec-conformance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-spec-conformance.d.ts","sourceRoot":"","sources":["../../src/tools/verify-spec-conformance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA8BzE,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAsBrE"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `verify_spec_conformance` MCP tool.
3
+ *
4
+ * Runs spec-gap analysis over a code root against a Specifica spec directory
5
+ * and reports an alignment score plus per-requirement coverage status.
6
+ */
7
+ import { z } from 'zod';
8
+ import { analyzeSpecGap } from 'circle-ir-ai';
9
+ import { loadCircleIR } from '../analysis.js';
10
+ import { toVerifyConformance } from '../mappers.js';
11
+ const inputSchema = {
12
+ spec_dir: z.string().describe('Path to the .specifica/ directory containing spec.md'),
13
+ code_root: z.string().describe('Path to the code root to analyze'),
14
+ };
15
+ const evidenceSchema = z
16
+ .object({
17
+ function: z.string().optional(),
18
+ file: z.string().optional(),
19
+ span: z.tuple([z.number(), z.number()]).optional(),
20
+ })
21
+ .passthrough();
22
+ const outputSchema = {
23
+ alignment_score: z.number(),
24
+ requirements: z.array(z.object({
25
+ id: z.string(),
26
+ status: z.enum(['covered', 'partial', 'uncovered']),
27
+ evidence: evidenceSchema,
28
+ })),
29
+ summary: z.string(),
30
+ };
31
+ export function registerVerifySpecConformance(server) {
32
+ server.registerTool('verify_spec_conformance', {
33
+ title: 'Verify Spec Conformance',
34
+ description: 'Analyze how well code conforms to its Specifica spec. Returns an ' +
35
+ 'alignment score (0-100) and per-requirement coverage status ' +
36
+ '(covered/partial/uncovered). "partial" = matched with confidence < 0.7.',
37
+ inputSchema,
38
+ outputSchema,
39
+ }, async ({ spec_dir, code_root }) => {
40
+ const { codePath, results } = await loadCircleIR(code_root);
41
+ const specGap = await analyzeSpecGap(codePath, results, { specDir: spec_dir });
42
+ const payload = toVerifyConformance(specGap);
43
+ return {
44
+ content: [{ type: 'text', text: JSON.stringify(payload) }],
45
+ structuredContent: payload,
46
+ };
47
+ });
48
+ }
49
+ //# sourceMappingURL=verify-spec-conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify-spec-conformance.js","sourceRoot":"","sources":["../../src/tools/verify-spec-conformance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,GAAG;IAClB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sDAAsD,CAAC;IACrF,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC;CACnE,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAA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CAAC;YAC1D,iBAAiB,EAAE,OAA6C;SACjE,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
package/dist/walk.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * File walker for the MCP server.
3
+ *
4
+ * Recursively collects files under a root directory, applying default and
5
+ * caller-supplied exclude globs via `minimatch` (per the repo convention of
6
+ * never hand-rolling glob translation). Language detection is delegated to
7
+ * circle-ir's `detectLanguage`.
8
+ */
9
+ import { type SupportedLanguage } from 'circle-ir';
10
+ /** Directories/patterns excluded by default for every walk. */
11
+ export declare const DEFAULT_EXCLUDES: string[];
12
+ export interface WalkOptions {
13
+ /** Additional exclude globs (matched against the path relative to root). */
14
+ exclude?: string[];
15
+ /** Hard cap on number of files returned. Default 5000. */
16
+ maxFiles?: number;
17
+ /** Skip files larger than this many bytes. Default 1 MiB. */
18
+ maxFileBytes?: number;
19
+ }
20
+ export interface WalkedFile {
21
+ /** Absolute path. */
22
+ absolutePath: string;
23
+ /** Path relative to the walk root (used for matching/snippets). */
24
+ relativePath: string;
25
+ }
26
+ export interface SourceFile extends WalkedFile {
27
+ language: SupportedLanguage;
28
+ }
29
+ /** Walk all (non-excluded, size-bounded) files under `root`. */
30
+ export declare function walkFiles(root: string, options?: WalkOptions): WalkedFile[];
31
+ /** Walk and keep only files whose language circle-ir can detect. */
32
+ export declare function collectSourceFiles(root: string, options?: WalkOptions): SourceFile[];
33
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnE,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,UAS5B,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,qBAAqB;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,UAAU,EAAE,CA6C/E;AAED,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,UAAU,EAAE,CAUxF"}
package/dist/walk.js ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * File walker for the MCP server.
3
+ *
4
+ * Recursively collects files under a root directory, applying default and
5
+ * caller-supplied exclude globs via `minimatch` (per the repo convention of
6
+ * never hand-rolling glob translation). Language detection is delegated to
7
+ * circle-ir's `detectLanguage`.
8
+ */
9
+ import * as fs from 'fs';
10
+ import * as path from 'path';
11
+ import { minimatch } from 'minimatch';
12
+ import { detectLanguage } from 'circle-ir';
13
+ /** Directories/patterns excluded by default for every walk. */
14
+ export const DEFAULT_EXCLUDES = [
15
+ '**/node_modules/**',
16
+ '**/dist/**',
17
+ '**/build/**',
18
+ '**/.git/**',
19
+ '**/coverage/**',
20
+ '**/*.min.js',
21
+ '**/*.min.css',
22
+ '**/.specifica/**',
23
+ ];
24
+ /** Walk all (non-excluded, size-bounded) files under `root`. */
25
+ export function walkFiles(root, options = {}) {
26
+ const excludes = [...DEFAULT_EXCLUDES, ...(options.exclude ?? [])];
27
+ const maxFiles = options.maxFiles ?? 5000;
28
+ const maxFileBytes = options.maxFileBytes ?? 1024 * 1024;
29
+ const out = [];
30
+ const rootStat = fs.statSync(root);
31
+ if (rootStat.isFile()) {
32
+ return [{ absolutePath: path.resolve(root), relativePath: path.basename(root) }];
33
+ }
34
+ const stack = [root];
35
+ while (stack.length > 0 && out.length < maxFiles) {
36
+ const dir = stack.pop();
37
+ let entries;
38
+ try {
39
+ entries = fs.readdirSync(dir, { withFileTypes: true });
40
+ }
41
+ catch {
42
+ continue;
43
+ }
44
+ for (const entry of entries) {
45
+ const absolutePath = path.join(dir, entry.name);
46
+ const relativePath = path.relative(root, absolutePath);
47
+ const isExcluded = excludes.some((p) => minimatch(relativePath, p, { dot: true }));
48
+ if (isExcluded)
49
+ continue;
50
+ if (entry.isDirectory()) {
51
+ stack.push(absolutePath);
52
+ }
53
+ else if (entry.isFile()) {
54
+ let size = 0;
55
+ try {
56
+ size = fs.statSync(absolutePath).size;
57
+ }
58
+ catch {
59
+ continue;
60
+ }
61
+ if (size > maxFileBytes)
62
+ continue;
63
+ out.push({ absolutePath, relativePath });
64
+ if (out.length >= maxFiles)
65
+ break;
66
+ }
67
+ }
68
+ }
69
+ return out;
70
+ }
71
+ /** Walk and keep only files whose language circle-ir can detect. */
72
+ export function collectSourceFiles(root, options = {}) {
73
+ const files = walkFiles(root, options);
74
+ const sources = [];
75
+ for (const f of files) {
76
+ const language = detectLanguage(f.absolutePath);
77
+ if (language) {
78
+ sources.push({ ...f, language });
79
+ }
80
+ }
81
+ return sources;
82
+ }
83
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAA0B,MAAM,WAAW,CAAC;AAEnE,+DAA+D;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,oBAAoB;IACpB,YA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AE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@cognium-ai/mcp-server",
3
+ "version": "0.1.0",
4
+ "description": "MCP server exposing Cognium spec-conformance, spec-drift, and pattern-search tools over stdio",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "cognium-mcp": "dist/index.js"
9
+ },
10
+ "type": "module",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepare": "npm run build",
14
+ "prepublishOnly": "npm run build",
15
+ "dev": "tsx src/index.ts",
16
+ "start": "node dist/index.js",
17
+ "test": "vitest run",
18
+ "typecheck": "tsc --noEmit",
19
+ "smoke": "node test/smoke-stdio.mjs",
20
+ "clean": "rm -rf dist *.tsbuildinfo"
21
+ },
22
+ "keywords": [
23
+ "mcp",
24
+ "model-context-protocol",
25
+ "sast",
26
+ "specifica",
27
+ "spec-conformance",
28
+ "cognium"
29
+ ],
30
+ "author": {
31
+ "name": "Cognium Labs",
32
+ "url": "https://cognium.net"
33
+ },
34
+ "license": "PolyForm-Noncommercial-1.0.0",
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "dependencies": {
47
+ "@modelcontextprotocol/sdk": "^1.29.0",
48
+ "circle-ir": "^3.23.3",
49
+ "circle-ir-ai": "^2.7.19",
50
+ "minimatch": "^10.2.5",
51
+ "zod": "^3.25.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^25.5.0",
55
+ "tsx": "^4.21.0",
56
+ "typescript": "^6.0.2",
57
+ "vitest": "^4.1.3"
58
+ }
59
+ }