tmcp 1.16.2 → 1.16.4
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/package.json +1 -1
- package/src/index.js +33 -18
- package/src/internal/internal.d.ts +2 -1
- package/src/internal/utils.js +12 -0
- package/src/types/index.d.ts +2 -1
- package/src/types/index.d.ts.map +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
negotiate_protocol_version,
|
|
32
32
|
} from './validation/version.js';
|
|
33
33
|
import { should_version_negotiation_fail } from './validation/version.js';
|
|
34
|
+
import { event } from './internal/utils.js';
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Information about a validated access token, provided to request handlers.
|
|
@@ -248,9 +249,7 @@ export class McpServer {
|
|
|
248
249
|
|
|
249
250
|
// Dispatch initialization event
|
|
250
251
|
this.#event_target.dispatchEvent(
|
|
251
|
-
|
|
252
|
-
detail: validated_initialize,
|
|
253
|
-
}),
|
|
252
|
+
event('initialize', validated_initialize),
|
|
254
253
|
);
|
|
255
254
|
|
|
256
255
|
// Return server response with negotiated version and capabilities
|
|
@@ -352,16 +351,12 @@ export class McpServer {
|
|
|
352
351
|
this.#client = new JSONRPCClient((payload, kind) => {
|
|
353
352
|
if (kind === 'broadcast') {
|
|
354
353
|
this.#event_target.dispatchEvent(
|
|
355
|
-
|
|
356
|
-
detail: { request: payload },
|
|
357
|
-
}),
|
|
354
|
+
event('broadcast', { request: payload }),
|
|
358
355
|
);
|
|
359
356
|
return;
|
|
360
357
|
}
|
|
361
358
|
this.#event_target.dispatchEvent(
|
|
362
|
-
|
|
363
|
-
detail: { request: payload },
|
|
364
|
-
}),
|
|
359
|
+
event('send', { request: payload }),
|
|
365
360
|
);
|
|
366
361
|
});
|
|
367
362
|
}
|
|
@@ -406,8 +401,8 @@ export class McpServer {
|
|
|
406
401
|
*/
|
|
407
402
|
#init_tools() {
|
|
408
403
|
if (!this.#options.capabilities?.tools) return;
|
|
409
|
-
this.#server.addMethod('tools/list', async () => {
|
|
410
|
-
const
|
|
404
|
+
this.#server.addMethod('tools/list', async ({ cursor } = {}) => {
|
|
405
|
+
const all_tools = (
|
|
411
406
|
await Promise.all(
|
|
412
407
|
[...this.#tools].map(async ([name, tool]) => {
|
|
413
408
|
if (
|
|
@@ -444,8 +439,26 @@ export class McpServer {
|
|
|
444
439
|
}),
|
|
445
440
|
)
|
|
446
441
|
).filter((tool) => tool !== null);
|
|
442
|
+
|
|
443
|
+
const pagination_options = this.#options.pagination?.tools;
|
|
444
|
+
if (!pagination_options || pagination_options.size == null) {
|
|
445
|
+
return { tools: all_tools };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const page_length = pagination_options.size;
|
|
449
|
+
const offset = cursor ? await decode_cursor(cursor) : 0;
|
|
450
|
+
const start_index = offset;
|
|
451
|
+
const end_index = start_index + page_length;
|
|
452
|
+
|
|
453
|
+
const tools = all_tools.slice(start_index, end_index);
|
|
454
|
+
const has_next = end_index < all_tools.length;
|
|
455
|
+
const next_cursor = has_next
|
|
456
|
+
? await encode_cursor(end_index)
|
|
457
|
+
: null;
|
|
458
|
+
|
|
447
459
|
return {
|
|
448
|
-
tools
|
|
460
|
+
tools,
|
|
461
|
+
...(next_cursor && { nextCursor: next_cursor }),
|
|
449
462
|
};
|
|
450
463
|
});
|
|
451
464
|
this.#server.addMethod(
|
|
@@ -636,9 +649,13 @@ export class McpServer {
|
|
|
636
649
|
if (this.#options.capabilities?.resources?.subscribe) {
|
|
637
650
|
this.#server.addMethod('resources/subscribe', async ({ uri }) => {
|
|
638
651
|
this.#event_target.dispatchEvent(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
652
|
+
event('subscription', { uri, action: 'add' }),
|
|
653
|
+
);
|
|
654
|
+
return {};
|
|
655
|
+
});
|
|
656
|
+
this.#server.addMethod('resources/unsubscribe', async ({ uri }) => {
|
|
657
|
+
this.#event_target.dispatchEvent(
|
|
658
|
+
event('subscription', { uri, action: 'remove' }),
|
|
642
659
|
);
|
|
643
660
|
return {};
|
|
644
661
|
});
|
|
@@ -815,9 +832,7 @@ export class McpServer {
|
|
|
815
832
|
|
|
816
833
|
this.#server.addMethod('logging/setLevel', ({ level }) => {
|
|
817
834
|
this.#event_target.dispatchEvent(
|
|
818
|
-
|
|
819
|
-
detail: { level },
|
|
820
|
-
}),
|
|
835
|
+
event('loglevelchange', { level }),
|
|
821
836
|
);
|
|
822
837
|
return {};
|
|
823
838
|
});
|
|
@@ -73,6 +73,7 @@ export type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
|
73
73
|
instructions?: string;
|
|
74
74
|
adapter: JsonSchemaAdapter<TSchema> | undefined;
|
|
75
75
|
pagination?: {
|
|
76
|
+
tools?: { size?: number };
|
|
76
77
|
resources?: { size?: number };
|
|
77
78
|
prompts?: { size?: number };
|
|
78
79
|
};
|
|
@@ -102,6 +103,6 @@ export type McpEvents = {
|
|
|
102
103
|
request: JSONRPCRequest;
|
|
103
104
|
}) => void;
|
|
104
105
|
initialize: (initialize_request: InitializeRequestParams) => void;
|
|
105
|
-
subscription: (subscriptions_request: { uri: string }) => void;
|
|
106
|
+
subscription: (subscriptions_request: { uri: string, action?: "add" | "remove" }) => void;
|
|
106
107
|
loglevelchange: (change: { level: LoggingLevel }) => void;
|
|
107
108
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {McpEvents} from "./internal.js"
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @template {keyof McpEvents} Key
|
|
6
|
+
* @param {Key} type
|
|
7
|
+
* @param {Parameters<McpEvents[Key]>[0]} detail
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function event(type, detail) {
|
|
11
|
+
return new CustomEvent(type, { detail });
|
|
12
|
+
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -222,6 +222,7 @@ declare module 'tmcp' {
|
|
|
222
222
|
instructions?: string;
|
|
223
223
|
adapter: JsonSchemaAdapter<TSchema> | undefined;
|
|
224
224
|
pagination?: {
|
|
225
|
+
tools?: { size?: number };
|
|
225
226
|
resources?: { size?: number };
|
|
226
227
|
prompts?: { size?: number };
|
|
227
228
|
};
|
|
@@ -251,7 +252,7 @@ declare module 'tmcp' {
|
|
|
251
252
|
request: JSONRPCRequest;
|
|
252
253
|
}) => void;
|
|
253
254
|
initialize: (initialize_request: InitializeRequestParams) => void;
|
|
254
|
-
subscription: (subscriptions_request: { uri: string }) => void;
|
|
255
|
+
subscription: (subscriptions_request: { uri: string, action?: "add" | "remove" }) => void;
|
|
255
256
|
loglevelchange: (change: { level: LoggingLevel_1 }) => void;
|
|
256
257
|
};
|
|
257
258
|
const JSONRPCMessageSchema: v.UnionSchema<[v.ObjectSchema<{
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
null,
|
|
75
75
|
null
|
|
76
76
|
],
|
|
77
|
-
"mappings": ";;;;;
|
|
77
|
+
"mappings": ";;;;;cAiLaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aCg0CyBC,KAAKA;aDn7CFC,aAAaA;;aC08CHC,kBAAkBA;aAGrBC,eAAeA;aAvBZC,kBAAkBA;aAUKC,UAAUA;aAmBzBC,0BAA0BA;aAGjCC,mBAAmBA;aAY9BC,QAAQA;aAYJC,YAAYA;aAlDVC,UAAUA;aAwDZC,YAAYA;aAGRC,gBAAgBA;aAGjBC,eAAeA;aAGbC,iBAAiBA;aAMPC,2BAA2BA;aAHnCC,mBAAmBA;aAhDxBC,cAAcA;MCj/C1DC,UAAUA;;;;;MA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