toolcraft 0.0.232 → 0.0.233
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/composition.json +3 -3
- package/dist/applied-default.d.ts +3 -0
- package/dist/applied-default.js +16 -0
- package/dist/cli.js +508 -204
- package/dist/composition.json +3 -3
- package/dist/discriminator.d.ts +9 -0
- package/dist/discriminator.js +32 -0
- package/dist/error-report.d.ts +2 -18
- package/dist/error-report.js +12 -14
- package/dist/http.js +8 -1
- package/dist/human-in-loop/gate.js +6 -0
- package/dist/index.compile-check.js +22 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +50 -0
- package/dist/json-schema-converter.d.ts +14 -6
- package/dist/json-schema-converter.js +150 -20
- package/dist/mcp-proxy-metadata.d.ts +2 -0
- package/dist/mcp-proxy-metadata.js +13 -0
- package/dist/mcp-proxy.d.ts +1 -0
- package/dist/mcp-proxy.js +65 -47
- package/dist/mcp-result.d.ts +3 -0
- package/dist/mcp-result.js +10 -0
- package/dist/mcp.js +211 -153
- package/dist/redaction.js +26 -17
- package/dist/renderer.js +40 -29
- package/dist/schema-member-names.d.ts +2 -0
- package/dist/schema-member-names.js +39 -0
- package/dist/schema-scope.d.ts +1 -0
- package/dist/schema-scope.js +29 -16
- package/dist/schema.d.ts +1 -1
- package/dist/sdk.d.ts +2 -1
- package/dist/sdk.js +164 -50
- package/dist/stream.js +24 -23
- package/dist/testing/diagnostic-value.d.ts +1 -0
- package/dist/testing/diagnostic-value.js +57 -0
- package/dist/testing/fakes.js +2 -1
- package/dist/testing/harness.js +1 -0
- package/dist/testing/memory-fs.js +42 -1
- package/dist/testing/parity.js +50 -6
- package/dist/union-validation.d.ts +5 -0
- package/dist/union-validation.js +36 -0
- package/node_modules/@poe-code/process-runner/dist/types.d.ts +2 -0
- package/node_modules/mcp-oauth-server/dist/index.js +47 -6
- package/node_modules/tiny-http-mcp-server/dist/cli.js +14 -2
- package/node_modules/tiny-http-mcp-server/dist/composition.json +1 -1
- package/node_modules/tiny-http-mcp-server/dist/http-server.d.ts +7 -5
- package/node_modules/tiny-http-mcp-server/dist/http-server.js +3 -11
- package/node_modules/tiny-http-mcp-server/dist/http-transport.d.ts +6 -1
- package/node_modules/tiny-http-mcp-server/dist/http-transport.js +196 -15
- package/node_modules/tiny-http-mcp-server/dist/index.d.ts +2 -2
- package/node_modules/tiny-http-mcp-server/dist/modern-headers.d.ts +3 -0
- package/node_modules/tiny-http-mcp-server/dist/modern-headers.js +35 -0
- package/node_modules/tiny-http-mcp-server/dist/parse-body.d.ts +1 -0
- package/node_modules/tiny-http-mcp-server/dist/parse-body.js +9 -5
- package/node_modules/tiny-http-mcp-server/dist/test-support.js +17 -0
- package/node_modules/tiny-http-mcp-server/dist/testing.d.ts +1 -1
- package/node_modules/tiny-http-mcp-server/dist/testing.js +3 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +21 -4
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.d.ts +1 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +14 -6
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.d.ts +1 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +8 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-response.d.ts +1 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-response.js +50 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +2 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +2 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/server/jwks-token-verifier.js +21 -3
- package/node_modules/tiny-http-mcp-server/package.json +1 -1
- package/node_modules/tiny-mcp-client/README.md +1 -0
- package/node_modules/tiny-mcp-client/dist/index.d.ts +178 -101
- package/node_modules/tiny-mcp-client/dist/index.js +4696 -291
- package/node_modules/tiny-mcp-client/package.json +2 -1
- package/node_modules/tiny-stdio-mcp-server/dist/base64.d.ts +1 -0
- package/node_modules/tiny-stdio-mcp-server/dist/base64.js +5 -0
- package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
- package/node_modules/tiny-stdio-mcp-server/dist/content/audio.d.ts +3 -0
- package/node_modules/tiny-stdio-mcp-server/dist/content/convert.d.ts +5 -1
- package/node_modules/tiny-stdio-mcp-server/dist/content/convert.js +41 -6
- package/node_modules/tiny-stdio-mcp-server/dist/content/file.d.ts +5 -0
- package/node_modules/tiny-stdio-mcp-server/dist/content/image.d.ts +3 -0
- package/node_modules/tiny-stdio-mcp-server/dist/headers.d.ts +10 -0
- package/node_modules/tiny-stdio-mcp-server/dist/headers.js +180 -0
- package/node_modules/tiny-stdio-mcp-server/dist/index.d.ts +5 -5
- package/node_modules/tiny-stdio-mcp-server/dist/index.js +1 -1
- package/node_modules/tiny-stdio-mcp-server/dist/input-request-schema.d.ts +220 -0
- package/node_modules/tiny-stdio-mcp-server/dist/input-request-schema.js +1995 -0
- package/node_modules/tiny-stdio-mcp-server/dist/jsonrpc.d.ts +1 -0
- package/node_modules/tiny-stdio-mcp-server/dist/jsonrpc.js +38 -25
- package/node_modules/tiny-stdio-mcp-server/dist/metadata.d.ts +2 -0
- package/node_modules/tiny-stdio-mcp-server/dist/metadata.js +37 -0
- package/node_modules/tiny-stdio-mcp-server/dist/protocol-validation.d.ts +4 -0
- package/node_modules/tiny-stdio-mcp-server/dist/protocol-validation.js +53 -0
- package/node_modules/tiny-stdio-mcp-server/dist/protocol.d.ts +17 -0
- package/node_modules/tiny-stdio-mcp-server/dist/protocol.js +228 -0
- package/node_modules/tiny-stdio-mcp-server/dist/request-cancellation.d.ts +1 -0
- package/node_modules/tiny-stdio-mcp-server/dist/request-cancellation.js +18 -0
- package/node_modules/tiny-stdio-mcp-server/dist/sampling-messages.d.ts +18 -0
- package/node_modules/tiny-stdio-mcp-server/dist/sampling-messages.js +34 -0
- package/node_modules/tiny-stdio-mcp-server/dist/schema.d.ts +4 -1
- package/node_modules/tiny-stdio-mcp-server/dist/server.d.ts +9 -4
- package/node_modules/tiny-stdio-mcp-server/dist/server.js +334 -135
- package/node_modules/tiny-stdio-mcp-server/dist/stdio-input.d.ts +3 -0
- package/node_modules/tiny-stdio-mcp-server/dist/stdio-input.js +50 -28
- package/node_modules/tiny-stdio-mcp-server/dist/subscriptions.d.ts +11 -0
- package/node_modules/tiny-stdio-mcp-server/dist/subscriptions.js +128 -0
- package/node_modules/tiny-stdio-mcp-server/dist/types.d.ts +58 -18
- package/node_modules/tiny-stdio-mcp-server/dist/types.js +2 -1
- package/node_modules/tiny-stdio-mcp-server/dist/uri.d.ts +1 -0
- package/node_modules/tiny-stdio-mcp-server/dist/uri.js +41 -0
- package/node_modules/tiny-stdio-mcp-server/package.json +8 -0
- package/node_modules/toolcraft-design/dist/command-registry.d.ts +11 -0
- package/node_modules/toolcraft-design/dist/command-registry.js +24 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/dashboard/ansi.js +81 -27
- package/node_modules/toolcraft-design/dist/dashboard/buffer.js +39 -25
- package/node_modules/toolcraft-design/dist/dashboard/components/border.js +6 -5
- package/node_modules/toolcraft-design/dist/dashboard/components/footer.js +26 -21
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.d.ts +1 -1
- package/node_modules/toolcraft-design/dist/dashboard/components/output-pane.js +12 -6
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.d.ts +2 -1
- package/node_modules/toolcraft-design/dist/dashboard/components/stats-pane.js +51 -10
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.d.ts +4 -0
- package/node_modules/toolcraft-design/dist/dashboard/dashboard.js +77 -4
- package/node_modules/toolcraft-design/dist/dashboard/index.d.ts +2 -0
- package/node_modules/toolcraft-design/dist/dashboard/index.js +2 -0
- package/node_modules/toolcraft-design/dist/dashboard/keymap.js +26 -6
- package/node_modules/toolcraft-design/dist/dashboard/layout.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/dashboard/layout.js +19 -3
- package/node_modules/toolcraft-design/dist/dashboard/line-buffer.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/dashboard/line-buffer.js +63 -0
- package/node_modules/toolcraft-design/dist/dashboard/output-preview.d.ts +9 -0
- package/node_modules/toolcraft-design/dist/dashboard/output-preview.js +70 -0
- package/node_modules/toolcraft-design/dist/dashboard/snapshot.js +3 -1
- package/node_modules/toolcraft-design/dist/dashboard/store.js +9 -3
- package/node_modules/toolcraft-design/dist/dashboard/terminal-strings.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-strings.js +108 -0
- package/node_modules/toolcraft-design/dist/dashboard/terminal-width.js +3 -1
- package/node_modules/toolcraft-design/dist/dashboard/terminal.js +11 -1
- package/node_modules/toolcraft-design/dist/dashboard/testing/pipeline-scenario.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/dashboard/testing/pipeline-scenario.js +126 -0
- package/node_modules/toolcraft-design/dist/dashboard/types.d.ts +3 -1
- package/node_modules/toolcraft-design/dist/event-groups.d.ts +19 -0
- package/node_modules/toolcraft-design/dist/event-groups.js +49 -0
- package/node_modules/toolcraft-design/dist/index.d.ts +6 -1
- package/node_modules/toolcraft-design/dist/index.js +5 -1
- package/node_modules/toolcraft-design/dist/inline-notice.d.ts +14 -0
- package/node_modules/toolcraft-design/dist/inline-notice.js +28 -0
- package/node_modules/toolcraft-design/dist/metric.d.ts +8 -0
- package/node_modules/toolcraft-design/dist/metric.js +21 -0
- package/node_modules/toolcraft-design/dist/overlay-manager.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/overlay-manager.js +10 -0
- package/node_modules/toolcraft-design/dist/primitives.d.ts +12 -0
- package/node_modules/toolcraft-design/dist/primitives.js +7 -0
- package/node_modules/toolcraft-design/dist/progress-group.d.ts +7 -0
- package/node_modules/toolcraft-design/dist/progress-group.js +10 -0
- package/node_modules/toolcraft-design/dist/render-performance.d.ts +33 -0
- package/node_modules/toolcraft-design/dist/render-performance.js +71 -0
- package/node_modules/toolcraft-design/dist/task-tree.d.ts +22 -0
- package/node_modules/toolcraft-design/dist/task-tree.js +79 -0
- package/node_modules/toolcraft-design/dist/viewport.d.ts +18 -0
- package/node_modules/toolcraft-design/dist/viewport.js +56 -0
- package/node_modules/toolcraft-schema/dist/clone-default.d.ts +1 -0
- package/node_modules/toolcraft-schema/dist/clone-default.js +26 -0
- package/node_modules/toolcraft-schema/dist/index.compile-check.js +1 -0
- package/node_modules/toolcraft-schema/dist/index.d.ts +18 -9
- package/node_modules/toolcraft-schema/dist/index.js +46 -8
- package/node_modules/toolcraft-schema/dist/json-schema/compiler.d.ts +1 -0
- package/node_modules/toolcraft-schema/dist/json-schema/compiler.js +6 -0
- package/node_modules/toolcraft-schema/dist/json-schema/evaluate.js +6 -3
- package/node_modules/toolcraft-schema/dist/json-schema/normalize-nullability.d.ts +1 -0
- package/node_modules/toolcraft-schema/dist/json-schema/normalize-nullability.js +69 -0
- package/node_modules/toolcraft-schema/dist/json-schema/types.d.ts +1 -0
- package/node_modules/toolcraft-schema/dist/json.d.ts +4 -1
- package/node_modules/toolcraft-schema/dist/json.js +57 -1
- package/node_modules/toolcraft-schema/dist/native-json-schema.d.ts +10 -0
- package/node_modules/toolcraft-schema/dist/native-json-schema.js +11 -0
- package/node_modules/toolcraft-schema/dist/validate.d.ts +5 -1
- package/node_modules/toolcraft-schema/dist/validate.js +61 -47
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +6 -3
|
@@ -3,6 +3,9 @@ export declare class StdioInput extends Transform {
|
|
|
3
3
|
private readonly maxLineBytes;
|
|
4
4
|
private lineBytes;
|
|
5
5
|
private trailingHighSurrogate;
|
|
6
|
+
private readonly decoder;
|
|
6
7
|
constructor(maxLineBytes: number);
|
|
7
8
|
_transform(chunk: Buffer | string, _encoding: BufferEncoding, callback: TransformCallback): void;
|
|
9
|
+
_flush(callback: TransformCallback): void;
|
|
10
|
+
private pushSegment;
|
|
8
11
|
}
|
|
@@ -3,43 +3,65 @@ export class StdioInput extends Transform {
|
|
|
3
3
|
maxLineBytes;
|
|
4
4
|
lineBytes = 0;
|
|
5
5
|
trailingHighSurrogate = false;
|
|
6
|
+
decoder = new TextDecoder("utf-8", { fatal: true });
|
|
6
7
|
constructor(maxLineBytes) {
|
|
7
8
|
super({ decodeStrings: false, readableObjectMode: true });
|
|
8
9
|
this.maxLineBytes = maxLineBytes;
|
|
9
10
|
}
|
|
10
11
|
_transform(chunk, _encoding, callback) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let start = 0;
|
|
15
|
-
for (let index = 0; index < chunk.length; index++) {
|
|
16
|
-
const unit = text ? chunk.charCodeAt(index) : chunk[index];
|
|
17
|
-
if (unit === 10 || unit === 13) {
|
|
18
|
-
this.lineBytes = 0;
|
|
12
|
+
try {
|
|
13
|
+
const text = typeof chunk === "string";
|
|
14
|
+
if (!text)
|
|
19
15
|
this.trailingHighSurrogate = false;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
let start = 0;
|
|
17
|
+
for (let index = 0; index < chunk.length; index++) {
|
|
18
|
+
const unit = text ? chunk.charCodeAt(index) : chunk[index];
|
|
19
|
+
if (unit === 10 || unit === 13) {
|
|
20
|
+
this.lineBytes = 0;
|
|
21
|
+
this.trailingHighSurrogate = false;
|
|
22
|
+
this.pushSegment(text ? chunk.slice(start, index + 1) : chunk.subarray(start, index + 1));
|
|
23
|
+
start = index + 1;
|
|
24
|
+
if (this.destroyed) {
|
|
25
|
+
callback();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (text) {
|
|
31
|
+
const lowSurrogate = unit >= 0xdc00 && unit <= 0xdfff;
|
|
32
|
+
this.lineBytes += this.trailingHighSurrogate && lowSurrogate ? 1 : unit <= 0x7f ? 1 : unit <= 0x7ff ? 2 : 3;
|
|
33
|
+
this.trailingHighSurrogate = unit >= 0xd800 && unit <= 0xdbff;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.lineBytes++;
|
|
37
|
+
}
|
|
38
|
+
if (this.lineBytes > this.maxLineBytes) {
|
|
39
|
+
callback(new Error("Stdio input line byte limit exceeded"));
|
|
24
40
|
return;
|
|
25
41
|
}
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (text) {
|
|
29
|
-
const lowSurrogate = unit >= 0xdc00 && unit <= 0xdfff;
|
|
30
|
-
this.lineBytes += this.trailingHighSurrogate && lowSurrogate ? 1 : unit <= 0x7f ? 1 : unit <= 0x7ff ? 2 : 3;
|
|
31
|
-
this.trailingHighSurrogate = unit >= 0xd800 && unit <= 0xdbff;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.lineBytes++;
|
|
35
|
-
}
|
|
36
|
-
if (this.lineBytes > this.maxLineBytes) {
|
|
37
|
-
callback(new Error("Stdio input line byte limit exceeded"));
|
|
38
|
-
return;
|
|
39
42
|
}
|
|
43
|
+
if (start < chunk.length)
|
|
44
|
+
this.pushSegment(text ? chunk.slice(start) : chunk.subarray(start));
|
|
45
|
+
callback();
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
catch (error) {
|
|
48
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
_flush(callback) {
|
|
52
|
+
try {
|
|
53
|
+
this.decoder.decode();
|
|
54
|
+
callback();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
pushSegment(segment) {
|
|
61
|
+
if (typeof segment === "string")
|
|
62
|
+
this.decoder.decode();
|
|
63
|
+
else
|
|
64
|
+
this.decoder.decode(segment, { stream: true });
|
|
65
|
+
this.push(segment);
|
|
44
66
|
}
|
|
45
67
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HandleResult, type JSONRPCNotification } from "./types.js";
|
|
2
|
+
export declare class SubscriptionRegistry {
|
|
3
|
+
private readonly listener;
|
|
4
|
+
private readonly supportNotifications;
|
|
5
|
+
private readonly supportResourceSubscriptions;
|
|
6
|
+
private readonly subscriptions;
|
|
7
|
+
constructor(listener: (notification: JSONRPCNotification) => void | Promise<void>, supportNotifications: boolean, supportResourceSubscriptions: boolean);
|
|
8
|
+
get size(): number;
|
|
9
|
+
listen(id: string | number | undefined, value: unknown, signal: AbortSignal): Promise<HandleResult>;
|
|
10
|
+
emit(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { isValidUri } from "./uri.js";
|
|
2
|
+
import { JSON_RPC_ERROR_CODES } from "./types.js";
|
|
3
|
+
const listNotifications = {
|
|
4
|
+
"notifications/tools/list_changed": "toolsListChanged",
|
|
5
|
+
"notifications/prompts/list_changed": "promptsListChanged",
|
|
6
|
+
"notifications/resources/list_changed": "resourcesListChanged"
|
|
7
|
+
};
|
|
8
|
+
export class SubscriptionRegistry {
|
|
9
|
+
listener;
|
|
10
|
+
supportNotifications;
|
|
11
|
+
supportResourceSubscriptions;
|
|
12
|
+
subscriptions = new Map();
|
|
13
|
+
constructor(listener, supportNotifications, supportResourceSubscriptions) {
|
|
14
|
+
this.listener = listener;
|
|
15
|
+
this.supportNotifications = supportNotifications;
|
|
16
|
+
this.supportResourceSubscriptions = supportResourceSubscriptions;
|
|
17
|
+
}
|
|
18
|
+
get size() {
|
|
19
|
+
return this.subscriptions.size;
|
|
20
|
+
}
|
|
21
|
+
async listen(id, value, signal) {
|
|
22
|
+
if (id === undefined || (typeof id === "number" && !Number.isSafeInteger(id))) {
|
|
23
|
+
return {
|
|
24
|
+
error: {
|
|
25
|
+
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
26
|
+
message: "subscriptions/listen requires a request ID"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
31
|
+
return {
|
|
32
|
+
error: {
|
|
33
|
+
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
34
|
+
message: "Subscription notifications must be an object"
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const requested = value;
|
|
39
|
+
const filter = {};
|
|
40
|
+
for (const field of Object.values(listNotifications)) {
|
|
41
|
+
if (requested[field] !== undefined && typeof requested[field] !== "boolean") {
|
|
42
|
+
return {
|
|
43
|
+
error: {
|
|
44
|
+
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
45
|
+
message: `${field} must be a boolean`
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (this.supportNotifications && requested[field] === true)
|
|
50
|
+
filter[field] = true;
|
|
51
|
+
}
|
|
52
|
+
const uris = requested.resourceSubscriptions;
|
|
53
|
+
if (uris !== undefined) {
|
|
54
|
+
if (!Array.isArray(uris) || uris.length > 1024 || !uris.every((uri) => {
|
|
55
|
+
if (typeof uri !== "string" || uri.length > 8192)
|
|
56
|
+
return false;
|
|
57
|
+
return isValidUri(uri);
|
|
58
|
+
})) {
|
|
59
|
+
return {
|
|
60
|
+
error: {
|
|
61
|
+
code: JSON_RPC_ERROR_CODES.INVALID_PARAMS,
|
|
62
|
+
message: "resourceSubscriptions must contain at most 1024 absolute URIs of at most 8192 characters"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (this.supportResourceSubscriptions)
|
|
67
|
+
filter.resourceSubscriptions = [...new Set(uris)];
|
|
68
|
+
}
|
|
69
|
+
if (signal.aborted)
|
|
70
|
+
return { result: undefined };
|
|
71
|
+
let resolve;
|
|
72
|
+
const completed = new Promise((complete) => {
|
|
73
|
+
resolve = complete;
|
|
74
|
+
});
|
|
75
|
+
const entry = {
|
|
76
|
+
filter,
|
|
77
|
+
resourceUris: new Set(Array.isArray(filter.resourceSubscriptions) ? filter.resourceSubscriptions : []),
|
|
78
|
+
ready: false,
|
|
79
|
+
finish: () => {
|
|
80
|
+
signal.removeEventListener("abort", entry.finish);
|
|
81
|
+
if (this.subscriptions.get(id) === entry)
|
|
82
|
+
this.subscriptions.delete(id);
|
|
83
|
+
resolve({ result: undefined });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this.subscriptions.set(id, entry);
|
|
87
|
+
signal.addEventListener("abort", entry.finish, { once: true });
|
|
88
|
+
try {
|
|
89
|
+
await this.listener({
|
|
90
|
+
jsonrpc: "2.0",
|
|
91
|
+
method: "notifications/subscriptions/acknowledged",
|
|
92
|
+
params: {
|
|
93
|
+
_meta: { "io.modelcontextprotocol/subscriptionId": id },
|
|
94
|
+
notifications: structuredClone(filter)
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
if (!signal.aborted)
|
|
98
|
+
entry.ready = true;
|
|
99
|
+
return await completed;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
entry.finish();
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async emit(method, params) {
|
|
107
|
+
await Promise.all([...this.subscriptions].map(async ([id, entry]) => {
|
|
108
|
+
if (!entry.ready)
|
|
109
|
+
return;
|
|
110
|
+
const field = listNotifications[method];
|
|
111
|
+
const selected = field !== undefined
|
|
112
|
+
? entry.filter[field] === true
|
|
113
|
+
: method === "notifications/resources/updated" &&
|
|
114
|
+
typeof params?.uri === "string" &&
|
|
115
|
+
entry.resourceUris.has(params.uri);
|
|
116
|
+
if (!selected)
|
|
117
|
+
return;
|
|
118
|
+
await this.listener({
|
|
119
|
+
jsonrpc: "2.0",
|
|
120
|
+
method,
|
|
121
|
+
params: {
|
|
122
|
+
...params,
|
|
123
|
+
_meta: { "io.modelcontextprotocol/subscriptionId": id }
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -22,6 +22,7 @@ export declare const JSON_RPC_ERROR_CODES: Readonly<{
|
|
|
22
22
|
readonly INVALID_PARAMS: -32602;
|
|
23
23
|
readonly INTERNAL_ERROR: -32603;
|
|
24
24
|
readonly RESOURCE_NOT_FOUND: -32002;
|
|
25
|
+
readonly UNSUPPORTED_PROTOCOL_VERSION: -32022;
|
|
25
26
|
}>;
|
|
26
27
|
export declare class ToolError extends Error {
|
|
27
28
|
readonly code: number;
|
|
@@ -38,24 +39,40 @@ export interface ResourcesCapability {
|
|
|
38
39
|
subscribe?: boolean;
|
|
39
40
|
listChanged?: boolean;
|
|
40
41
|
}
|
|
42
|
+
export interface Implementation {
|
|
43
|
+
name: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
version: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
websiteUrl?: string;
|
|
48
|
+
icons?: Icon[];
|
|
49
|
+
}
|
|
41
50
|
export interface InitializeResult {
|
|
42
51
|
protocolVersion: string;
|
|
43
52
|
capabilities: {
|
|
53
|
+
extensions?: Record<string, Record<string, unknown>>;
|
|
44
54
|
tools?: ToolsCapability;
|
|
45
55
|
prompts?: PromptsCapability;
|
|
46
56
|
resources?: ResourcesCapability;
|
|
47
57
|
};
|
|
48
|
-
serverInfo:
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
serverInfo: Implementation;
|
|
59
|
+
}
|
|
60
|
+
export interface DiscoverResult {
|
|
61
|
+
resultType: "complete";
|
|
62
|
+
supportedVersions: string[];
|
|
63
|
+
capabilities: InitializeResult["capabilities"];
|
|
64
|
+
_meta: {
|
|
65
|
+
"io.modelcontextprotocol/serverInfo": InitializeResult["serverInfo"];
|
|
51
66
|
};
|
|
67
|
+
ttlMs: number;
|
|
68
|
+
cacheScope: "public" | "private";
|
|
52
69
|
}
|
|
53
70
|
export interface Tool {
|
|
54
71
|
name: string;
|
|
55
72
|
title?: string;
|
|
56
73
|
description?: string;
|
|
57
74
|
inputSchema: JSONSchema;
|
|
58
|
-
outputSchema?:
|
|
75
|
+
outputSchema?: OutputSchema;
|
|
59
76
|
annotations?: ToolAnnotations;
|
|
60
77
|
execution?: ToolExecution;
|
|
61
78
|
icons?: Icon[];
|
|
@@ -63,7 +80,7 @@ export interface Tool {
|
|
|
63
80
|
}
|
|
64
81
|
export interface CallToolResult {
|
|
65
82
|
content: ContentItem[];
|
|
66
|
-
structuredContent?:
|
|
83
|
+
structuredContent?: unknown;
|
|
67
84
|
isError?: boolean;
|
|
68
85
|
}
|
|
69
86
|
export interface ToolAnnotations {
|
|
@@ -87,18 +104,12 @@ export interface ContentAnnotations {
|
|
|
87
104
|
priority?: number;
|
|
88
105
|
lastModified?: string;
|
|
89
106
|
}
|
|
90
|
-
export interface ResourceLink {
|
|
107
|
+
export interface ResourceLink extends Resource {
|
|
91
108
|
type: "resource_link";
|
|
92
|
-
uri: string;
|
|
93
|
-
name: string;
|
|
94
|
-
title?: string;
|
|
95
|
-
description?: string;
|
|
96
|
-
mimeType?: string;
|
|
97
|
-
size?: number;
|
|
98
|
-
annotations?: ContentAnnotations;
|
|
99
109
|
}
|
|
100
110
|
export interface PromptArgument {
|
|
101
111
|
name: string;
|
|
112
|
+
title?: string;
|
|
102
113
|
description?: string;
|
|
103
114
|
required?: boolean;
|
|
104
115
|
}
|
|
@@ -112,13 +123,13 @@ export interface Prompt {
|
|
|
112
123
|
}
|
|
113
124
|
export interface PromptMessage {
|
|
114
125
|
role: "user" | "assistant";
|
|
115
|
-
content:
|
|
126
|
+
content: ContentItem;
|
|
116
127
|
}
|
|
117
128
|
export interface GetPromptResult {
|
|
118
129
|
description?: string;
|
|
119
130
|
messages: PromptMessage[];
|
|
120
131
|
}
|
|
121
|
-
export type PromptHandler = (args: Record<string, string
|
|
132
|
+
export type PromptHandler = (args: Record<string, string>, context: HandlerRequestContext) => Promise<GetPromptResult | InputRequiredResult> | GetPromptResult | InputRequiredResult;
|
|
122
133
|
export interface PromptDefinition extends Prompt {
|
|
123
134
|
handler: PromptHandler;
|
|
124
135
|
}
|
|
@@ -147,15 +158,17 @@ export type ResourceContents = {
|
|
|
147
158
|
uri: string;
|
|
148
159
|
mimeType?: string;
|
|
149
160
|
text: string;
|
|
161
|
+
_meta?: Record<string, unknown>;
|
|
150
162
|
} | {
|
|
151
163
|
uri: string;
|
|
152
164
|
mimeType?: string;
|
|
153
165
|
blob: string;
|
|
166
|
+
_meta?: Record<string, unknown>;
|
|
154
167
|
};
|
|
155
168
|
export interface ReadResourceResult {
|
|
156
169
|
contents: ResourceContents[];
|
|
157
170
|
}
|
|
158
|
-
export type ResourceHandler = (uri: string) => Promise<ReadResourceResult> | ReadResourceResult;
|
|
171
|
+
export type ResourceHandler = (uri: string, context: HandlerRequestContext) => Promise<ReadResourceResult | InputRequiredResult> | ReadResourceResult | InputRequiredResult;
|
|
159
172
|
export interface ResourceDefinition extends Resource {
|
|
160
173
|
handler: ResourceHandler;
|
|
161
174
|
}
|
|
@@ -170,27 +183,33 @@ export type PromptContentItem = {
|
|
|
170
183
|
type: "text";
|
|
171
184
|
text: string;
|
|
172
185
|
annotations?: ContentAnnotations;
|
|
186
|
+
_meta?: Record<string, unknown>;
|
|
173
187
|
} | {
|
|
174
188
|
type: "image";
|
|
175
189
|
data: string;
|
|
176
190
|
mimeType: string;
|
|
177
191
|
annotations?: ContentAnnotations;
|
|
192
|
+
_meta?: Record<string, unknown>;
|
|
178
193
|
} | {
|
|
179
194
|
type: "audio";
|
|
180
195
|
data: string;
|
|
181
196
|
mimeType: string;
|
|
182
197
|
annotations?: ContentAnnotations;
|
|
198
|
+
_meta?: Record<string, unknown>;
|
|
183
199
|
} | {
|
|
184
200
|
type: "resource";
|
|
185
201
|
annotations?: ContentAnnotations;
|
|
202
|
+
_meta?: Record<string, unknown>;
|
|
186
203
|
resource: {
|
|
187
204
|
uri: string;
|
|
188
205
|
mimeType?: string;
|
|
189
206
|
text: string;
|
|
207
|
+
_meta?: Record<string, unknown>;
|
|
190
208
|
} | {
|
|
191
209
|
uri: string;
|
|
192
210
|
mimeType?: string;
|
|
193
211
|
blob: string;
|
|
212
|
+
_meta?: Record<string, unknown>;
|
|
194
213
|
};
|
|
195
214
|
};
|
|
196
215
|
export type ContentItem = PromptContentItem | ResourceLink;
|
|
@@ -200,6 +219,10 @@ export interface JSONSchema {
|
|
|
200
219
|
required?: string[];
|
|
201
220
|
[keyword: string]: unknown;
|
|
202
221
|
}
|
|
222
|
+
export interface OutputSchema {
|
|
223
|
+
$schema?: string;
|
|
224
|
+
[keyword: string]: unknown;
|
|
225
|
+
}
|
|
203
226
|
export interface JSONSchemaProperty extends Record<string, unknown> {
|
|
204
227
|
type?: string | string[];
|
|
205
228
|
description?: string;
|
|
@@ -217,19 +240,36 @@ export interface ServerOptions {
|
|
|
217
240
|
maxStdioOutputBytes?: number;
|
|
218
241
|
/** Per-stdio-connection messages awaiting handler/output settlement; defaults to 128. */
|
|
219
242
|
maxPendingStdioMessages?: number;
|
|
243
|
+
/** Shared in-flight requests retained until their work settles; defaults to 128. */
|
|
244
|
+
maxActiveRequests?: number;
|
|
220
245
|
maxStdioLineBytes?: number;
|
|
221
246
|
validateToolArguments?: boolean;
|
|
222
247
|
supportNotifications?: boolean;
|
|
223
248
|
supportResourceSubscriptions?: boolean;
|
|
224
249
|
}
|
|
225
250
|
import type { ToolReturn } from "./content/index.js";
|
|
226
|
-
export
|
|
251
|
+
export interface InputRequiredResult {
|
|
252
|
+
resultType: "input_required";
|
|
253
|
+
inputRequests?: Record<string, {
|
|
254
|
+
method: "elicitation/create" | "sampling/createMessage" | "roots/list";
|
|
255
|
+
params?: Record<string, unknown>;
|
|
256
|
+
}>;
|
|
257
|
+
requestState?: string;
|
|
258
|
+
_meta?: Record<string, unknown>;
|
|
259
|
+
}
|
|
260
|
+
export interface HandlerRequestContext {
|
|
261
|
+
readonly signal: AbortSignal;
|
|
262
|
+
readonly requestState?: string;
|
|
263
|
+
readonly inputResponses?: Record<string, unknown>;
|
|
264
|
+
readonly clientCapabilities: Record<string, unknown>;
|
|
265
|
+
}
|
|
266
|
+
export type ToolHandler<T = Record<string, unknown>, TOut = ToolReturn> = (args: T, context: HandlerRequestContext) => Promise<TOut | CallToolResult | InputRequiredResult> | TOut | CallToolResult | InputRequiredResult;
|
|
227
267
|
export interface ToolDefinition<T = Record<string, unknown>, TOut = ToolReturn> {
|
|
228
268
|
name: string;
|
|
229
269
|
title?: string;
|
|
230
270
|
description?: string;
|
|
231
271
|
inputSchema: JSONSchema;
|
|
232
|
-
outputSchema?:
|
|
272
|
+
outputSchema?: OutputSchema;
|
|
233
273
|
annotations?: ToolAnnotations;
|
|
234
274
|
execution?: ToolExecution;
|
|
235
275
|
icons?: Icon[];
|
|
@@ -5,7 +5,8 @@ export const JSON_RPC_ERROR_CODES = Object.freeze({
|
|
|
5
5
|
METHOD_NOT_FOUND: -32601,
|
|
6
6
|
INVALID_PARAMS: -32602,
|
|
7
7
|
INTERNAL_ERROR: -32603,
|
|
8
|
-
RESOURCE_NOT_FOUND: -32002
|
|
8
|
+
RESOURCE_NOT_FOUND: -32002,
|
|
9
|
+
UNSUPPORTED_PROTOCOL_VERSION: -32022
|
|
9
10
|
});
|
|
10
11
|
export class ToolError extends Error {
|
|
11
12
|
code;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidUri(uri: string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const invalidUriCharacters = new Set(["\"", "<", ">", "\\", "^", "`", "{", "|", "}"]);
|
|
2
|
+
export function isValidUri(uri) {
|
|
3
|
+
for (let index = 0; index < uri.length; index++) {
|
|
4
|
+
const code = uri.charCodeAt(index);
|
|
5
|
+
if (code <= 0x20 || code >= 0x7f || invalidUriCharacters.has(uri[index]))
|
|
6
|
+
return false;
|
|
7
|
+
if (uri[index] === "%") {
|
|
8
|
+
if (index + 2 >= uri.length)
|
|
9
|
+
return false;
|
|
10
|
+
for (let offset = 1; offset <= 2; offset++) {
|
|
11
|
+
const digit = uri.charCodeAt(index + offset);
|
|
12
|
+
if (!((digit >= 0x30 && digit <= 0x39) || (digit >= 0x41 && digit <= 0x46) || (digit >= 0x61 && digit <= 0x66)))
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
index += 2;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = new URL(uri);
|
|
20
|
+
const openingBracket = uri.indexOf("[");
|
|
21
|
+
const closingBracket = uri.indexOf("]");
|
|
22
|
+
if (openingBracket !== -1 || closingBracket !== -1) {
|
|
23
|
+
const schemeEnd = uri.indexOf(":");
|
|
24
|
+
if (!uri.startsWith("//", schemeEnd + 1) || !parsed.hostname.startsWith("["))
|
|
25
|
+
return false;
|
|
26
|
+
const authorityStart = schemeEnd + 3;
|
|
27
|
+
let authorityEnd = authorityStart;
|
|
28
|
+
while (authorityEnd < uri.length && !"/?#".includes(uri[authorityEnd]))
|
|
29
|
+
authorityEnd++;
|
|
30
|
+
const authority = uri.slice(authorityStart, authorityEnd);
|
|
31
|
+
if (openingBracket !== authorityStart + authority.lastIndexOf("@") + 1 ||
|
|
32
|
+
closingBracket >= authorityEnd || uri.indexOf("[", openingBracket + 1) !== -1 ||
|
|
33
|
+
uri.indexOf("]", closingBracket + 1) !== -1)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
"./testing": {
|
|
21
21
|
"types": "./dist/testing.d.ts",
|
|
22
22
|
"import": "./dist/testing.js"
|
|
23
|
+
},
|
|
24
|
+
"./headers": {
|
|
25
|
+
"types": "./dist/headers.d.ts",
|
|
26
|
+
"import": "./dist/headers.js"
|
|
27
|
+
},
|
|
28
|
+
"./protocol": {
|
|
29
|
+
"types": "./dist/protocol.d.ts",
|
|
30
|
+
"import": "./dist/protocol.js"
|
|
23
31
|
}
|
|
24
32
|
},
|
|
25
33
|
"scripts": {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface DesignCommand {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
keys: readonly string[];
|
|
5
|
+
enabled?: () => boolean;
|
|
6
|
+
run: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createCommandRegistry(commands: readonly DesignCommand[]): {
|
|
9
|
+
dispatch(key: string): boolean;
|
|
10
|
+
list(): DesignCommand[];
|
|
11
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createCommandRegistry(commands) {
|
|
2
|
+
const bindings = new Map();
|
|
3
|
+
const ids = new Set();
|
|
4
|
+
for (const command of commands) {
|
|
5
|
+
if (ids.has(command.id))
|
|
6
|
+
throw new Error(`Duplicate command: ${command.id}`);
|
|
7
|
+
ids.add(command.id);
|
|
8
|
+
for (const key of command.keys) {
|
|
9
|
+
if (bindings.has(key))
|
|
10
|
+
throw new Error(`Duplicate binding: ${key}`);
|
|
11
|
+
bindings.set(key, command);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
dispatch(key) {
|
|
16
|
+
const command = bindings.get(key);
|
|
17
|
+
if (!command || command.enabled?.() === false)
|
|
18
|
+
return false;
|
|
19
|
+
command.run();
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
list() { return commands.filter(command => command.enabled?.() !== false); }
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -6,6 +6,8 @@ export interface StyledSegment {
|
|
|
6
6
|
export interface StyledLine {
|
|
7
7
|
segments: StyledSegment[];
|
|
8
8
|
}
|
|
9
|
+
/** Visible text for a plain screen row; styles are supplied by the caller. */
|
|
10
|
+
export declare function plainTerminalText(text: string): string;
|
|
9
11
|
export declare function hasAnsi(text: string): boolean;
|
|
10
12
|
/**
|
|
11
13
|
* Parse a block of text that may contain ANSI SGR escape codes into a sequence of
|