tmcp 1.10.3 → 1.11.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/package.json +1 -1
- package/src/index.js +23 -6
- package/src/internal/internal.d.ts +1 -1
- package/src/types/index.d.ts +14 -7
- package/src/types/index.d.ts.map +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/no-undefined-types */
|
|
1
2
|
/**
|
|
2
3
|
* @import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
4
|
* @import SqidsType from "sqids";
|
|
@@ -43,9 +44,11 @@ import { should_version_negotiation_fail } from './validation/version.js';
|
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
46
|
/**
|
|
47
|
+
* @template {Record<string, unknown> | undefined} [TCustom=undefined]
|
|
46
48
|
* @typedef {Object} Context
|
|
47
49
|
* @property {string} [sessionId]
|
|
48
50
|
* @property {AuthInfo} [auth]
|
|
51
|
+
* @property {TCustom} [custom]
|
|
49
52
|
*/
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -93,7 +96,8 @@ async function safe_enabled(enabled) {
|
|
|
93
96
|
*/
|
|
94
97
|
|
|
95
98
|
/**
|
|
96
|
-
* @template {StandardSchemaV1} StandardSchema
|
|
99
|
+
* @template {StandardSchemaV1 | undefined} [StandardSchema=undefined]
|
|
100
|
+
* @template {Record<string, unknown> | undefined} [CustomContext=undefined]
|
|
97
101
|
*/
|
|
98
102
|
export class McpServer {
|
|
99
103
|
#server = new JSONRPCServer();
|
|
@@ -140,7 +144,7 @@ export class McpServer {
|
|
|
140
144
|
};
|
|
141
145
|
|
|
142
146
|
/**
|
|
143
|
-
* @type {AsyncLocalStorage<Context & { progress_token?: string }>}
|
|
147
|
+
* @type {AsyncLocalStorage<Context<CustomContext> & { progress_token?: string }>}
|
|
144
148
|
*/
|
|
145
149
|
#ctx_storage = new AsyncLocalStorage();
|
|
146
150
|
|
|
@@ -276,6 +280,19 @@ export class McpServer {
|
|
|
276
280
|
this.#init_logging();
|
|
277
281
|
}
|
|
278
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Utility method to specify the type of the custom context for this server instance without the need to specify the standard schema type.
|
|
285
|
+
* @example
|
|
286
|
+
* const server = new McpServer({ ... }, { ... }).withContext<{ name: string }>();
|
|
287
|
+
* @template {Record<string, unknown>} TCustom
|
|
288
|
+
* @returns {McpServer<StandardSchema, TCustom>}
|
|
289
|
+
*/
|
|
290
|
+
withContext() {
|
|
291
|
+
return /** @type {McpServer<StandardSchema, TCustom>} */ (
|
|
292
|
+
/** @type {unknown} */ (this)
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
279
296
|
get #session_id() {
|
|
280
297
|
return this.#ctx_storage.getStore()?.sessionId;
|
|
281
298
|
}
|
|
@@ -285,8 +302,8 @@ export class McpServer {
|
|
|
285
302
|
}
|
|
286
303
|
|
|
287
304
|
/**
|
|
288
|
-
* The context of the current request, include the session ID
|
|
289
|
-
* @type {Context}
|
|
305
|
+
* The context of the current request, include the session ID, any auth information, and custom data.
|
|
306
|
+
* @type {Context<CustomContext>}
|
|
290
307
|
*/
|
|
291
308
|
get ctx() {
|
|
292
309
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -877,7 +894,7 @@ export class McpServer {
|
|
|
877
894
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
878
895
|
*
|
|
879
896
|
* @param {JSONRPCResponse | JSONRPCRequest} message
|
|
880
|
-
* @param {Context} [ctx]
|
|
897
|
+
* @param {Context<CustomContext>} [ctx]
|
|
881
898
|
* @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
|
|
882
899
|
*/
|
|
883
900
|
receive(message, ctx) {
|
|
@@ -955,7 +972,7 @@ export class McpServer {
|
|
|
955
972
|
*
|
|
956
973
|
* If the client doesn't support elicitation, it will throw an error.
|
|
957
974
|
*
|
|
958
|
-
* @template {StandardSchema} TSchema
|
|
975
|
+
* @template {StandardSchema extends undefined ? never : StandardSchema} TSchema
|
|
959
976
|
* @param {TSchema} schema
|
|
960
977
|
* @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
|
|
961
978
|
*/
|
|
@@ -66,7 +66,7 @@ export type StoredResource =
|
|
|
66
66
|
) => Promise<ReadResourceResult> | ReadResourceResult;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
export type ServerOptions<TSchema extends StandardSchemaV1> = {
|
|
69
|
+
export type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
70
70
|
capabilities?: ServerCapabilities;
|
|
71
71
|
instructions?: string;
|
|
72
72
|
adapter: JsonSchemaAdapter<TSchema>;
|
package/src/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare module 'tmcp' {
|
|
|
3
3
|
import type { JSONRPCRequest, JSONRPCServer, JSONRPCClient } from 'json-rpc-2.0';
|
|
4
4
|
import type { JSONSchema7 } from 'json-schema';
|
|
5
5
|
import * as v from 'valibot';
|
|
6
|
-
export class McpServer<StandardSchema extends StandardSchemaV1> {
|
|
6
|
+
export class McpServer<StandardSchema extends StandardSchemaV1 | undefined = undefined, CustomContext extends Record<string, unknown> | undefined = undefined> {
|
|
7
7
|
|
|
8
8
|
constructor(server_info: ServerInfo, options: ServerOptions<StandardSchema>);
|
|
9
9
|
|
|
@@ -12,9 +12,15 @@ declare module 'tmcp' {
|
|
|
12
12
|
name?: string;
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Utility method to specify the type of the custom context for this server instance without the need to specify the standard schema type.
|
|
16
|
+
* @example
|
|
17
|
+
* const server = new McpServer({ ... }, { ... }).withContext<{ name: string }>();
|
|
16
18
|
* */
|
|
17
|
-
|
|
19
|
+
withContext<TCustom extends Record<string, unknown>>(): McpServer<StandardSchema, TCustom>;
|
|
20
|
+
/**
|
|
21
|
+
* The context of the current request, include the session ID, any auth information, and custom data.
|
|
22
|
+
* */
|
|
23
|
+
get ctx(): Context<CustomContext>;
|
|
18
24
|
/**
|
|
19
25
|
* Get the client information (name, version, etc.) of the client that initiated the current request...useful if you want to do something different based on the client.
|
|
20
26
|
*/
|
|
@@ -97,7 +103,7 @@ declare module 'tmcp' {
|
|
|
97
103
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
98
104
|
*
|
|
99
105
|
* */
|
|
100
|
-
receive(message: JSONRPCResponse | JSONRPCRequest, ctx?: Context): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
|
|
106
|
+
receive(message: JSONRPCResponse | JSONRPCRequest, ctx?: Context<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
|
|
101
107
|
/**
|
|
102
108
|
* Send a notification for subscriptions
|
|
103
109
|
* */
|
|
@@ -114,7 +120,7 @@ declare module 'tmcp' {
|
|
|
114
120
|
* If the client doesn't support elicitation, it will throw an error.
|
|
115
121
|
*
|
|
116
122
|
* */
|
|
117
|
-
elicitation<TSchema extends StandardSchema>(schema: TSchema): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
123
|
+
elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(schema: TSchema): Promise<StandardSchemaV1.InferOutput<TSchema>>;
|
|
118
124
|
/**
|
|
119
125
|
* Request language model sampling from the client
|
|
120
126
|
* */
|
|
@@ -166,9 +172,10 @@ declare module 'tmcp' {
|
|
|
166
172
|
*/
|
|
167
173
|
extra?: Record<string, unknown> | undefined;
|
|
168
174
|
};
|
|
169
|
-
export type Context = {
|
|
175
|
+
export type Context<TCustom extends Record<string, unknown> | undefined = undefined> = {
|
|
170
176
|
sessionId?: string | undefined;
|
|
171
177
|
auth?: AuthInfo | undefined;
|
|
178
|
+
custom?: TCustom | undefined;
|
|
172
179
|
};
|
|
173
180
|
export type ClientCapabilities = ClientCapabilities_1;
|
|
174
181
|
type Completion = (
|
|
@@ -176,7 +183,7 @@ declare module 'tmcp' {
|
|
|
176
183
|
context: { arguments: Record<string, string> },
|
|
177
184
|
) => CompleteResult | Promise<CompleteResult>;
|
|
178
185
|
|
|
179
|
-
type ServerOptions<TSchema extends StandardSchemaV1> = {
|
|
186
|
+
type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
180
187
|
capabilities?: ServerCapabilities;
|
|
181
188
|
instructions?: string;
|
|
182
189
|
adapter: JsonSchemaAdapter<TSchema>;
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
null,
|
|
56
56
|
null
|
|
57
57
|
],
|
|
58
|
-
"mappings": ";;;;;
|
|
58
|
+
"mappings": ";;;;;cAqGaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aCk2CsCC,kBAAkBA;MC56ClEC,UAAUA;;;;;MAyCVC,aAAaA;;;;;;;;;;;;;MAabC,UAAUA;;;;;;MAMVC,iBAAiBA;;MAEjBC,SAASA;;;;;;;;;;;;ODWRC,qBAAqBA;;;;;;;;;;;;;;OAuGrBC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;OA6BxBC,6BAA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuB7BC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmMxBC,cAAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4GdC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8PxBC,qBAAqBA;;;;;;;;;;;;;;;;;;;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