tmcp 1.16.0 → 1.16.1
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 +8 -1
- package/package.json +1 -1
- package/src/index.js +21 -19
- package/src/internal/internal.d.ts +1 -1
- package/src/types/index.d.ts +45 -9
- package/src/types/index.d.ts.map +3 -3
- package/src/validation/index.js +3 -0
package/README.md
CHANGED
|
@@ -57,6 +57,10 @@ const server = new McpServer(
|
|
|
57
57
|
},
|
|
58
58
|
);
|
|
59
59
|
|
|
60
|
+
// While the adapter is optional (you can opt out by explicitly passing `adapter: undefined`)
|
|
61
|
+
// without an adapter the server cannot accept inputs, produce structured outputs, or request
|
|
62
|
+
// elicitations at all only do this for very simple servers.
|
|
63
|
+
|
|
60
64
|
// Define a tool with type-safe schema
|
|
61
65
|
server.tool(
|
|
62
66
|
{
|
|
@@ -107,7 +111,10 @@ new McpServer(serverInfo, options);
|
|
|
107
111
|
```
|
|
108
112
|
|
|
109
113
|
- `serverInfo`: Server metadata (name, version, description)
|
|
110
|
-
- `options`: Configuration object with adapter and capabilities
|
|
114
|
+
- `options`: Configuration object with optional adapter (for schema conversion) and capabilities
|
|
115
|
+
|
|
116
|
+
> [!IMPORTANT]
|
|
117
|
+
> While the adapter is optional (you can opt out by explicitly passing `adapter: undefined`) without an adapter the server cannot accept inputs, produce structured outputs, or request elicitations at all only do this for very simple servers.
|
|
111
118
|
|
|
112
119
|
#### Methods
|
|
113
120
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @import SqidsType from "sqids";
|
|
5
5
|
* @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
|
|
6
6
|
* @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
|
|
7
|
-
* @import { CallToolResult as CallToolResultType, ReadResourceResult as ReadResourceResultType, GetPromptResult as GetPromptResultType, ServerInfo as ServerInfoType, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams as CreateMessageRequestParamsType, CreateMessageResult as CreateMessageResultType, Resource as ResourceType, LoggingLevel as LoggingLevelType, ToolAnnotations, ClientInfo as ClientInfoType, ElicitResult as ElicitResultType, Icons as IconsType } from "./validation/index.js";
|
|
7
|
+
* @import { CallToolResult as CallToolResultType, ReadResourceResult as ReadResourceResultType, GetPromptResult as GetPromptResultType, ServerInfo as ServerInfoType, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams as CreateMessageRequestParamsType, CreateMessageResult as CreateMessageResultType, Resource as ResourceType, LoggingLevel as LoggingLevelType, ToolAnnotations, ClientInfo as ClientInfoType, ElicitResult as ElicitResultType, Icons as IconsType, JSONRPCMessage } from "./validation/index.js";
|
|
8
8
|
* @import { Tool, Completion, Prompt, StoredResource, ServerOptions, SubscriptionsKeys, ChangedArgs, McpEvents } from "./internal/internal.js";
|
|
9
9
|
*/
|
|
10
10
|
import { JSONRPCClient, JSONRPCServer } from 'json-rpc-2.0';
|
|
@@ -398,12 +398,13 @@ export class McpServer {
|
|
|
398
398
|
description: tool.description,
|
|
399
399
|
icons: tool.icons,
|
|
400
400
|
_meta: tool._meta,
|
|
401
|
-
inputSchema:
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
401
|
+
inputSchema:
|
|
402
|
+
tool.schema && this.#options.adapter
|
|
403
|
+
? await this.#options.adapter.toJsonSchema(
|
|
404
|
+
tool.schema,
|
|
405
|
+
)
|
|
406
|
+
: { type: 'object', properties: {} },
|
|
407
|
+
...(tool.outputSchema && this.#options.adapter
|
|
407
408
|
? {
|
|
408
409
|
outputSchema:
|
|
409
410
|
await this.#options.adapter.toJsonSchema(
|
|
@@ -515,16 +516,17 @@ export class McpServer {
|
|
|
515
516
|
(await safe_enabled(prompt.enabled)) === false
|
|
516
517
|
)
|
|
517
518
|
return null;
|
|
518
|
-
const arguments_schema =
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
519
|
+
const arguments_schema =
|
|
520
|
+
prompt.schema && this.#options.adapter
|
|
521
|
+
? await this.#options.adapter.toJsonSchema(
|
|
522
|
+
prompt.schema,
|
|
523
|
+
)
|
|
524
|
+
: {
|
|
525
|
+
type: 'object',
|
|
526
|
+
properties:
|
|
527
|
+
/** @type {Record<string, {description: string}>} */ ({}),
|
|
528
|
+
required: [],
|
|
529
|
+
};
|
|
528
530
|
const keys = Object.keys(
|
|
529
531
|
arguments_schema.properties ?? {},
|
|
530
532
|
);
|
|
@@ -956,7 +958,7 @@ export class McpServer {
|
|
|
956
958
|
/**
|
|
957
959
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
958
960
|
*
|
|
959
|
-
* @param {
|
|
961
|
+
* @param {JSONRPCMessage} message
|
|
960
962
|
* @param {Context<CustomContext>} [ctx]
|
|
961
963
|
* @returns {ReturnType<JSONRPCServer['receive']> | ReturnType<JSONRPCClient['receive'] | undefined>}
|
|
962
964
|
*/
|
|
@@ -1045,7 +1047,7 @@ export class McpServer {
|
|
|
1045
1047
|
{
|
|
1046
1048
|
message,
|
|
1047
1049
|
requestedSchema:
|
|
1048
|
-
await this.#options.adapter
|
|
1050
|
+
await this.#options.adapter?.toJsonSchema(schema),
|
|
1049
1051
|
},
|
|
1050
1052
|
'standalone',
|
|
1051
1053
|
);
|
|
@@ -71,7 +71,7 @@ export type StoredResource =
|
|
|
71
71
|
export type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
72
72
|
capabilities?: ServerCapabilities;
|
|
73
73
|
instructions?: string;
|
|
74
|
-
adapter: JsonSchemaAdapter<TSchema
|
|
74
|
+
adapter: JsonSchemaAdapter<TSchema> | undefined;
|
|
75
75
|
pagination?: {
|
|
76
76
|
resources?: { size?: number };
|
|
77
77
|
prompts?: { size?: number };
|
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 {
|
|
3
|
+
import type { JSONRPCServer, JSONRPCClient, 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> {
|
|
@@ -112,7 +112,7 @@ declare module 'tmcp' {
|
|
|
112
112
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
113
113
|
*
|
|
114
114
|
* */
|
|
115
|
-
receive(message:
|
|
115
|
+
receive(message: JSONRPCMessage, ctx?: Context<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
|
|
116
116
|
/**
|
|
117
117
|
* Send a notification for subscriptions
|
|
118
118
|
* */
|
|
@@ -214,7 +214,7 @@ declare module 'tmcp' {
|
|
|
214
214
|
type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
|
|
215
215
|
capabilities?: ServerCapabilities;
|
|
216
216
|
instructions?: string;
|
|
217
|
-
adapter: JsonSchemaAdapter<TSchema
|
|
217
|
+
adapter: JsonSchemaAdapter<TSchema> | undefined;
|
|
218
218
|
pagination?: {
|
|
219
219
|
resources?: { size?: number };
|
|
220
220
|
prompts?: { size?: number };
|
|
@@ -248,10 +248,29 @@ declare module 'tmcp' {
|
|
|
248
248
|
subscription: (subscriptions_request: { uri: string }) => void;
|
|
249
249
|
loglevelchange: (change: { level: LoggingLevel_1 }) => void;
|
|
250
250
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
251
|
+
const JSONRPCMessageSchema: v.UnionSchema<[v.ObjectSchema<{
|
|
252
|
+
readonly method: v.StringSchema<undefined>;
|
|
253
|
+
readonly params: v.OptionalSchema<v.LooseObjectSchema<{
|
|
254
|
+
readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{
|
|
255
|
+
/**
|
|
256
|
+
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
257
|
+
*/
|
|
258
|
+
readonly progressToken: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>, undefined>;
|
|
259
|
+
}, undefined>, undefined>;
|
|
260
|
+
}, undefined>, undefined>;
|
|
261
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
262
|
+
readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
|
|
263
|
+
}, undefined>, v.ObjectSchema<{
|
|
264
|
+
readonly method: v.StringSchema<undefined>;
|
|
265
|
+
readonly params: v.OptionalSchema<v.LooseObjectSchema<{
|
|
266
|
+
/**
|
|
267
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
268
|
+
* for notes on _meta usage.
|
|
269
|
+
*/
|
|
270
|
+
readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
|
|
271
|
+
}, undefined>, undefined>;
|
|
272
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
273
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
255
274
|
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
256
275
|
readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
|
|
257
276
|
readonly result: v.LooseObjectSchema<{
|
|
@@ -261,7 +280,24 @@ declare module 'tmcp' {
|
|
|
261
280
|
*/
|
|
262
281
|
readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
|
|
263
282
|
}, undefined>;
|
|
264
|
-
}, undefined
|
|
283
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
284
|
+
readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
|
|
285
|
+
readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
|
|
286
|
+
readonly error: v.ObjectSchema<{
|
|
287
|
+
/**
|
|
288
|
+
* The error type that occurred.
|
|
289
|
+
*/
|
|
290
|
+
readonly code: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
|
|
291
|
+
/**
|
|
292
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
293
|
+
*/
|
|
294
|
+
readonly message: v.StringSchema<undefined>;
|
|
295
|
+
/**
|
|
296
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
297
|
+
*/
|
|
298
|
+
readonly data: v.OptionalSchema<v.UnknownSchema, undefined>;
|
|
299
|
+
}, undefined>;
|
|
300
|
+
}, undefined>], undefined>;
|
|
265
301
|
const IconsSchema: v.ObjectSchema<{
|
|
266
302
|
/**
|
|
267
303
|
* Optional set of sized icons that the client can display in a user interface.
|
|
@@ -1223,7 +1259,7 @@ declare module 'tmcp' {
|
|
|
1223
1259
|
type CreateMessageRequestParams_1 = v.InferInput<typeof CreateMessageRequestParamsSchema>;
|
|
1224
1260
|
type CreateMessageResult_1 = v.InferInput<typeof CreateMessageResultSchema>;
|
|
1225
1261
|
type Resource_1 = v.InferInput<typeof ResourceSchema>;
|
|
1226
|
-
type
|
|
1262
|
+
type JSONRPCMessage = v.InferInput<typeof JSONRPCMessageSchema>;
|
|
1227
1263
|
type LoggingLevel_1 = v.InferInput<typeof LoggingLevelSchema>;
|
|
1228
1264
|
type ToolAnnotations = v.InferInput<typeof ToolAnnotationsSchema>;
|
|
1229
1265
|
type ElicitResult_1 = v.InferInput<typeof ElicitResultSchema>;
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"SubscriptionsKeysObj",
|
|
22
22
|
"SubscriptionsKeys",
|
|
23
23
|
"McpEvents",
|
|
24
|
-
"
|
|
24
|
+
"JSONRPCMessageSchema",
|
|
25
25
|
"IconsSchema",
|
|
26
26
|
"ImplementationSchema",
|
|
27
27
|
"ClientCapabilitiesSchema",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"ServerCapabilities",
|
|
41
41
|
"InitializeRequestParams",
|
|
42
42
|
"CompleteResult",
|
|
43
|
-
"
|
|
43
|
+
"JSONRPCMessage",
|
|
44
44
|
"ToolAnnotations",
|
|
45
45
|
"Trim",
|
|
46
46
|
"ExtractVarName",
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
null,
|
|
65
65
|
null
|
|
66
66
|
],
|
|
67
|
-
"mappings": ";;;;;cAyJaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aCw1CyBC,KAAKA;aDp7CFC,aAAaA;;aC28CHC,kBAAkBA;aAGrBC,eAAeA;aAvBZC,kBAAkBA;aAUKC,UAAUA;aAmBzBC,0BAA0BA;aAGjCC,mBAAmBA;aAY9BC,QAAQA;
|
|
67
|
+
"mappings": ";;;;;cAyJaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;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typedef {v.InferInput<typeof JSONRPCRequestSchema>} JSONRPCRequest
|
|
1573
1573
|
*/
|
|
1574
|
+
/**
|
|
1575
|
+
* @typedef {v.InferInput<typeof JSONRPCMessageSchema>} JSONRPCMessage
|
|
1576
|
+
*/
|
|
1574
1577
|
/**
|
|
1575
1578
|
* @typedef {v.InferInput<typeof JSONRPCResponseSchema>} JSONRPCResponse
|
|
1576
1579
|
*/
|