tmcp 1.20.0 → 1.20.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/package.json +42 -15
- package/src/index.js +24 -9
- package/src/prompt.js +7 -1
- package/src/resource.js +6 -1
- package/src/template.js +7 -1
- package/src/tool.js +8 -1
- package/src/utils/index.js +2 -1
- package/src/validation/index.js +58 -461
- package/types/adapter.d.ts +6 -0
- package/types/adapter.d.ts.map +1 -0
- package/types/index.d.ts +405 -0
- package/types/index.d.ts.map +1 -0
- package/{src → types}/internal/internal.d.ts +12 -27
- package/types/internal/utils.d.ts +3 -0
- package/types/internal/utils.d.ts.map +1 -0
- package/types/method-policy.d.ts +2 -0
- package/types/method-policy.d.ts.map +1 -0
- package/types/prompt.d.ts +15 -0
- package/types/prompt.d.ts.map +1 -0
- package/types/resource.d.ts +14 -0
- package/types/resource.d.ts.map +1 -0
- package/types/template.d.ts +18 -0
- package/types/template.d.ts.map +1 -0
- package/types/tool.d.ts +14 -0
- package/types/tool.d.ts.map +1 -0
- package/types/utils/index.d.ts +327 -0
- package/types/utils/index.d.ts.map +1 -0
- package/types/validation/index.d.ts +2618 -0
- package/types/validation/index.d.ts.map +1 -0
- package/types/validation/method-policy.d.ts +26 -0
- package/types/validation/method-policy.d.ts.map +1 -0
- package/types/validation/version.d.ts +113 -0
- package/types/validation/version.d.ts.map +1 -0
- package/src/types/index.d.ts +0 -4383
- package/src/types/index.d.ts.map +0 -134
- /package/{src → types}/internal/uri-template.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tmcp",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "The main tmcp library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"types": "
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
8
|
"keywords": [],
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -14,61 +14,88 @@
|
|
|
14
14
|
"author": "Paolo Ricciuti",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"files": [
|
|
17
|
-
"src/"
|
|
17
|
+
"src/",
|
|
18
|
+
"types/",
|
|
19
|
+
"!src/**/*.d.ts"
|
|
18
20
|
],
|
|
19
21
|
"exports": {
|
|
20
22
|
".": {
|
|
21
|
-
"types": "./
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
22
24
|
"default": "./src/index.js"
|
|
23
25
|
},
|
|
24
26
|
"./tool": {
|
|
25
|
-
"types": "./
|
|
27
|
+
"types": "./types/tool.d.ts",
|
|
26
28
|
"default": "./src/tool.js"
|
|
27
29
|
},
|
|
28
30
|
"./prompt": {
|
|
29
|
-
"types": "./
|
|
31
|
+
"types": "./types/prompt.d.ts",
|
|
30
32
|
"default": "./src/prompt.js"
|
|
31
33
|
},
|
|
32
34
|
"./resource": {
|
|
33
|
-
"types": "./
|
|
35
|
+
"types": "./types/resource.d.ts",
|
|
34
36
|
"default": "./src/resource.js"
|
|
35
37
|
},
|
|
36
38
|
"./template": {
|
|
37
|
-
"types": "./
|
|
39
|
+
"types": "./types/template.d.ts",
|
|
38
40
|
"default": "./src/template.js"
|
|
39
41
|
},
|
|
40
42
|
"./adapter": {
|
|
41
|
-
"types": "./
|
|
43
|
+
"types": "./types/adapter.d.ts",
|
|
42
44
|
"default": "./src/adapter.js"
|
|
43
45
|
},
|
|
44
46
|
"./method-policy": {
|
|
45
|
-
"types": "./
|
|
47
|
+
"types": "./types/method-policy.d.ts",
|
|
46
48
|
"default": "./src/method-policy.js"
|
|
47
49
|
},
|
|
48
50
|
"./utils": {
|
|
49
|
-
"types": "./
|
|
51
|
+
"types": "./types/utils/index.d.ts",
|
|
50
52
|
"default": "./src/utils/index.js"
|
|
51
53
|
},
|
|
52
54
|
"./package.json": "./package.json"
|
|
53
55
|
},
|
|
56
|
+
"typesVersions": {
|
|
57
|
+
"*": {
|
|
58
|
+
"tool": [
|
|
59
|
+
"./types/tool.d.ts"
|
|
60
|
+
],
|
|
61
|
+
"prompt": [
|
|
62
|
+
"./types/prompt.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"resource": [
|
|
65
|
+
"./types/resource.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"template": [
|
|
68
|
+
"./types/template.d.ts"
|
|
69
|
+
],
|
|
70
|
+
"adapter": [
|
|
71
|
+
"./types/adapter.d.ts"
|
|
72
|
+
],
|
|
73
|
+
"method-policy": [
|
|
74
|
+
"./types/method-policy.d.ts"
|
|
75
|
+
],
|
|
76
|
+
"utils": [
|
|
77
|
+
"./types/utils/index.d.ts"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
54
81
|
"dependencies": {
|
|
55
82
|
"@standard-schema/spec": "^1.0.0",
|
|
83
|
+
"@types/json-schema": "^7.0.15",
|
|
56
84
|
"json-rpc-2.0": "^1.7.1",
|
|
57
85
|
"sqids": "^0.3.0",
|
|
58
86
|
"uri-template-matcher": "^1.1.1",
|
|
59
87
|
"valibot": "^1.1.0"
|
|
60
88
|
},
|
|
61
89
|
"devDependencies": {
|
|
62
|
-
"@types/json-schema": "^7.0.15",
|
|
63
90
|
"@types/node": "^24.0.13",
|
|
64
|
-
"dts-buddy": "^0.6.2",
|
|
65
91
|
"publint": "^0.3.12",
|
|
66
|
-
"vitest": "^4.0.0"
|
|
92
|
+
"vitest": "^4.0.0",
|
|
93
|
+
"@tmcp/internal-ts-helpers": "^1.0.0"
|
|
67
94
|
},
|
|
68
95
|
"scripts": {
|
|
69
96
|
"test": "vitest",
|
|
70
97
|
"typecheck": "tsc --noEmit",
|
|
71
|
-
"generate:types": "
|
|
98
|
+
"generate:types": "generate-types && publint",
|
|
72
99
|
"prepublish": "pnpm generate:types"
|
|
73
100
|
}
|
|
74
101
|
}
|
package/src/index.js
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
4
|
* @import SqidsType from "sqids";
|
|
5
|
-
* @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
|
|
5
|
+
* @import { JSONRPCRequest, JSONRPCParams, JSONRPCErrorResponse } from "json-rpc-2.0";
|
|
6
6
|
* @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
|
|
7
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, InitializeResult as InitializeResultType, ListToolsResult as ListToolsResultType, ListPromptsResult as ListPromptsResultType, ListResourceTemplatesResult as ListResourceTemplatesResultType, ListResourcesResult as ListResourcesResultType, CompleteResult as CompleteResultType, SubscriptionFilter as SubscriptionFilterType, SubscriptionsListenRequest as SubscriptionsListenRequestType, SubscriptionsListenResult as SubscriptionsListenResultType, SubscriptionsAcknowledgedNotification as SubscriptionsAcknowledgedNotificationType, DiscoverRequestParams } from "./validation/index.js";
|
|
8
|
-
* @import { Tool, Completion, Prompt, StoredResource, ServerOptions, SubscriptionsKeys,
|
|
9
|
-
* @import {
|
|
8
|
+
* @import { Tool, Completion, Prompt, StoredResource, ServerOptions, SubscriptionsKeys, McpEvents as McpEventsType, AllSame, TemplateOptions, MrtrState, Subscription as SubscriptionType, SubscriptionCallbacks as SubscriptionCallbacksType, SubscriptionManager as SubscriptionManagerType, SubscriptionOrigin as SubscriptionOriginType } from "./internal/internal.js";
|
|
9
|
+
* @import { ToolOptions, PromptOptions, ResourceOptions } from "./internal/internal.js";
|
|
10
|
+
* @import { CreatedTool } from "./tool.js";
|
|
11
|
+
* @import { CreatedPrompt } from "./prompt.js";
|
|
12
|
+
* @import { CreatedResource } from "./resource.js";
|
|
13
|
+
* @import { CreatedTemplate } from "./template.js";
|
|
10
14
|
*/
|
|
11
15
|
import {
|
|
12
16
|
createJSONRPCErrorResponse,
|
|
@@ -153,6 +157,11 @@ export function getPerRequestProtocolVersions() {
|
|
|
153
157
|
* @typedef {Context<TCustom> & { subscriptionOrigin?: SubscriptionOriginType, subscriptionManager?: SubscriptionManagerType }} ReceiveContext
|
|
154
158
|
*/
|
|
155
159
|
|
|
160
|
+
/** @typedef {McpEventsType} McpEvents */
|
|
161
|
+
/**
|
|
162
|
+
* The arguments of `McpServer.changed` for each kind of change.
|
|
163
|
+
* @typedef {{ resource: [id: string], tools: [], prompts: [], resources: [] }} ChangedArgs
|
|
164
|
+
*/
|
|
156
165
|
/** @typedef {SubscriptionFilterType} SubscriptionFilter */
|
|
157
166
|
/** @typedef {SubscriptionOriginType} SubscriptionOrigin */
|
|
158
167
|
/** @typedef {SubscriptionType} Subscription */
|
|
@@ -399,13 +408,14 @@ export class McpServer {
|
|
|
399
408
|
event('initialize', validated_initialize),
|
|
400
409
|
);
|
|
401
410
|
|
|
402
|
-
// Return server response with negotiated version and capabilities
|
|
403
|
-
//
|
|
404
|
-
// eslint-disable-next-line no-unused-vars
|
|
405
|
-
const { cache, ...legacy_options } = options;
|
|
411
|
+
// Return server response with negotiated version and capabilities;
|
|
412
|
+
// the rest of the options (adapter, pagination, cache...) is server-side only
|
|
406
413
|
return {
|
|
407
414
|
protocolVersion: negotiated_version,
|
|
408
|
-
|
|
415
|
+
capabilities: options.capabilities,
|
|
416
|
+
...(options.instructions != null
|
|
417
|
+
? { instructions: options.instructions }
|
|
418
|
+
: {}),
|
|
409
419
|
serverInfo: server_info,
|
|
410
420
|
};
|
|
411
421
|
} catch (error) {
|
|
@@ -1620,6 +1630,7 @@ export class McpServer {
|
|
|
1620
1630
|
* notification (which cannot receive a response).
|
|
1621
1631
|
* @param {string | number | undefined} id
|
|
1622
1632
|
* @param {McpError} error
|
|
1633
|
+
* @returns {Promise<JSONRPCErrorResponse | null>}
|
|
1623
1634
|
*/
|
|
1624
1635
|
#error_response(id, error) {
|
|
1625
1636
|
if (id === undefined) return Promise.resolve(null);
|
|
@@ -1634,12 +1645,16 @@ export class McpServer {
|
|
|
1634
1645
|
});
|
|
1635
1646
|
}
|
|
1636
1647
|
|
|
1648
|
+
// TODO: on the next major remove `@returns {any}` so the real return type is
|
|
1649
|
+
// inferred. Since 1.5.0 a misplaced `| undefined` in the annotation
|
|
1650
|
+
// (`ReturnType<JSONRPCClient['receive'] | undefined>`) made it `any`, and
|
|
1651
|
+
// changing it now would break users that rely on it.
|
|
1637
1652
|
/**
|
|
1638
1653
|
* The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
|
|
1639
1654
|
*
|
|
1640
1655
|
* @param {JSONRPCMessage} message
|
|
1641
1656
|
* @param {ReceiveContext<CustomContext>} [ctx]
|
|
1642
|
-
* @returns {
|
|
1657
|
+
* @returns {any}
|
|
1643
1658
|
*/
|
|
1644
1659
|
receive(message, ctx) {
|
|
1645
1660
|
// Validate the message first
|
package/src/prompt.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
* @import { PromptOptions
|
|
3
|
+
* @import { PromptOptions } from "./internal/internal.js";
|
|
4
4
|
* @import { GetPromptResult } from "./validation/index.js"
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* A prompt created with `definePrompt`.
|
|
9
|
+
* @template {StandardSchemaV1 | undefined} [TSchema=undefined]
|
|
10
|
+
* @typedef {PromptOptions<TSchema> & { [created_prompt]: typeof created_prompt }} CreatedPrompt
|
|
11
|
+
*/
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
|
|
9
15
|
* Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
|
package/src/resource.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { ResourceOptions
|
|
2
|
+
* @import { ResourceOptions } from "./internal/internal.js";
|
|
3
3
|
* @import { ReadResourceResult } from "./validation/index.js";
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* A resource created with `defineResource`.
|
|
8
|
+
* @typedef {ResourceOptions & { [created_resource]: typeof created_resource }} CreatedResource
|
|
9
|
+
*/
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
|
|
8
13
|
* Use the description and title to help the user to understand what the resource is. The mimeType can be used to indicate the type of content.
|
package/src/template.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
2
2
|
/**
|
|
3
3
|
* @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
|
|
4
|
-
* @import { TemplateOptions
|
|
4
|
+
* @import { TemplateOptions } from "./internal/internal.js";
|
|
5
5
|
* @import { ReadResourceResult } from "./validation/index.js";
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A resource template created with `defineTemplate`.
|
|
10
|
+
* @template {string} [TUri=string]
|
|
11
|
+
* @typedef {TemplateOptions<TUri> & { [created_template]: typeof created_template }} CreatedTemplate
|
|
12
|
+
*/
|
|
13
|
+
|
|
8
14
|
/**
|
|
9
15
|
* Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
|
|
10
16
|
* Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
|
package/src/tool.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
-
* @import { ToolOptions
|
|
3
|
+
* @import { ToolOptions } from "./internal/internal.js";
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A tool created with `defineTool`.
|
|
8
|
+
* @template {StandardSchemaV1 | undefined} [TSchema=undefined]
|
|
9
|
+
* @template {StandardSchemaV1 | undefined} [TOutputSchema=undefined]
|
|
10
|
+
* @typedef {ToolOptions<TSchema, TOutputSchema> & { [created_tool]: typeof created_tool }} CreatedTool
|
|
4
11
|
*/
|
|
5
12
|
|
|
6
13
|
/**
|
package/src/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @import { EmbeddedResource, ResourceLink,
|
|
2
|
+
* @import { EmbeddedResource, ResourceLink, ReadResourceResult, GetPromptResult, CompleteResult } from "../validation/index.js";
|
|
3
|
+
* @import { CallToolResult } from "../index.js";
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
/**
|