tmcp 1.16.3 → 1.17.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 +40 -0
- package/package.json +1 -1
- package/src/index.js +32 -3
- package/src/internal/internal.d.ts +1 -0
- package/src/types/index.d.ts +10 -1
- package/src/types/index.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -293,6 +293,46 @@ const response = server.receive(jsonRpcRequest, {
|
|
|
293
293
|
});
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
+
##### `request({ method, params })`
|
|
297
|
+
|
|
298
|
+
Send a raw JSON-RPC request to the connected client. This lets you call
|
|
299
|
+
experimental MCP APIs or proprietary extensions before they gain a dedicated
|
|
300
|
+
method on `McpServer` or to send a request with a custom JSON-schema that is not expressible with your validation library.
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
const response = await server.request({
|
|
304
|
+
method: 'elicitation/create',
|
|
305
|
+
params: {
|
|
306
|
+
message: 'Describe the deployment plan',
|
|
307
|
+
requestedSchema: {
|
|
308
|
+
type: 'object',
|
|
309
|
+
required: ['region', 'replicas', 'features'],
|
|
310
|
+
properties: {
|
|
311
|
+
region: {
|
|
312
|
+
type: 'string',
|
|
313
|
+
enum: ['us-east-1', 'us-west-2', 'eu-central-1'],
|
|
314
|
+
},
|
|
315
|
+
replicas: { type: 'integer', minimum: 1, maximum: 20 },
|
|
316
|
+
features: {
|
|
317
|
+
type: 'array',
|
|
318
|
+
items: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
enum: ['canary', 'observability', 'autoscaling'],
|
|
321
|
+
},
|
|
322
|
+
minItems: 1,
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
- `method`: Fully qualified MCP client method name
|
|
331
|
+
- `params` (optional): JSON-RPC params object/array accepted by that method
|
|
332
|
+
|
|
333
|
+
Handle the resolved payload like any other JSON-RPC response—cast or (better) validate
|
|
334
|
+
as needed when using this escape hatch.
|
|
335
|
+
|
|
296
336
|
##### `elicitation(schema)`
|
|
297
337
|
|
|
298
338
|
Request client elicitation with schema validation.
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -401,8 +401,8 @@ export class McpServer {
|
|
|
401
401
|
*/
|
|
402
402
|
#init_tools() {
|
|
403
403
|
if (!this.#options.capabilities?.tools) return;
|
|
404
|
-
this.#server.addMethod('tools/list', async () => {
|
|
405
|
-
const
|
|
404
|
+
this.#server.addMethod('tools/list', async ({ cursor } = {}) => {
|
|
405
|
+
const all_tools = (
|
|
406
406
|
await Promise.all(
|
|
407
407
|
[...this.#tools].map(async ([name, tool]) => {
|
|
408
408
|
if (
|
|
@@ -439,8 +439,26 @@ export class McpServer {
|
|
|
439
439
|
}),
|
|
440
440
|
)
|
|
441
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
|
+
|
|
442
459
|
return {
|
|
443
|
-
tools
|
|
460
|
+
tools,
|
|
461
|
+
...(next_cursor && { nextCursor: next_cursor }),
|
|
444
462
|
};
|
|
445
463
|
});
|
|
446
464
|
this.#server.addMethod(
|
|
@@ -1011,6 +1029,17 @@ export class McpServer {
|
|
|
1011
1029
|
);
|
|
1012
1030
|
}
|
|
1013
1031
|
|
|
1032
|
+
/**
|
|
1033
|
+
* Lower level api to send a request to the client, mostly useful to call client methods that not yet supported by the server or
|
|
1034
|
+
* if you want to send requests with json schema that is not expressible with your validation library.
|
|
1035
|
+
* @param {{ method: string, params?: JSONRPCParams }} request
|
|
1036
|
+
* @returns {Promise<unknown>}
|
|
1037
|
+
*/
|
|
1038
|
+
async request({ method, params }) {
|
|
1039
|
+
this.#lazyily_create_client();
|
|
1040
|
+
return this.#client?.request(method, params, 'standalone');
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1014
1043
|
/**
|
|
1015
1044
|
* Send a notification for subscriptions
|
|
1016
1045
|
* @template {keyof ChangedArgs} TWhat
|
|
@@ -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
|
};
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare module 'tmcp' {
|
|
2
2
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
import type { JSONRPCServer, JSONRPCClient, JSONRPCRequest } from 'json-rpc-2.0';
|
|
3
|
+
import type { JSONRPCServer, JSONRPCClient, JSONRPCParams, JSONRPCRequest } from 'json-rpc-2.0';
|
|
4
4
|
import type { JSONSchema7 } from 'json-schema';
|
|
5
5
|
import * as v from 'valibot';
|
|
6
6
|
export class McpServer<StandardSchema extends StandardSchemaV1 | undefined = undefined, CustomContext extends Record<string, unknown> | undefined = undefined> {
|
|
@@ -113,6 +113,14 @@ declare module 'tmcp' {
|
|
|
113
113
|
*
|
|
114
114
|
* */
|
|
115
115
|
receive(message: JSONRPCMessage, ctx?: Context<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* Lower level api to send a request to the client, mostly useful to call client methods that not yet supported by the server or
|
|
118
|
+
* if you want to send requests with json schema that is not expressible with your validation library.
|
|
119
|
+
* */
|
|
120
|
+
request({ method, params }: {
|
|
121
|
+
method: string;
|
|
122
|
+
params?: JSONRPCParams;
|
|
123
|
+
}): Promise<unknown>;
|
|
116
124
|
/**
|
|
117
125
|
* Send a notification for subscriptions
|
|
118
126
|
* */
|
|
@@ -222,6 +230,7 @@ declare module 'tmcp' {
|
|
|
222
230
|
instructions?: string;
|
|
223
231
|
adapter: JsonSchemaAdapter<TSchema> | undefined;
|
|
224
232
|
pagination?: {
|
|
233
|
+
tools?: { size?: number };
|
|
225
234
|
resources?: { size?: number };
|
|
226
235
|
prompts?: { size?: number };
|
|
227
236
|
};
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
null,
|
|
75
75
|
null
|
|
76
76
|
],
|
|
77
|
-
"mappings": ";;;;;cAiLaA,SAASA
|
|
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/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