@cognium/mcp-server 0.8.1 → 0.9.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 +229 -0
- package/README.md +165 -5
- package/dist/bin.js +32 -3
- package/dist/bin.js.map +1 -1
- package/dist/deps/resolve.d.ts +70 -0
- package/dist/deps/resolve.d.ts.map +1 -0
- package/dist/deps/resolve.js +256 -0
- package/dist/deps/resolve.js.map +1 -0
- package/dist/deps/snapshot.d.ts +42 -0
- package/dist/deps/snapshot.d.ts.map +1 -0
- package/dist/deps/snapshot.js +104 -0
- package/dist/deps/snapshot.js.map +1 -0
- package/dist/deps/tycho-target.d.ts +31 -0
- package/dist/deps/tycho-target.d.ts.map +1 -0
- package/dist/deps/tycho-target.js +62 -0
- package/dist/deps/tycho-target.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/modules.d.ts +14 -2
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +11 -3
- package/dist/modules.js.map +1 -1
- package/dist/roots.d.ts +146 -0
- package/dist/roots.d.ts.map +1 -0
- package/dist/roots.js +354 -0
- package/dist/roots.js.map +1 -0
- package/dist/server.d.ts +38 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +131 -7
- package/dist/server.js.map +1 -1
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +3 -4
- package/dist/startup.js.map +1 -1
- package/dist/status.d.ts +43 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +54 -0
- package/dist/status.js.map +1 -0
- package/dist/tools/analyze-dependencies.d.ts +377 -0
- package/dist/tools/analyze-dependencies.d.ts.map +1 -0
- package/dist/tools/analyze-dependencies.js +387 -0
- package/dist/tools/analyze-dependencies.js.map +1 -0
- package/dist/tools/attack-surface-summary.d.ts +11 -0
- package/dist/tools/attack-surface-summary.d.ts.map +1 -1
- package/dist/tools/attack-surface-summary.js +2 -0
- package/dist/tools/attack-surface-summary.js.map +1 -1
- package/dist/tools/check-sanitizer.d.ts +10 -0
- package/dist/tools/check-sanitizer.d.ts.map +1 -1
- package/dist/tools/check-sanitizer.js +2 -0
- package/dist/tools/check-sanitizer.js.map +1 -1
- package/dist/tools/describe-sink.d.ts +14 -0
- package/dist/tools/describe-sink.d.ts.map +1 -1
- package/dist/tools/describe-sink.js +2 -0
- package/dist/tools/describe-sink.js.map +1 -1
- package/dist/tools/describe-source.d.ts +8 -0
- package/dist/tools/describe-source.d.ts.map +1 -1
- package/dist/tools/describe-source.js +2 -0
- package/dist/tools/describe-source.js.map +1 -1
- package/dist/tools/explain-finding.d.ts +5 -0
- package/dist/tools/explain-finding.d.ts.map +1 -1
- package/dist/tools/explain-finding.js +2 -0
- package/dist/tools/explain-finding.js.map +1 -1
- package/dist/tools/find-similar.d.ts +10 -0
- package/dist/tools/find-similar.d.ts.map +1 -1
- package/dist/tools/find-similar.js +2 -0
- package/dist/tools/find-similar.js.map +1 -1
- package/dist/tools/graph-facts.d.ts +829 -0
- package/dist/tools/graph-facts.d.ts.map +1 -0
- package/dist/tools/graph-facts.js +735 -0
- package/dist/tools/graph-facts.js.map +1 -0
- package/dist/tools/list-entry-points.d.ts +11 -0
- package/dist/tools/list-entry-points.d.ts.map +1 -1
- package/dist/tools/list-entry-points.js +2 -0
- package/dist/tools/list-entry-points.js.map +1 -1
- package/dist/tools/list-reachable-sinks.d.ts +11 -0
- package/dist/tools/list-reachable-sinks.d.ts.map +1 -1
- package/dist/tools/list-reachable-sinks.js +2 -0
- package/dist/tools/list-reachable-sinks.js.map +1 -1
- package/dist/tools/navigation.d.ts +22 -0
- package/dist/tools/navigation.d.ts.map +1 -1
- package/dist/tools/navigation.js +3 -0
- package/dist/tools/navigation.js.map +1 -1
- package/dist/tools/output-shapes.d.ts +159 -0
- package/dist/tools/output-shapes.d.ts.map +1 -0
- package/dist/tools/output-shapes.js +153 -0
- package/dist/tools/output-shapes.js.map +1 -0
- package/dist/tools/refresh.d.ts +7 -0
- package/dist/tools/refresh.d.ts.map +1 -1
- package/dist/tools/refresh.js +2 -0
- package/dist/tools/refresh.js.map +1 -1
- package/dist/tools/scan.d.ts +18 -0
- package/dist/tools/scan.d.ts.map +1 -1
- package/dist/tools/scan.js +2 -0
- package/dist/tools/scan.js.map +1 -1
- package/dist/tools/taint-paths.d.ts +10 -0
- package/dist/tools/taint-paths.d.ts.map +1 -1
- package/dist/tools/taint-paths.js +2 -0
- package/dist/tools/taint-paths.js.map +1 -1
- package/dist/tools/types.d.ts +17 -5
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +9 -0
- package/dist/tools/types.js.map +1 -1
- package/package.json +6 -6
package/dist/modules.js
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
*
|
|
10
10
|
* The loader's contract is that **the server comes up either way**. A module
|
|
11
11
|
* that is absent, broken, built against the wrong engine, or wrong in shape
|
|
12
|
-
* is refused with one line on stderr
|
|
13
|
-
*
|
|
12
|
+
* is refused with one line on stderr — and reported to the client, see
|
|
13
|
+
* `status.ts` — and the deterministic floor serves as normal. There is no
|
|
14
|
+
* state in which a bad module takes the server down.
|
|
14
15
|
*/
|
|
15
16
|
import { createRequire } from 'node:module';
|
|
16
17
|
/**
|
|
@@ -126,7 +127,14 @@ export async function loadModules(opts = {}) {
|
|
|
126
127
|
}
|
|
127
128
|
const range = checkCircleIrRange(mod.circleIrRange, installed);
|
|
128
129
|
if (!range.ok) {
|
|
129
|
-
refusals.push({
|
|
130
|
+
refusals.push({
|
|
131
|
+
specifier,
|
|
132
|
+
reason: `${mod.id}@${mod.version} ${range.reason}`,
|
|
133
|
+
id: mod.id,
|
|
134
|
+
version: mod.version,
|
|
135
|
+
builtAgainst: mod.circleIrRange,
|
|
136
|
+
installed,
|
|
137
|
+
});
|
|
130
138
|
continue;
|
|
131
139
|
}
|
|
132
140
|
modules.push(mod);
|
package/dist/modules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsC5C;;;;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,CAAC,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC;QACH,OAAQ,QAAQ,CAAC,wBAAwB,CAAyB,CAAC,OAAO,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,wEAAwE;QACxE,oEAAoE;QACpE,sBAAsB;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAA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sB,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;gBACZ,SAAS;gBACT,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;gBAClD,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,YAAY,EAAE,GAAG,CAAC,aAAa;gBAC/B,SAAS;aACV,CAAC,CAAC;YACH,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/roots.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowed roots: which directories a tool may read (issue #37, S5).
|
|
3
|
+
*
|
|
4
|
+
* Every path-taking tool reads the tree it is given and returns text derived
|
|
5
|
+
* from it (finding messages and snippets quote string literals). Mounted over
|
|
6
|
+
* HTTP, an unconfined server lets a token holder read any directory on the
|
|
7
|
+
* *server's* host; over stdio it lets a prompt-injected client wander out of
|
|
8
|
+
* the project. So every server checks every path argument of every tool —
|
|
9
|
+
* the floor's and a module's — before the tool runs:
|
|
10
|
+
*
|
|
11
|
+
* - a path with a `..` segment is refused, however it is spelled;
|
|
12
|
+
* - on a POSIX host, a Windows-style path (a backslash, a drive letter `C:`)
|
|
13
|
+
* is refused; on Windows, a UNC path (`\\server\share`, `\\?\…`) is;
|
|
14
|
+
* - anything else is resolved with `realpath` (the longest existing prefix,
|
|
15
|
+
* for a path that does not exist yet), so a symlink that leads out of a
|
|
16
|
+
* root resolves to where it really points, and is refused unless that lies
|
|
17
|
+
* inside a root;
|
|
18
|
+
* - a top-level tree argument inside a root (`path`, `project_root`, …) is
|
|
19
|
+
* passed to the tool as its real path, so the tool reads what was checked;
|
|
20
|
+
* a nested relative path (`resolved[].path`, `resolved[].applies_to`,
|
|
21
|
+
* `site.file`) is checked against every tree argument of the call, since
|
|
22
|
+
* the tool may read it relative to any of them;
|
|
23
|
+
* - anything else is refused with one line, and the tool does not run.
|
|
24
|
+
*
|
|
25
|
+
* A tool that then finds files of its own inside a tree it was given (a
|
|
26
|
+
* build file, a lockfile, a snapshot record) reads them through
|
|
27
|
+
* `fileInside`, so a symlink planted in the tree cannot lead the read out of
|
|
28
|
+
* it either.
|
|
29
|
+
*
|
|
30
|
+
* **Where the roots come from.**
|
|
31
|
+
*
|
|
32
|
+
* - *Configured roots*: `allowedRoots` when the host passes them, else
|
|
33
|
+
* `COGNIUM_MCP_ALLOWED_ROOTS`. `'*'` as either is the explicit opt-out.
|
|
34
|
+
* - *The client's MCP roots* (`roots/list`), when the client declares the
|
|
35
|
+
* `roots` capability. They narrow the configured roots: a tool may read the
|
|
36
|
+
* part of the client's roots that lies inside a configured root (all of
|
|
37
|
+
* them, under `'*'`). With no configured root they stand in for one only
|
|
38
|
+
* where the host lets them (`'establish'`, the stdio binary's policy: its
|
|
39
|
+
* client is the user's own). Over HTTP they never do — a remote client's
|
|
40
|
+
* roots name directories on the client's machine, and letting them open
|
|
41
|
+
* the server's would let any token holder widen the confinement.
|
|
42
|
+
* - **No implicit root.** With no configured root and no client root, every
|
|
43
|
+
* path is refused with one line saying how to allow one. The working
|
|
44
|
+
* directory is not a root: clients start servers in `/` (Claude Desktop on
|
|
45
|
+
* macOS) or in `$HOME`, which made it the whole disk.
|
|
46
|
+
*/
|
|
47
|
+
/** Environment variable naming the allowed roots, separated by the platform's path delimiter (`:` on POSIX). */
|
|
48
|
+
export declare const ENV_ALLOWED_ROOTS = "COGNIUM_MCP_ALLOWED_ROOTS";
|
|
49
|
+
/** The value, of the option or the variable, that turns the check off. */
|
|
50
|
+
export declare const UNCONFINED = "*";
|
|
51
|
+
/** The longest path argument accepted; longer ones are refused before any file-system call. */
|
|
52
|
+
export declare const MAX_PATH_LENGTH = 4096;
|
|
53
|
+
/** Allowed roots as a host passes them: directories, or `'*'` for no check. */
|
|
54
|
+
export type AllowedRoots = readonly string[] | typeof UNCONFINED;
|
|
55
|
+
/**
|
|
56
|
+
* What the client's MCP roots may do when no root is configured.
|
|
57
|
+
*
|
|
58
|
+
* - `'narrow'` (the default, and the HTTP handler's): they only narrow
|
|
59
|
+
* configured roots; with none configured every path is refused.
|
|
60
|
+
* - `'establish'` (the stdio binary): with none configured, the client's
|
|
61
|
+
* roots are the allowed roots.
|
|
62
|
+
*
|
|
63
|
+
* Either way, configured roots are never widened by a client.
|
|
64
|
+
*/
|
|
65
|
+
export type ClientRootsPolicy = 'narrow' | 'establish';
|
|
66
|
+
/**
|
|
67
|
+
* The roots from the environment: `'*'`, a list, or `undefined` when the
|
|
68
|
+
* variable is unset or blank.
|
|
69
|
+
*/
|
|
70
|
+
export declare function rootsFromEnv(env?: NodeJS.ProcessEnv): AllowedRoots | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* The configured roots: the option, else the environment. `undefined` when
|
|
73
|
+
* neither names any — there is no implicit root, the working directory
|
|
74
|
+
* included.
|
|
75
|
+
*/
|
|
76
|
+
export declare function resolveAllowedRoots(option: AllowedRoots | undefined, env?: NodeJS.ProcessEnv): AllowedRoots | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The directories a client's `roots/list` answer names: its `file://` URIs
|
|
79
|
+
* as paths. Anything else — another scheme, a URI that is not a local file,
|
|
80
|
+
* a malformed entry — is ignored; the answer is untrusted input.
|
|
81
|
+
*/
|
|
82
|
+
export declare function rootPathsFromList(answer: unknown): string[];
|
|
83
|
+
/**
|
|
84
|
+
* The real path `p` stands for when it lies inside `base` (itself a real
|
|
85
|
+
* path) — following every symlink, for a path that need not exist yet — else
|
|
86
|
+
* `undefined`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function pathInside(base: string, p: string): string | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The real path of `p` when it is an existing regular file (after following
|
|
91
|
+
* symlinks) inside `base` (itself a real path), else `undefined`. For a file
|
|
92
|
+
* a tool finds on its own inside a tree it was given: a symlink that leads
|
|
93
|
+
* out of the tree reads as no file at all.
|
|
94
|
+
*/
|
|
95
|
+
export declare function fileInside(base: string, p: string): string | undefined;
|
|
96
|
+
/** `realpath` of `p`, or `p` resolved when it does not exist. */
|
|
97
|
+
export declare function realOrResolved(p: string): string;
|
|
98
|
+
/** How a guard words its refusals: why it has no root, and how to widen its roots. */
|
|
99
|
+
export interface GuardWording {
|
|
100
|
+
/** The refusal when there is no root at all. */
|
|
101
|
+
none?: string;
|
|
102
|
+
/** Appended to an "outside the allowed roots" refusal. */
|
|
103
|
+
hint?: string;
|
|
104
|
+
}
|
|
105
|
+
export declare class RootGuard {
|
|
106
|
+
readonly unconfined: boolean;
|
|
107
|
+
/** The roots, each as its real path. Empty means every path is refused. */
|
|
108
|
+
readonly roots: readonly string[];
|
|
109
|
+
private readonly platform;
|
|
110
|
+
private readonly none;
|
|
111
|
+
private readonly hint;
|
|
112
|
+
constructor(roots: AllowedRoots, platform?: NodeJS.Platform, wording?: GuardWording);
|
|
113
|
+
/**
|
|
114
|
+
* The real path to use for `value`, or a one-line refusal. `base` resolves
|
|
115
|
+
* a relative path (the tree it is relative to); without one, a relative
|
|
116
|
+
* path resolves against the working directory, as the tools resolve it.
|
|
117
|
+
*/
|
|
118
|
+
check(value: string, name: string, base?: string): {
|
|
119
|
+
path: string;
|
|
120
|
+
} | {
|
|
121
|
+
error: string;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Check every path-carrying argument of one tool call. Returns the
|
|
125
|
+
* arguments with each top-level tree path replaced by its real path, or
|
|
126
|
+
* the first refusal. Unconfined, only the sanity checks run.
|
|
127
|
+
*/
|
|
128
|
+
apply(args: unknown): {
|
|
129
|
+
args: unknown;
|
|
130
|
+
} | {
|
|
131
|
+
error: string;
|
|
132
|
+
};
|
|
133
|
+
private treeBase;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The guard for one call: the configured roots, narrowed by the client's MCP
|
|
137
|
+
* roots when it sent any — or, under `'establish'` with none configured,
|
|
138
|
+
* the client's roots themselves. `client` is `undefined` when the client
|
|
139
|
+
* sent no usable root.
|
|
140
|
+
*/
|
|
141
|
+
export declare function effectiveGuard(configured: AllowedRoots | undefined, client: readonly string[] | undefined, policy?: ClientRootsPolicy, platform?: NodeJS.Platform): RootGuard;
|
|
142
|
+
/** Run one tool call under `guard`, so that what it reads on its own is held to the same roots. */
|
|
143
|
+
export declare function withGuard<T>(guard: RootGuard, fn: () => T): T;
|
|
144
|
+
/** The guard of the tool call in progress, if any. */
|
|
145
|
+
export declare function activeGuard(): RootGuard | undefined;
|
|
146
|
+
//# sourceMappingURL=roots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roots.d.ts","sourceRoot":"","sources":["../src/roots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAOH,gHAAgH;AAChH,eAAO,MAAM,iBAAiB,8BAA8B,CAAC;AAE7D,0EAA0E;AAC1E,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,+FAA+F;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QAAQ,CAAC,IAAI,CAAS;IAE9B,YAAY,KAAK,EAAE,YAAY,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAAE,OAAO,GAAE,YAAiB,EAMxG;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAetF;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAmD1D;IAED,OAAO,CAAC,QAAQ;CAIjB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,YAAY,GAAG,SAAS,EACpC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACrC,MAAM,GAAE,iBAA4B,EACpC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC3C,SAAS,CAiCX;AAID,mGAAmG;AACnG,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE7D;AAED,sDAAsD;AACtD,wBAAgB,WAAW,IAAI,SAAS,GAAG,SAAS,CAEnD"}
|
package/dist/roots.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowed roots: which directories a tool may read (issue #37, S5).
|
|
3
|
+
*
|
|
4
|
+
* Every path-taking tool reads the tree it is given and returns text derived
|
|
5
|
+
* from it (finding messages and snippets quote string literals). Mounted over
|
|
6
|
+
* HTTP, an unconfined server lets a token holder read any directory on the
|
|
7
|
+
* *server's* host; over stdio it lets a prompt-injected client wander out of
|
|
8
|
+
* the project. So every server checks every path argument of every tool —
|
|
9
|
+
* the floor's and a module's — before the tool runs:
|
|
10
|
+
*
|
|
11
|
+
* - a path with a `..` segment is refused, however it is spelled;
|
|
12
|
+
* - on a POSIX host, a Windows-style path (a backslash, a drive letter `C:`)
|
|
13
|
+
* is refused; on Windows, a UNC path (`\\server\share`, `\\?\…`) is;
|
|
14
|
+
* - anything else is resolved with `realpath` (the longest existing prefix,
|
|
15
|
+
* for a path that does not exist yet), so a symlink that leads out of a
|
|
16
|
+
* root resolves to where it really points, and is refused unless that lies
|
|
17
|
+
* inside a root;
|
|
18
|
+
* - a top-level tree argument inside a root (`path`, `project_root`, …) is
|
|
19
|
+
* passed to the tool as its real path, so the tool reads what was checked;
|
|
20
|
+
* a nested relative path (`resolved[].path`, `resolved[].applies_to`,
|
|
21
|
+
* `site.file`) is checked against every tree argument of the call, since
|
|
22
|
+
* the tool may read it relative to any of them;
|
|
23
|
+
* - anything else is refused with one line, and the tool does not run.
|
|
24
|
+
*
|
|
25
|
+
* A tool that then finds files of its own inside a tree it was given (a
|
|
26
|
+
* build file, a lockfile, a snapshot record) reads them through
|
|
27
|
+
* `fileInside`, so a symlink planted in the tree cannot lead the read out of
|
|
28
|
+
* it either.
|
|
29
|
+
*
|
|
30
|
+
* **Where the roots come from.**
|
|
31
|
+
*
|
|
32
|
+
* - *Configured roots*: `allowedRoots` when the host passes them, else
|
|
33
|
+
* `COGNIUM_MCP_ALLOWED_ROOTS`. `'*'` as either is the explicit opt-out.
|
|
34
|
+
* - *The client's MCP roots* (`roots/list`), when the client declares the
|
|
35
|
+
* `roots` capability. They narrow the configured roots: a tool may read the
|
|
36
|
+
* part of the client's roots that lies inside a configured root (all of
|
|
37
|
+
* them, under `'*'`). With no configured root they stand in for one only
|
|
38
|
+
* where the host lets them (`'establish'`, the stdio binary's policy: its
|
|
39
|
+
* client is the user's own). Over HTTP they never do — a remote client's
|
|
40
|
+
* roots name directories on the client's machine, and letting them open
|
|
41
|
+
* the server's would let any token holder widen the confinement.
|
|
42
|
+
* - **No implicit root.** With no configured root and no client root, every
|
|
43
|
+
* path is refused with one line saying how to allow one. The working
|
|
44
|
+
* directory is not a root: clients start servers in `/` (Claude Desktop on
|
|
45
|
+
* macOS) or in `$HOME`, which made it the whole disk.
|
|
46
|
+
*/
|
|
47
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
48
|
+
import { realpathSync, statSync } from 'node:fs';
|
|
49
|
+
import { delimiter, dirname, isAbsolute, resolve, sep } from 'node:path';
|
|
50
|
+
import { fileURLToPath } from 'node:url';
|
|
51
|
+
/** Environment variable naming the allowed roots, separated by the platform's path delimiter (`:` on POSIX). */
|
|
52
|
+
export const ENV_ALLOWED_ROOTS = 'COGNIUM_MCP_ALLOWED_ROOTS';
|
|
53
|
+
/** The value, of the option or the variable, that turns the check off. */
|
|
54
|
+
export const UNCONFINED = '*';
|
|
55
|
+
/** The longest path argument accepted; longer ones are refused before any file-system call. */
|
|
56
|
+
export const MAX_PATH_LENGTH = 4096;
|
|
57
|
+
/**
|
|
58
|
+
* Argument names that carry a path, at any depth: `path`, `file`, `root`,
|
|
59
|
+
* `dir`, `applies_to`, and any `*_root`, `*_path`, `*_dir`, `*_file`, `*_db`
|
|
60
|
+
* (or camelCase `…Root`, `…Path`, `…Dir`, `…File`). A module's tools follow
|
|
61
|
+
* the same naming, so the check covers them too.
|
|
62
|
+
*/
|
|
63
|
+
const PATH_KEY = /^(path|root|file|dir|applies_to)$|_(root|path|dir|file|db)$|(Root|Path|Dir|File)$/;
|
|
64
|
+
/** Top-level arguments naming a tree or directory to read, passed on as their real path. */
|
|
65
|
+
const REWRITE_KEY = /^(path|root|dir)$|_(root|dir|db)$|(Root|Dir)$/;
|
|
66
|
+
/** Top-level arguments naming a tree that a nested relative path may be read against. */
|
|
67
|
+
const TREE_KEY = /^root$|_root$/;
|
|
68
|
+
/** Object-valued arguments whose every string value is a path (`advisory_dbs: { maven, npm }`). */
|
|
69
|
+
const PATH_MAP_KEY = /_dbs$|_roots$|_paths$|_dirs$/;
|
|
70
|
+
const HINT_CONFIGURED = `Set ${ENV_ALLOWED_ROOTS} (or allowedRoots on the host) to widen them.`;
|
|
71
|
+
const HINT_CLIENT = "They are the client's MCP roots (within any configured roots): add the directory as a root in the client to widen them.";
|
|
72
|
+
/**
|
|
73
|
+
* The roots from the environment: `'*'`, a list, or `undefined` when the
|
|
74
|
+
* variable is unset or blank.
|
|
75
|
+
*/
|
|
76
|
+
export function rootsFromEnv(env = process.env) {
|
|
77
|
+
const raw = env[ENV_ALLOWED_ROOTS];
|
|
78
|
+
if (raw === undefined || raw.trim() === '')
|
|
79
|
+
return undefined;
|
|
80
|
+
if (raw.trim() === UNCONFINED)
|
|
81
|
+
return UNCONFINED;
|
|
82
|
+
return raw
|
|
83
|
+
.split(delimiter)
|
|
84
|
+
.map((r) => r.trim())
|
|
85
|
+
.filter((r) => r.length > 0);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The configured roots: the option, else the environment. `undefined` when
|
|
89
|
+
* neither names any — there is no implicit root, the working directory
|
|
90
|
+
* included.
|
|
91
|
+
*/
|
|
92
|
+
export function resolveAllowedRoots(option, env = process.env) {
|
|
93
|
+
return option ?? rootsFromEnv(env);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The directories a client's `roots/list` answer names: its `file://` URIs
|
|
97
|
+
* as paths. Anything else — another scheme, a URI that is not a local file,
|
|
98
|
+
* a malformed entry — is ignored; the answer is untrusted input.
|
|
99
|
+
*/
|
|
100
|
+
export function rootPathsFromList(answer) {
|
|
101
|
+
const roots = answer?.roots;
|
|
102
|
+
if (!Array.isArray(roots))
|
|
103
|
+
return [];
|
|
104
|
+
const out = [];
|
|
105
|
+
for (const root of roots) {
|
|
106
|
+
const uri = root?.uri;
|
|
107
|
+
if (typeof uri !== 'string' || !uri.startsWith('file:'))
|
|
108
|
+
continue;
|
|
109
|
+
let path;
|
|
110
|
+
try {
|
|
111
|
+
path = fileURLToPath(uri);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (!isAbsolute(path) || path.includes('\u0000') || path.length > MAX_PATH_LENGTH)
|
|
117
|
+
continue;
|
|
118
|
+
if (!out.includes(path))
|
|
119
|
+
out.push(path);
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/** `realpath` of the longest existing prefix of `p`, with the rest appended. */
|
|
124
|
+
function realOrNearest(p) {
|
|
125
|
+
let cur = p;
|
|
126
|
+
const rest = [];
|
|
127
|
+
for (;;) {
|
|
128
|
+
try {
|
|
129
|
+
const real = realpathSync.native(cur);
|
|
130
|
+
return rest.length ? resolve(real, ...rest.reverse()) : real;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
const up = dirname(cur);
|
|
134
|
+
if (up === cur)
|
|
135
|
+
return p;
|
|
136
|
+
rest.push(cur.slice(up.length).replace(/^[\\/]+/, ''));
|
|
137
|
+
cur = up;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function within(child, root) {
|
|
142
|
+
if (child === root)
|
|
143
|
+
return true;
|
|
144
|
+
const base = root.endsWith(sep) ? root : root + sep;
|
|
145
|
+
return child.startsWith(base);
|
|
146
|
+
}
|
|
147
|
+
const realRoots = (roots) => [...new Set(roots.map((r) => realOrNearest(resolve(r))))];
|
|
148
|
+
/**
|
|
149
|
+
* The real path `p` stands for when it lies inside `base` (itself a real
|
|
150
|
+
* path) — following every symlink, for a path that need not exist yet — else
|
|
151
|
+
* `undefined`.
|
|
152
|
+
*/
|
|
153
|
+
export function pathInside(base, p) {
|
|
154
|
+
const real = realOrNearest(resolve(p));
|
|
155
|
+
return within(real, base) ? real : undefined;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The real path of `p` when it is an existing regular file (after following
|
|
159
|
+
* symlinks) inside `base` (itself a real path), else `undefined`. For a file
|
|
160
|
+
* a tool finds on its own inside a tree it was given: a symlink that leads
|
|
161
|
+
* out of the tree reads as no file at all.
|
|
162
|
+
*/
|
|
163
|
+
export function fileInside(base, p) {
|
|
164
|
+
let real;
|
|
165
|
+
try {
|
|
166
|
+
real = realpathSync.native(p);
|
|
167
|
+
if (!statSync(real).isFile())
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
return within(real, base) ? real : undefined;
|
|
174
|
+
}
|
|
175
|
+
/** `realpath` of `p`, or `p` resolved when it does not exist. */
|
|
176
|
+
export function realOrResolved(p) {
|
|
177
|
+
return realOrNearest(resolve(p));
|
|
178
|
+
}
|
|
179
|
+
/** Why a path is refused on its spelling alone, before the file system is asked. */
|
|
180
|
+
function spellingRefusal(value, name, platform) {
|
|
181
|
+
if (value.includes('\u0000'))
|
|
182
|
+
return `\`${name}\` contains a NUL byte`;
|
|
183
|
+
if (value.length > MAX_PATH_LENGTH)
|
|
184
|
+
return `\`${name}\` is longer than ${MAX_PATH_LENGTH} characters`;
|
|
185
|
+
if (value.split(/[\\/]/).includes('..'))
|
|
186
|
+
return `\`${name}\` contains a \`..\` segment; pass the path without one`;
|
|
187
|
+
if (platform === 'win32') {
|
|
188
|
+
if (/^[\\/]{2}/.test(value))
|
|
189
|
+
return `\`${name}\` is a UNC path, which this server does not read`;
|
|
190
|
+
}
|
|
191
|
+
else if (value.includes('\\') || /^[A-Za-z]:/.test(value)) {
|
|
192
|
+
return `\`${name}\` is a Windows-style path; this server runs on ${platform} and takes POSIX paths`;
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
export class RootGuard {
|
|
197
|
+
unconfined;
|
|
198
|
+
/** The roots, each as its real path. Empty means every path is refused. */
|
|
199
|
+
roots;
|
|
200
|
+
platform;
|
|
201
|
+
none;
|
|
202
|
+
hint;
|
|
203
|
+
constructor(roots, platform = process.platform, wording = {}) {
|
|
204
|
+
this.unconfined = roots === UNCONFINED;
|
|
205
|
+
this.roots = roots === UNCONFINED ? [] : realRoots(roots);
|
|
206
|
+
this.platform = platform;
|
|
207
|
+
this.none = wording.none ?? `this server has no allowed roots (${ENV_ALLOWED_ROOTS}, or allowedRoots on the host)`;
|
|
208
|
+
this.hint = wording.hint ?? HINT_CONFIGURED;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The real path to use for `value`, or a one-line refusal. `base` resolves
|
|
212
|
+
* a relative path (the tree it is relative to); without one, a relative
|
|
213
|
+
* path resolves against the working directory, as the tools resolve it.
|
|
214
|
+
*/
|
|
215
|
+
check(value, name, base) {
|
|
216
|
+
if (this.unconfined) {
|
|
217
|
+
// The opt-out turns off confinement, not sanity: a NUL byte or an
|
|
218
|
+
// oversized path is still refused.
|
|
219
|
+
if (value.includes('\u0000'))
|
|
220
|
+
return { error: `\`${name}\` contains a NUL byte` };
|
|
221
|
+
if (value.length > MAX_PATH_LENGTH)
|
|
222
|
+
return { error: `\`${name}\` is longer than ${MAX_PATH_LENGTH} characters` };
|
|
223
|
+
return { path: value };
|
|
224
|
+
}
|
|
225
|
+
const spelling = spellingRefusal(value, name, this.platform);
|
|
226
|
+
if (spelling)
|
|
227
|
+
return { error: spelling };
|
|
228
|
+
if (this.roots.length === 0)
|
|
229
|
+
return { error: `\`${name}\` is not allowed: ${this.none}` };
|
|
230
|
+
const abs = isAbsolute(value) ? value : resolve(base ?? process.cwd(), value);
|
|
231
|
+
const real = realOrNearest(resolve(abs));
|
|
232
|
+
if (this.roots.some((r) => within(real, r)))
|
|
233
|
+
return { path: real };
|
|
234
|
+
return { error: `\`${name}\` is outside the allowed roots: ${value}. ${this.hint}` };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Check every path-carrying argument of one tool call. Returns the
|
|
238
|
+
* arguments with each top-level tree path replaced by its real path, or
|
|
239
|
+
* the first refusal. Unconfined, only the sanity checks run.
|
|
240
|
+
*/
|
|
241
|
+
apply(args) {
|
|
242
|
+
if (args === null || typeof args !== 'object')
|
|
243
|
+
return { args };
|
|
244
|
+
const top = args;
|
|
245
|
+
// Every tree a nested relative path may be read against: `resolved[]`
|
|
246
|
+
// of `analyze_dependencies` is relative to `baseline_root` on one side
|
|
247
|
+
// and `project_root` on the other, so it is checked against both.
|
|
248
|
+
const trees = Object.entries(top)
|
|
249
|
+
.filter(([k, v]) => TREE_KEY.test(k) && typeof v === 'string')
|
|
250
|
+
.map(([k, v]) => this.treeBase(v, k))
|
|
251
|
+
.filter((b) => b !== undefined);
|
|
252
|
+
let refusal;
|
|
253
|
+
const visit = (value, key, where) => {
|
|
254
|
+
if (refusal)
|
|
255
|
+
return value;
|
|
256
|
+
if (typeof value === 'string' && PATH_KEY.test(key)) {
|
|
257
|
+
// A tree or directory argument at the top level (`path`,
|
|
258
|
+
// `project_root`, `maven_repo_dir`, `advisory_db`) goes to the tool as
|
|
259
|
+
// its real path. Any other path (`site.file`, a `sink_file` filter, a
|
|
260
|
+
// `jar_path`, `resolved[].applies_to`) is checked — relative to every
|
|
261
|
+
// tree of the call when it is relative — and passed as written: the
|
|
262
|
+
// tool reads it relative to its tree, and rewriting it would change
|
|
263
|
+
// what the tool answers.
|
|
264
|
+
const nested = where.includes('.') || where.includes('[');
|
|
265
|
+
const rewrite = !nested && REWRITE_KEY.test(key);
|
|
266
|
+
const bases = rewrite || isAbsolute(value) || trees.length === 0 ? [undefined] : trees;
|
|
267
|
+
let r = { path: value };
|
|
268
|
+
for (const base of bases) {
|
|
269
|
+
r = this.check(value, where, base);
|
|
270
|
+
if ('error' in r)
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
if ('error' in r) {
|
|
274
|
+
refusal = r.error;
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
return rewrite && !this.unconfined ? r.path : value;
|
|
278
|
+
}
|
|
279
|
+
if (Array.isArray(value))
|
|
280
|
+
return value.map((v, i) => visit(v, key, `${where}[${i}]`));
|
|
281
|
+
if (value !== null && typeof value === 'object') {
|
|
282
|
+
const mapOfPaths = PATH_MAP_KEY.test(key);
|
|
283
|
+
const out = {};
|
|
284
|
+
for (const [k, v] of Object.entries(value)) {
|
|
285
|
+
out[k] = mapOfPaths && typeof v === 'string' ? visit(v, 'path', `${where}.${k}`) : visit(v, k, `${where}.${k}`);
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
return value;
|
|
290
|
+
};
|
|
291
|
+
const out = {};
|
|
292
|
+
for (const [k, v] of Object.entries(top))
|
|
293
|
+
out[k] = visit(v, k, k);
|
|
294
|
+
return refusal ? { error: refusal } : { args: out };
|
|
295
|
+
}
|
|
296
|
+
treeBase(treeRoot, name) {
|
|
297
|
+
const r = this.check(treeRoot, name);
|
|
298
|
+
return 'path' in r ? r.path : undefined;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* The guard for one call: the configured roots, narrowed by the client's MCP
|
|
303
|
+
* roots when it sent any — or, under `'establish'` with none configured,
|
|
304
|
+
* the client's roots themselves. `client` is `undefined` when the client
|
|
305
|
+
* sent no usable root.
|
|
306
|
+
*/
|
|
307
|
+
export function effectiveGuard(configured, client, policy = 'narrow', platform = process.platform) {
|
|
308
|
+
const fromClient = client !== undefined && client.length > 0;
|
|
309
|
+
if (!fromClient) {
|
|
310
|
+
if (configured !== undefined)
|
|
311
|
+
return new RootGuard(configured, platform);
|
|
312
|
+
return new RootGuard([], platform, {
|
|
313
|
+
none: `no allowed roots — the client sent no MCP roots and none are configured. ` +
|
|
314
|
+
`Set ${ENV_ALLOWED_ROOTS} to the directories tools may read (allowedRoots on the host), ` +
|
|
315
|
+
'or use a client that sends MCP roots',
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (configured === undefined) {
|
|
319
|
+
if (policy === 'establish')
|
|
320
|
+
return new RootGuard(client, platform, { hint: HINT_CLIENT });
|
|
321
|
+
return new RootGuard([], platform, {
|
|
322
|
+
none: "no allowed roots — none are configured, and on this server a client's MCP roots only narrow configured roots. " +
|
|
323
|
+
`Set allowedRoots on the host (or ${ENV_ALLOWED_ROOTS})`,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (configured === UNCONFINED)
|
|
327
|
+
return new RootGuard(client, platform, { hint: HINT_CLIENT });
|
|
328
|
+
// The intersection: each client root inside a configured root, and each
|
|
329
|
+
// configured root inside a client root.
|
|
330
|
+
const mine = realRoots(configured);
|
|
331
|
+
const theirs = realRoots(client);
|
|
332
|
+
const both = new Set();
|
|
333
|
+
for (const c of theirs)
|
|
334
|
+
for (const k of mine) {
|
|
335
|
+
if (within(c, k))
|
|
336
|
+
both.add(c);
|
|
337
|
+
else if (within(k, c))
|
|
338
|
+
both.add(k);
|
|
339
|
+
}
|
|
340
|
+
return new RootGuard([...both], platform, {
|
|
341
|
+
hint: HINT_CLIENT,
|
|
342
|
+
none: `no allowed roots — none of the client's MCP roots lies inside the configured roots (${ENV_ALLOWED_ROOTS}, or allowedRoots on the host)`,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
const CALL = new AsyncLocalStorage();
|
|
346
|
+
/** Run one tool call under `guard`, so that what it reads on its own is held to the same roots. */
|
|
347
|
+
export function withGuard(guard, fn) {
|
|
348
|
+
return CALL.run(guard, fn);
|
|
349
|
+
}
|
|
350
|
+
/** The guard of the tool call in progress, if any. */
|
|
351
|
+
export function activeGuard() {
|
|
352
|
+
return CALL.getStore();
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=roots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roots.js","sourceRoot":"","sources":["../src/roots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UA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;IAC/B,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YAC7C,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;iBACzB,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;IACD,OAAO,IAAI,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,EAAE;QACxC,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,uFAAuF,iBAAiB,gCAAgC;KAC/I,CAAC,CAAC;AACL,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,iBAAiB,EAAa,CAAC;AAEhD,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAI,KAAgB,EAAE,EAAW;IACxD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,WAAW;IACzB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* without spawning a subprocess.
|
|
7
7
|
*/
|
|
8
8
|
import { McpServer, type CreateMcpHandlerOptions, type McpHttpHandler } from '@modelcontextprotocol/server';
|
|
9
|
+
import { type AllowedRoots, type ClientRootsPolicy } from './roots.js';
|
|
9
10
|
import { type Enablement } from './enablement.js';
|
|
10
11
|
import { type ToolModule, type ModuleRefusal } from './modules.js';
|
|
11
12
|
export declare const SERVER_NAME: string;
|
|
@@ -24,9 +25,42 @@ export interface BuildServerOptions {
|
|
|
24
25
|
* a server built with no modules.
|
|
25
26
|
*/
|
|
26
27
|
enablement?: Enablement;
|
|
27
|
-
/**
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Modules the loader refused (`Discovery.refusals`). Not registered — they
|
|
30
|
+
* are reported to the client in `capabilities.experimental` and
|
|
31
|
+
* `instructions` (issue #26), together with any module in `modules` that
|
|
32
|
+
* throws while registering.
|
|
33
|
+
*/
|
|
34
|
+
refusals?: readonly ModuleRefusal[];
|
|
35
|
+
/**
|
|
36
|
+
* Directories a tool may read (issue #37, S5): the *configured* roots.
|
|
37
|
+
* Every path argument of every tool — the floor's and a module's — is
|
|
38
|
+
* refused if it has a `..` segment or is Windows-style on a POSIX host,
|
|
39
|
+
* and otherwise resolved with `realpath` and refused unless it lies inside
|
|
40
|
+
* an allowed root, so a symlink cannot lead out. Absent, the configured
|
|
41
|
+
* roots are `COGNIUM_MCP_ALLOWED_ROOTS`; absent both, **there are none**:
|
|
42
|
+
* the working directory is never a root, and every path is refused unless
|
|
43
|
+
* the client's MCP roots stand in (see `clientRoots`). `'*'` (or
|
|
44
|
+
* `COGNIUM_MCP_ALLOWED_ROOTS=*`) is the explicit opt-out. An empty list
|
|
45
|
+
* refuses every path.
|
|
46
|
+
*
|
|
47
|
+
* When the client declares the `roots` capability, its MCP roots narrow
|
|
48
|
+
* these: a tool may read only the part of the client's roots that lies
|
|
49
|
+
* inside a configured root.
|
|
50
|
+
*/
|
|
51
|
+
allowedRoots?: AllowedRoots;
|
|
52
|
+
/**
|
|
53
|
+
* What the client's MCP roots may do when no root is configured.
|
|
54
|
+
* `'narrow'` (the default): nothing — they only ever narrow configured
|
|
55
|
+
* roots, so with none configured every path is refused. `'establish'`:
|
|
56
|
+
* they are the allowed roots. The stdio binary uses `'establish'`, since
|
|
57
|
+
* its client is the user's own; `createHandler()` leaves the default,
|
|
58
|
+
* since an HTTP client's roots name directories on the client's machine.
|
|
59
|
+
*/
|
|
60
|
+
clientRoots?: ClientRootsPolicy;
|
|
29
61
|
}
|
|
62
|
+
/** The key the server's `roots/list` input request goes under (protocol revision 2026-07-28). */
|
|
63
|
+
export declare const ROOTS_INPUT = "cognium/roots";
|
|
30
64
|
export declare function buildServer(opts?: BuildServerOptions): McpServer;
|
|
31
65
|
export interface Discovery {
|
|
32
66
|
readonly modules: readonly ToolModule[];
|
|
@@ -48,7 +82,7 @@ export declare function resetDiscoveryForTests(): void;
|
|
|
48
82
|
* The server a host should build: floor plus whatever optional modules this
|
|
49
83
|
* install has, with enablement computed once.
|
|
50
84
|
*/
|
|
51
|
-
export declare function createServer(opts?: Omit<BuildServerOptions, 'modules' | 'enablement'>): Promise<{
|
|
85
|
+
export declare function createServer(opts?: Omit<BuildServerOptions, 'modules' | 'refusals' | 'enablement'>): Promise<{
|
|
52
86
|
server: McpServer;
|
|
53
87
|
discovery: Discovery;
|
|
54
88
|
}>;
|
|
@@ -65,7 +99,7 @@ export declare function createServer(opts?: Omit<BuildServerOptions, 'modules' |
|
|
|
65
99
|
* A host that connects `createServer()`'s server to a transport of its own
|
|
66
100
|
* still works, and serves the 2025-era protocol only.
|
|
67
101
|
*/
|
|
68
|
-
export declare function createHandler(opts?: Omit<BuildServerOptions, 'modules' | 'enablement'> & {
|
|
102
|
+
export declare function createHandler(opts?: Omit<BuildServerOptions, 'modules' | 'refusals' | 'enablement'> & {
|
|
69
103
|
handler?: CreateMcpHandlerOptions;
|
|
70
104
|
}): McpHttpHandler;
|
|
71
105
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAEL,SAAS,EAKT,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACvB,MAAM,YAAY,CAAC;AAEpB,OAA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