@cavelang/cli 0.29.1 → 0.31.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/README.md +15 -1
- package/dist/internal/act/engine.d.ts +5 -1
- package/dist/internal/act/engine.d.ts.map +1 -1
- package/dist/internal/act/engine.js +39 -32
- package/dist/internal/act/engine.js.map +1 -1
- package/dist/internal/automate/engine.d.ts +4 -0
- package/dist/internal/automate/engine.d.ts.map +1 -1
- package/dist/internal/automate/engine.js +31 -25
- package/dist/internal/automate/engine.js.map +1 -1
- package/dist/internal/automate/main.d.ts.map +1 -1
- package/dist/internal/automate/main.js +7 -4
- package/dist/internal/automate/main.js.map +1 -1
- package/dist/internal/eval/loop.d.ts +1 -0
- package/dist/internal/eval/loop.d.ts.map +1 -1
- package/dist/internal/eval/loop.js +2 -1
- package/dist/internal/eval/loop.js.map +1 -1
- package/dist/internal/eval/main.d.ts.map +1 -1
- package/dist/internal/eval/main.js +2 -1
- package/dist/internal/eval/main.js.map +1 -1
- package/dist/internal/eval/run.d.ts +2 -0
- package/dist/internal/eval/run.d.ts.map +1 -1
- package/dist/internal/eval/run.js +6 -4
- package/dist/internal/eval/run.js.map +1 -1
- package/dist/internal/ingest/index.d.ts +1 -1
- package/dist/internal/ingest/index.d.ts.map +1 -1
- package/dist/internal/ingest/index.js.map +1 -1
- package/dist/internal/ingest/main.d.ts.map +1 -1
- package/dist/internal/ingest/main.js +4 -2
- package/dist/internal/ingest/main.js.map +1 -1
- package/dist/internal/ingest/run.d.ts +8 -1
- package/dist/internal/ingest/run.d.ts.map +1 -1
- package/dist/internal/ingest/run.js +17 -34
- package/dist/internal/ingest/run.js.map +1 -1
- package/dist/internal/loop/index.d.ts +2 -0
- package/dist/internal/loop/index.d.ts.map +1 -1
- package/dist/internal/loop/index.js +1 -0
- package/dist/internal/loop/index.js.map +1 -1
- package/dist/internal/loop/llm.d.ts +6 -0
- package/dist/internal/loop/llm.d.ts.map +1 -1
- package/dist/internal/loop/llm.js +22 -49
- package/dist/internal/loop/llm.js.map +1 -1
- package/dist/internal/loop/process-worker.d.ts +3 -0
- package/dist/internal/loop/process-worker.d.ts.map +1 -0
- package/dist/internal/loop/process-worker.js +32 -0
- package/dist/internal/loop/process-worker.js.map +1 -0
- package/dist/internal/loop/process.d.ts +61 -0
- package/dist/internal/loop/process.d.ts.map +1 -0
- package/dist/internal/loop/process.js +268 -0
- package/dist/internal/loop/process.js.map +1 -0
- package/dist/internal/mcp/guide.d.ts +12 -0
- package/dist/internal/mcp/guide.d.ts.map +1 -0
- package/dist/internal/mcp/guide.js +56 -0
- package/dist/internal/mcp/guide.js.map +1 -0
- package/dist/internal/mcp/index.d.ts +2 -2
- package/dist/internal/mcp/index.d.ts.map +1 -1
- package/dist/internal/mcp/index.js +2 -2
- package/dist/internal/mcp/index.js.map +1 -1
- package/dist/internal/mcp/server.d.ts +36 -36
- package/dist/internal/mcp/server.d.ts.map +1 -1
- package/dist/internal/mcp/server.js +90 -141
- package/dist/internal/mcp/server.js.map +1 -1
- package/dist/internal/mcp/tools.d.ts +5 -1
- package/dist/internal/mcp/tools.d.ts.map +1 -1
- package/dist/internal/mcp/tools.js +26 -1
- package/dist/internal/mcp/tools.js.map +1 -1
- package/dist/internal/view/scope.d.ts +19 -4
- package/dist/internal/view/scope.d.ts.map +1 -1
- package/dist/internal/view/scope.js +115 -31
- package/dist/internal/view/scope.js.map +1 -1
- package/dist/src/cli.d.ts +6 -2
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +12 -5
- package/dist/src/cli.js.map +1 -1
- package/dist/src/dispatch.d.ts.map +1 -1
- package/dist/src/dispatch.js +2 -2
- package/dist/src/dispatch.js.map +1 -1
- package/dist/src/doctor.d.ts.map +1 -1
- package/dist/src/doctor.js +19 -7
- package/dist/src/doctor.js.map +1 -1
- package/package.json +22 -21
- package/src/cli.ts +18 -5
- package/src/dispatch.ts +4 -2
- package/src/doctor.ts +18 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAC/D,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EACxD,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EACL,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EACnE,iBAAiB,EAAE,WAAW,EAAE,KAAK,EACtC,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* { "command": "cave", "args": ["mcp", "--db", "knowledge.db"] }
|
|
7
7
|
* ```
|
|
8
8
|
*
|
|
9
|
-
* Tools: cave_add, cave_query, cave_fuse, cave_search, cave_about,
|
|
9
|
+
* Tools: cave_help, cave_add, cave_query, cave_fuse, cave_search, cave_about,
|
|
10
10
|
* cave_neighbors, cave_reconstruct, cave_derive, cave_export, cave_lint —
|
|
11
11
|
* plus one generated `act_<name>` tool per action declared in the store
|
|
12
12
|
* (spec §25.5), the governed write vocabulary. `cave_fuse` and
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* `--tools <list>` narrow the served surface — the minimum viable agent
|
|
18
18
|
* permission boundary.
|
|
19
19
|
*/
|
|
20
|
-
export { agentSource, createServer, serve, instructions, instructionsFor, protocolVersion, serverInfo, specCard } from "./server.js";
|
|
20
|
+
export { agentSource, createServer, serve, instructions, instructionsFor, protocolVersion, protocolVersions, serverInfo, specCard } from "./server.js";
|
|
21
21
|
export { runMcp } from "./main.js";
|
|
22
22
|
export { actionTools, actToolName, actToolPrefix, allowsActions, permissions, scopedActionTools, scopedTools, tools } from "./tools.js";
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAC/D,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EACxD,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EACL,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EACnE,iBAAiB,EAAE,WAAW,EAAE,KAAK,EACtC,MAAM,YAAY,CAAA"}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* CAVE's tool surface on the official MCP TypeScript SDK v2.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `serve` wires it to stdin/stdout.
|
|
9
|
-
*
|
|
10
|
-
* Hand-rolled rather than pulling in an SDK: the protocol surface here is
|
|
11
|
-
* ~150 lines, the repo is otherwise dependency-free beyond
|
|
12
|
-
* `@prelude/parser`, and `@prelude/jsonrpc` targets WebSocket-style
|
|
13
|
-
* transports with numeric-only ids (MCP ids may be strings).
|
|
4
|
+
* `createToolSurface` keeps domain behavior transport-free and testable;
|
|
5
|
+
* `createServer` binds it to the SDK's low-level Server; `serve` delegates
|
|
6
|
+
* stdio framing, lifecycle, protocol-era detection, and legacy fallback to
|
|
7
|
+
* `serveStdio`.
|
|
14
8
|
*/
|
|
9
|
+
import { Server } from '@modelcontextprotocol/server';
|
|
15
10
|
import type { Store } from '@cavelang/store';
|
|
16
11
|
import { type Scope, type Tool } from './tools.ts';
|
|
17
12
|
export type ServerOptions = Scope & {
|
|
18
13
|
/**
|
|
19
14
|
* Actor provenance stamp for appends (spec §9.5), without the `src:`
|
|
20
|
-
* prefix. Default: `agent/<client-name>` from the initialize handshake
|
|
21
|
-
* plain `agent`
|
|
15
|
+
* prefix. Default: `agent/<client-name>` from the initialize handshake or
|
|
16
|
+
* modern request envelope, plain `agent` without one. `false` disables
|
|
17
|
+
* stamping.
|
|
22
18
|
*/
|
|
23
19
|
readonly source?: string | false;
|
|
24
20
|
/** Out-of-band hook command templates for action tools (spec §25.4). */
|
|
@@ -32,8 +28,10 @@ export type ServerOptions = Scope & {
|
|
|
32
28
|
* plain `agent` when no usable name is known (spec §9.5).
|
|
33
29
|
*/
|
|
34
30
|
export declare const agentSource: (clientName: undefined | string) => string;
|
|
35
|
-
/**
|
|
36
|
-
export declare const
|
|
31
|
+
/** Legacy initialize-era revisions supported by the official MCP SDK. */
|
|
32
|
+
export declare const protocolVersions: string[];
|
|
33
|
+
/** The preferred MCP protocol revision offered during version negotiation. */
|
|
34
|
+
export declare const protocolVersion = "2025-11-25";
|
|
37
35
|
export declare const serverInfo: {
|
|
38
36
|
readonly name: "cave";
|
|
39
37
|
readonly version: string;
|
|
@@ -60,33 +58,35 @@ export declare const instructionsFor: (served: readonly Tool[], options?: {
|
|
|
60
58
|
* how to write CAVE without reading the full specification.
|
|
61
59
|
*/
|
|
62
60
|
export declare const instructions: string;
|
|
63
|
-
type
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
code: number;
|
|
70
|
-
message: string;
|
|
61
|
+
export type ListedTool = {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly description: string;
|
|
64
|
+
readonly inputSchema: Tool['inputSchema'];
|
|
65
|
+
readonly annotations?: {
|
|
66
|
+
readonly readOnlyHint: true;
|
|
71
67
|
};
|
|
72
68
|
};
|
|
73
|
-
type
|
|
69
|
+
export type ToolCallResult = {
|
|
70
|
+
content: [{
|
|
71
|
+
type: 'text';
|
|
72
|
+
text: string;
|
|
73
|
+
}];
|
|
74
|
+
readonly isError?: true;
|
|
75
|
+
};
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* `initialize` becomes the default `agent/<name>` provenance stamp on
|
|
78
|
-
* appends (spec §9.5). Serves the scoped tool surface — tools outside the
|
|
79
|
-
* scope are absent from `tools/list` and unknown to `tools/call`; throws
|
|
80
|
-
* when the scope names an unknown tool or serves none.
|
|
77
|
+
* Pure CAVE tool surface beneath the MCP SDK. Action declarations are read on
|
|
78
|
+
* every list/call, so actions added mid-session appear without reconnecting.
|
|
81
79
|
*/
|
|
82
|
-
export declare const
|
|
83
|
-
|
|
80
|
+
export declare const createToolSurface: (store: Store, options?: ServerOptions) => {
|
|
81
|
+
list: () => ListedTool[];
|
|
82
|
+
call: (name: string, args: Record<string, unknown>, clientName?: string) => ToolCallResult;
|
|
84
83
|
};
|
|
85
84
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* Builds an official SDK server over CAVE's scoped, dynamic tool surface.
|
|
86
|
+
* Protocol negotiation, validation, lifecycle, ping, and error envelopes are
|
|
87
|
+
* owned by `@modelcontextprotocol/server`.
|
|
89
88
|
*/
|
|
89
|
+
export declare const createServer: (store: Store, options?: ServerOptions) => Server;
|
|
90
|
+
/** Serves both the 2026 MCP era and legacy initialize-era clients on stdio. */
|
|
90
91
|
export declare const serve: (store: Store, input: NodeJS.ReadableStream, output: NodeJS.WritableStream, options?: ServerOptions) => Promise<void>;
|
|
91
|
-
export {};
|
|
92
92
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAEc,MAAM,EAC1B,MAAM,8BAA8B,CAAA;AAGrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAuE,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAA;AAEvH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAChC,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,YAAY,SAAS,GAAG,MAAM,KAAG,MAO5D,CAAA;AAED,yEAAyE;AACzE,eAAO,MAAM,gBAAgB,UAAmC,CAAA;AAEhE,8EAA8E;AAC9E,eAAO,MAAM,eAAe,eAA0B,CAAA;AAEtD,eAAO,MAAM,UAAU;;;CAGb,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,QAAQ,i5BAgB4C,CAAA;AAEjE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,IAAI,EAAE,EAAE,UAAS;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,KAAG,MAkC9F,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAA4C,CAAA;AAErE,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAA;KAAE,CAAA;CACvD,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAA;CACxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,KAAK,EAAE,UAAS,aAAkB;gBAMxD,UAAU,EAAE;iBAQrB,MAAM,QACN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAChB,MAAM,KAClB,cAAc;CAmBlB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,EAAE,UAAS,aAAkB,KAAG,MAqBxE,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,KAAK,GAChB,OAAO,KAAK,EACZ,OAAO,MAAM,CAAC,cAAc,EAC5B,QAAQ,MAAM,CAAC,cAAc,EAC7B,UAAS,aAAkB,KAC1B,OAAO,CAAC,IAAI,CAgCd,CAAA"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* CAVE's tool surface on the official MCP TypeScript SDK v2.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `serve` wires it to stdin/stdout.
|
|
9
|
-
*
|
|
10
|
-
* Hand-rolled rather than pulling in an SDK: the protocol surface here is
|
|
11
|
-
* ~150 lines, the repo is otherwise dependency-free beyond
|
|
12
|
-
* `@prelude/parser`, and `@prelude/jsonrpc` targets WebSocket-style
|
|
13
|
-
* transports with numeric-only ids (MCP ids may be strings).
|
|
4
|
+
* `createToolSurface` keeps domain behavior transport-free and testable;
|
|
5
|
+
* `createServer` binds it to the SDK's low-level Server; `serve` delegates
|
|
6
|
+
* stdio framing, lifecycle, protocol-era detection, and legacy fallback to
|
|
7
|
+
* `serveStdio`.
|
|
14
8
|
*/
|
|
15
|
-
import {
|
|
9
|
+
import { CLIENT_INFO_META_KEY, LATEST_PROTOCOL_VERSION, ProtocolError, ProtocolErrorCode, Server, SUPPORTED_PROTOCOL_VERSIONS } from '@modelcontextprotocol/server';
|
|
10
|
+
import { serveStdio, StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
16
11
|
import { Version } from '@cavelang/core';
|
|
17
12
|
import { actToolPrefix, allowsActions, scopedActionTools, scopedTools, tools } from "./tools.js";
|
|
18
13
|
/**
|
|
@@ -28,8 +23,10 @@ export const agentSource = (clientName) => {
|
|
|
28
23
|
.replace(/[^a-z0-9._/-]/g, '');
|
|
29
24
|
return name === '' ? 'agent' : `agent/${name}`;
|
|
30
25
|
};
|
|
31
|
-
/**
|
|
32
|
-
export const
|
|
26
|
+
/** Legacy initialize-era revisions supported by the official MCP SDK. */
|
|
27
|
+
export const protocolVersions = [...SUPPORTED_PROTOCOL_VERSIONS];
|
|
28
|
+
/** The preferred MCP protocol revision offered during version negotiation. */
|
|
29
|
+
export const protocolVersion = LATEST_PROTOCOL_VERSION;
|
|
33
30
|
export const serverInfo = {
|
|
34
31
|
name: 'cave',
|
|
35
32
|
version: Version.current()
|
|
@@ -67,6 +64,7 @@ export const instructionsFor = (served, options = {}) => {
|
|
|
67
64
|
const has = (name) => served.some(tool => tool.name === name);
|
|
68
65
|
const explore = ['cave_about', 'cave_neighbors'].filter(has);
|
|
69
66
|
const clauses = [
|
|
67
|
+
...has('cave_help') ? ['consult cave_help for version-matched usage guidance when needed'] : [],
|
|
70
68
|
...has('cave_add') ?
|
|
71
69
|
[`extract knowledge with one claim per line via cave_add${has('cave_lint') ? ' (validate with cave_lint first)' : ''}`] :
|
|
72
70
|
has('cave_lint') ? ['validate CAVE text with cave_lint'] : [],
|
|
@@ -103,149 +101,100 @@ export const instructionsFor = (served, options = {}) => {
|
|
|
103
101
|
* how to write CAVE without reading the full specification.
|
|
104
102
|
*/
|
|
105
103
|
export const instructions = instructionsFor(tools, { actions: true });
|
|
106
|
-
const result = (id, value) => ({ jsonrpc: '2.0', id, result: value });
|
|
107
|
-
const failure = (id, code, message) => ({ jsonrpc: '2.0', id, error: { code, message } });
|
|
108
|
-
const isId = (value) => value === null || typeof value === 'string' || typeof value === 'number';
|
|
109
104
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* `initialize` becomes the default `agent/<name>` provenance stamp on
|
|
113
|
-
* appends (spec §9.5). Serves the scoped tool surface — tools outside the
|
|
114
|
-
* scope are absent from `tools/list` and unknown to `tools/call`; throws
|
|
115
|
-
* when the scope names an unknown tool or serves none.
|
|
105
|
+
* Pure CAVE tool surface beneath the MCP SDK. Action declarations are read on
|
|
106
|
+
* every list/call, so actions added mid-session appear without reconnecting.
|
|
116
107
|
*/
|
|
117
|
-
export const
|
|
108
|
+
export const createToolSurface = (store, options = {}) => {
|
|
118
109
|
const served = scopedTools(options);
|
|
119
110
|
const servedByName = new Map(served.map(tool => [tool.name, tool]));
|
|
120
|
-
// Action tools are generated from the store's current declarations per
|
|
121
|
-
// request (spec §25.5) — an action declared mid-session appears in the
|
|
122
|
-
// next tools/list without reconnecting.
|
|
123
111
|
const actionsPossible = allowsActions(options);
|
|
124
112
|
const actServed = () => actionsPossible ? scopedActionTools(store, options) : [];
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
113
|
+
const list = () => [...served, ...actServed()].map(tool => ({
|
|
114
|
+
name: tool.name,
|
|
115
|
+
description: tool.description,
|
|
116
|
+
inputSchema: tool.inputSchema,
|
|
117
|
+
...(tool.permission === 'record' || tool.permission === 'action' ?
|
|
118
|
+
{} : { annotations: { readOnlyHint: true } })
|
|
119
|
+
}));
|
|
120
|
+
const call = (name, args, clientName) => {
|
|
121
|
+
const tool = servedByName.get(name) ??
|
|
122
|
+
(name.startsWith(actToolPrefix) ? actServed().find(candidate => candidate.name === name) : undefined);
|
|
123
|
+
if (tool === undefined) {
|
|
124
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Unknown tool: ${name}`);
|
|
131
125
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
try {
|
|
127
|
+
const stamp = options.source === false ? undefined : options.source ?? agentSource(clientName);
|
|
128
|
+
const text = tool.run(store, args, {
|
|
129
|
+
...stamp === undefined ? {} : { source: stamp },
|
|
130
|
+
...options.hooks === undefined ? {} : { hooks: options.hooks }
|
|
131
|
+
});
|
|
132
|
+
return { content: [{ type: 'text', text }] };
|
|
136
133
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return undefined;
|
|
134
|
+
catch (error) {
|
|
135
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
136
|
+
return { content: [{ type: 'text', text }], isError: true };
|
|
141
137
|
}
|
|
142
|
-
const requestId = id;
|
|
143
|
-
switch (method) {
|
|
144
|
-
case 'initialize': {
|
|
145
|
-
const requested = params?.protocolVersion;
|
|
146
|
-
if (requested !== protocolVersion) {
|
|
147
|
-
return failure(requestId, -32602, `Unsupported protocol version: ${String(requested)}; supported: ${protocolVersion}`);
|
|
148
|
-
}
|
|
149
|
-
const name = params?.clientInfo?.name;
|
|
150
|
-
if (typeof name === 'string') {
|
|
151
|
-
clientName = name;
|
|
152
|
-
}
|
|
153
|
-
return result(requestId, {
|
|
154
|
-
protocolVersion,
|
|
155
|
-
capabilities: { tools: {} },
|
|
156
|
-
serverInfo,
|
|
157
|
-
instructions: servedInstructions
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
case 'ping':
|
|
161
|
-
return result(requestId, {});
|
|
162
|
-
case 'tools/list':
|
|
163
|
-
return result(requestId, {
|
|
164
|
-
tools: [...served, ...actServed()].map(tool => ({
|
|
165
|
-
name: tool.name,
|
|
166
|
-
description: tool.description,
|
|
167
|
-
inputSchema: tool.inputSchema,
|
|
168
|
-
...(tool.permission === 'record' || tool.permission === 'action' ?
|
|
169
|
-
{} : { annotations: { readOnlyHint: true } })
|
|
170
|
-
}))
|
|
171
|
-
});
|
|
172
|
-
case 'tools/call': {
|
|
173
|
-
const call = (params ?? {});
|
|
174
|
-
const tool = typeof call.name === 'string' ?
|
|
175
|
-
servedByName.get(call.name) ??
|
|
176
|
-
(call.name.startsWith(actToolPrefix) ? actServed().find(candidate => candidate.name === call.name) : undefined) :
|
|
177
|
-
undefined;
|
|
178
|
-
if (tool === undefined) {
|
|
179
|
-
return failure(requestId, -32602, `Unknown tool: ${String(call.name)}`);
|
|
180
|
-
}
|
|
181
|
-
const args = typeof call.arguments === 'object' && call.arguments !== null ?
|
|
182
|
-
call.arguments :
|
|
183
|
-
{};
|
|
184
|
-
try {
|
|
185
|
-
const stamp = source();
|
|
186
|
-
const text = tool.run(store, args, {
|
|
187
|
-
...stamp === undefined ? {} : { source: stamp },
|
|
188
|
-
...options.hooks === undefined ? {} : { hooks: options.hooks }
|
|
189
|
-
});
|
|
190
|
-
return result(requestId, { content: [{ type: 'text', text }] });
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
const text = error instanceof Error ? error.message : String(error);
|
|
194
|
-
return result(requestId, { content: [{ type: 'text', text }], isError: true });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
default:
|
|
198
|
-
return failure(requestId, -32601, `Method not found: ${method}`);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const handle = (message) => {
|
|
202
|
-
if (!Array.isArray(message))
|
|
203
|
-
return dispatch(message);
|
|
204
|
-
if (message.length === 0)
|
|
205
|
-
return failure(null, -32600, 'Invalid request');
|
|
206
|
-
const responses = message.flatMap(item => {
|
|
207
|
-
const response = dispatch(item);
|
|
208
|
-
return response === undefined ? [] : [response];
|
|
209
|
-
});
|
|
210
|
-
return responses.length === 0 ? undefined : responses;
|
|
211
138
|
};
|
|
212
|
-
return {
|
|
139
|
+
return { list, call };
|
|
213
140
|
};
|
|
214
141
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
142
|
+
* Builds an official SDK server over CAVE's scoped, dynamic tool surface.
|
|
143
|
+
* Protocol negotiation, validation, lifecycle, ping, and error envelopes are
|
|
144
|
+
* owned by `@modelcontextprotocol/server`.
|
|
218
145
|
*/
|
|
146
|
+
export const createServer = (store, options = {}) => {
|
|
147
|
+
const served = scopedTools(options);
|
|
148
|
+
const actionsPossible = allowsActions(options);
|
|
149
|
+
const surface = createToolSurface(store, options);
|
|
150
|
+
const server = new Server(serverInfo, {
|
|
151
|
+
capabilities: { tools: {} },
|
|
152
|
+
instructions: instructionsFor(served, { actions: actionsPossible })
|
|
153
|
+
});
|
|
154
|
+
const clientName = (context) => {
|
|
155
|
+
const envelope = context.mcpReq.envelope;
|
|
156
|
+
const modern = envelope?.[CLIENT_INFO_META_KEY];
|
|
157
|
+
return typeof modern?.name === 'string' ? modern.name : server.getClientVersion()?.name;
|
|
158
|
+
};
|
|
159
|
+
server.setRequestHandler('tools/list', async () => ({ tools: surface.list() }));
|
|
160
|
+
server.setRequestHandler('tools/call', async (request, context) => server.projectCallToolResult(surface.call(request.params.name, request.params.arguments ?? {}, clientName(context)), undefined));
|
|
161
|
+
return server;
|
|
162
|
+
};
|
|
163
|
+
/** Serves both the 2026 MCP era and legacy initialize-era clients on stdio. */
|
|
219
164
|
export const serve = (store, input, output, options = {}) => {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
165
|
+
const transport = new StdioServerTransport(input, output);
|
|
166
|
+
const handle = serveStdio(() => createServer(store, options), { transport });
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
let finished = false;
|
|
169
|
+
const cleanup = () => {
|
|
170
|
+
input.removeListener('end', close);
|
|
171
|
+
input.removeListener('close', close);
|
|
172
|
+
input.removeListener('error', fail);
|
|
173
|
+
options.signal?.removeEventListener('abort', close);
|
|
174
|
+
};
|
|
175
|
+
const done = () => {
|
|
176
|
+
if (finished)
|
|
227
177
|
return;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
message = JSON.parse(line);
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
234
|
-
output.write(`${JSON.stringify(failure(null, -32700, 'Parse error'))}\n`);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const response = server.handle(message);
|
|
238
|
-
if (response !== undefined) {
|
|
239
|
-
output.write(`${JSON.stringify(response)}\n`);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
lines.on('close', () => {
|
|
243
|
-
options.signal?.removeEventListener('abort', abort);
|
|
178
|
+
finished = true;
|
|
179
|
+
cleanup();
|
|
244
180
|
resolve();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
181
|
+
};
|
|
182
|
+
const fail = (error) => {
|
|
183
|
+
if (finished)
|
|
184
|
+
return;
|
|
185
|
+
finished = true;
|
|
186
|
+
cleanup();
|
|
187
|
+
reject(error);
|
|
188
|
+
};
|
|
189
|
+
const close = () => {
|
|
190
|
+
void handle.close().then(done, fail);
|
|
191
|
+
};
|
|
192
|
+
input.once('end', close);
|
|
193
|
+
input.once('close', close);
|
|
194
|
+
input.once('error', fail);
|
|
195
|
+
options.signal?.addEventListener('abort', close, { once: true });
|
|
196
|
+
if (options.signal?.aborted === true)
|
|
197
|
+
close();
|
|
249
198
|
});
|
|
250
199
|
};
|
|
251
200
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,oBAAoB,EAAE,uBAAuB,EAAE,aAAa,EAC5D,iBAAiB,EAAE,MAAM,EAAE,2BAA2B,EACvD,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,KAAK,EAAyB,MAAM,YAAY,CAAA;AAgBvH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,UAA8B,EAAU,EAAE;IACpE,MAAM,IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;SAC5B,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAA;IAChC,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAA;AAChD,CAAC,CAAA;AAED,yEAAyE;AACzE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,2BAA2B,CAAC,CAAA;AAEhE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAA;AAEtD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;CAClB,CAAA;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;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ACpB,QAAQ,GAAG,IAAI,CAAA;YACf,OAAO,EAAE,CAAA;YACT,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC,CAAA;QACD,MAAM,KAAK,GAAG,GAAS,EAAE;YACvB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC,CAAA;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACxB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC1B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACzB,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QAChE,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI;YAAE,KAAK,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* | Tool | Purpose |
|
|
6
6
|
* |---|---|
|
|
7
|
+
* | `cave_help` | version-matched usage guidance for agents |
|
|
7
8
|
* | `cave_add` | append CAVE text (extraction output) to the store |
|
|
8
9
|
* | `cave_query` | run a CAVE-Q pattern (spec §12) |
|
|
9
10
|
* | `cave_fuse` | Bayesian fusion of numeric estimates (§10.1) — named computation |
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
* the minimum viable agent permission boundary.
|
|
24
25
|
*/
|
|
25
26
|
import type { Store } from '@cavelang/store';
|
|
27
|
+
import type { Tool as McpTool } from '@modelcontextprotocol/server';
|
|
26
28
|
/** Per-connection state the server threads into tool calls. */
|
|
27
29
|
export type ToolContext = {
|
|
28
30
|
/**
|
|
@@ -40,7 +42,9 @@ export type Tool = {
|
|
|
40
42
|
readonly description: string;
|
|
41
43
|
/** Evaluation is ephemeral, recording is durable, and action may cause effects. */
|
|
42
44
|
readonly permission: Permission;
|
|
43
|
-
readonly inputSchema:
|
|
45
|
+
readonly inputSchema: McpTool['inputSchema'] & {
|
|
46
|
+
readonly properties: NonNullable<McpTool['inputSchema']['properties']>;
|
|
47
|
+
};
|
|
44
48
|
readonly run: (store: Store, args: Record<string, unknown>, context: ToolContext) => string;
|
|
45
49
|
};
|
|
46
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAM5C,OAAO,KAAK,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAGnE,+DAA+D;AAC/D,MAAM,MAAM,WAAW,GAAG;IACxB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAClD,CAAA;AAED,eAAO,MAAM,WAAW,mDAAoD,CAAA;AAC5E,MAAM,MAAM,UAAU,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAEnD,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,mFAAmF;IACnF,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG;QAC7C,QAAQ,CAAC,UAAU,EAAE,WAA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
|
7
8
|
* | `cave_add` | append CAVE text (extraction output) to the store |
|
|
8
9
|
* | `cave_query` | run a CAVE-Q pattern (spec §12) |
|
|
9
10
|
* | `cave_fuse` | Bayesian fusion of numeric estimates (§10.1) — named computation |
|
|
@@ -31,6 +32,7 @@ import { estimateOf, fuse } from '@cavelang/fusion';
|
|
|
31
32
|
import { derive } from '@cavelang/cli/rules';
|
|
32
33
|
import { reconstruct, heuristicPolicy, sqliteStore } from '@cavelang/cli/loop';
|
|
33
34
|
import { act, listActions } from '@cavelang/cli/act';
|
|
35
|
+
import { guideFor, guideTopics } from "./guide.js";
|
|
34
36
|
export const permissions = ['read', 'evaluate', 'record', 'action'];
|
|
35
37
|
const text = (value, name) => {
|
|
36
38
|
if (typeof value !== 'string' || value === '') {
|
|
@@ -131,6 +133,29 @@ const selectFuseClaims = (store, args) => {
|
|
|
131
133
|
return result.claims.map(entry => entry.claim);
|
|
132
134
|
};
|
|
133
135
|
export const tools = [
|
|
136
|
+
{
|
|
137
|
+
name: 'cave_help',
|
|
138
|
+
description: 'Version-matched CAVE usage guidance for agents. Call before the first CAVE task ' +
|
|
139
|
+
'or when choosing how to write, find, revise, or safely handle knowledge. This reads no user data.',
|
|
140
|
+
permission: 'read',
|
|
141
|
+
inputSchema: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
topic: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
enum: [...guideTopics],
|
|
147
|
+
description: 'guide topic (default: overview)'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
run: (_store, args) => {
|
|
152
|
+
const topic = args['topic'] ?? 'overview';
|
|
153
|
+
if (typeof topic !== 'string' || !guideTopics.includes(topic)) {
|
|
154
|
+
throw new Error(`topic must be one of ${guideTopics.join(', ')}`);
|
|
155
|
+
}
|
|
156
|
+
return guideFor(topic);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
134
159
|
{
|
|
135
160
|
name: 'cave_add',
|
|
136
161
|
description: 'Append CAVE claims to the knowledge database. Input is CAVE text ' +
|
|
@@ -429,7 +454,7 @@ export const tools = [
|
|
|
429
454
|
type: 'object',
|
|
430
455
|
properties: {
|
|
431
456
|
current: { type: 'boolean' },
|
|
432
|
-
maxSensitivity: { type: 'string', enum: Sensitivity.levels }
|
|
457
|
+
maxSensitivity: { type: 'string', enum: [...Sensitivity.levels] }
|
|
433
458
|
}
|
|
434
459
|
},
|
|
435
460
|
run: (store, args) => {
|