tmcp 1.6.2 → 1.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmcp",
3
- "version": "1.6.2",
3
+ "version": "1.7.1",
4
4
  "description": "The main tmcp library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -36,10 +36,11 @@
36
36
  "@standard-schema/spec": "^1.0.0",
37
37
  "@types/json-schema": "^7.0.15",
38
38
  "@types/node": "^24.0.13",
39
- "publint": "^0.3.12"
39
+ "publint": "^0.3.12",
40
+ "vitest": "^3.2.4"
40
41
  },
41
42
  "scripts": {
42
- "test": "echo \"Error: no test specified\" && exit 1",
43
+ "test": "vitest",
43
44
  "typecheck": "tsc --noEmit",
44
45
  "generate:types": "find ./src -name \"*.d.ts\" -not -path \"./src/internal/*\" -delete && tsc ./src/*.js --declaration --emitDeclarationOnly --target esnext --allowJs --moduleresolution nodenext --module nodenext && publint",
45
46
  "prepublish": "pnpm generate:types"
package/src/index.d.ts CHANGED
@@ -41,17 +41,18 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
41
41
  * @param {McpEvents[TEvent]} callback
42
42
  * @param {AddEventListenerOptions} [options]
43
43
  */
44
- on<TEvent extends keyof McpEvents>(event: TEvent, callback: McpEvents[TEvent], options?: AddEventListenerOptions): void;
44
+ on<TEvent extends keyof McpEvents>(event: TEvent, callback: McpEvents[TEvent], options?: AddEventListenerOptions): () => void;
45
45
  /**
46
46
  * @template {StandardSchema | undefined} [TSchema=undefined]
47
- * @param {{ name: string; description: string; title?: string; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never }} options
47
+ * @param {{ name: string; description: string; title?: string; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; annotations?: ToolAnnotations }} options
48
48
  * @param {TSchema extends undefined ? (()=>Promise<CallToolResult> | CallToolResult) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult> | CallToolResult)} execute
49
49
  */
50
- tool<TSchema extends StandardSchema | undefined = undefined>({ name, description, title, schema }: {
50
+ tool<TSchema extends StandardSchema | undefined = undefined>({ name, description, title, schema, annotations }: {
51
51
  name: string;
52
52
  description: string;
53
53
  title?: string;
54
54
  schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
55
+ annotations?: ToolAnnotations;
55
56
  }, execute: TSchema extends undefined ? (() => Promise<CallToolResult> | CallToolResult) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult> | CallToolResult)): void;
56
57
  /**
57
58
  * @template {StandardSchema | undefined} [TSchema=undefined]
@@ -129,6 +130,7 @@ export class McpServer<StandardSchema extends StandardSchemaV1> {
129
130
  export type ClientCapabilities = ClientCapabilitiesType;
130
131
  import type { StandardSchemaV1 } from "@standard-schema/spec";
131
132
  import type { McpEvents } from "./internal/internal.js";
133
+ import type { ToolAnnotations } from "./validation/index.js";
132
134
  import type { CallToolResult } from "./validation/index.js";
133
135
  import type { Completion } from "./internal/internal.js";
134
136
  import type { GetPromptResult } from "./validation/index.js";
package/src/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @import SqidsType from "sqids";
4
4
  * @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
5
5
  * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
6
- * @import { CallToolResult, ReadResourceResult, GetPromptResult, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams, CreateMessageResult, Resource, LoggingLevel } from "./validation/index.js";
6
+ * @import { CallToolResult, ReadResourceResult, GetPromptResult, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams, CreateMessageResult, Resource, LoggingLevel, ToolAnnotations } from "./validation/index.js";
7
7
  * @import { Tool, Completion, Prompt, StoredResource, ServerOptions, ServerInfo, SubscriptionsKeys, McpEvents } from "./internal/internal.js";
8
8
  */
9
9
  import { JSONRPCClient, JSONRPCServer } from 'json-rpc-2.0';
@@ -270,13 +270,18 @@ export class McpServer {
270
270
  this.#lazyily_create_client();
271
271
  }
272
272
 
273
- this.#event_target.addEventListener(
274
- event,
275
- (e) => {
276
- callback(/** @type {CustomEvent} */ (e).detail);
277
- },
278
- options,
279
- );
273
+ /**
274
+ * @param {Event} e
275
+ */
276
+ const listener = (e) => {
277
+ callback(/** @type {CustomEvent} */ (e).detail);
278
+ };
279
+
280
+ this.#event_target.addEventListener(event, listener, options);
281
+
282
+ return () => {
283
+ this.#event_target.removeEventListener(event, listener, options);
284
+ };
280
285
  }
281
286
 
282
287
  /**
@@ -300,6 +305,7 @@ export class McpServer {
300
305
  name,
301
306
  title: tool.title || tool.description,
302
307
  description: tool.description,
308
+ annotations: tool.annotations,
303
309
  inputSchema: tool.schema
304
310
  ? await this.#options.adapter.toJsonSchema(
305
311
  tool.schema,
@@ -519,7 +525,10 @@ export class McpServer {
519
525
  }
520
526
  if (resource.template) {
521
527
  if (!params)
522
- throw new McpError(-32602, 'Missing parameters for template resource');
528
+ throw new McpError(
529
+ -32602,
530
+ 'Missing parameters for template resource',
531
+ );
523
532
  return v.parse(
524
533
  ReadResourceResultSchema,
525
534
  await resource.execute(uri, params),
@@ -595,10 +604,10 @@ export class McpServer {
595
604
  }
596
605
  /**
597
606
  * @template {StandardSchema | undefined} [TSchema=undefined]
598
- * @param {{ name: string; description: string; title?: string; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never }} options
607
+ * @param {{ name: string; description: string; title?: string; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; annotations?: ToolAnnotations }} options
599
608
  * @param {TSchema extends undefined ? (()=>Promise<CallToolResult> | CallToolResult) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult> | CallToolResult)} execute
600
609
  */
601
- tool({ name, description, title, schema }, execute) {
610
+ tool({ name, description, title, schema, annotations }, execute) {
602
611
  if (this.#options.capabilities?.tools?.listChanged) {
603
612
  this.#notify('notifications/tools/list_changed', {});
604
613
  }
@@ -607,6 +616,7 @@ export class McpServer {
607
616
  title,
608
617
  schema,
609
618
  execute,
619
+ annotations,
610
620
  });
611
621
  }
612
622
  /**
@@ -9,13 +9,15 @@ import {
9
9
  InitializeRequestParams,
10
10
  Resource,
11
11
  ServerCapabilities,
12
- LoggingLevel
12
+ LoggingLevel,
13
+ ToolAnnotations
13
14
  } from '../validation/index.js';
14
15
 
15
16
  export type Tool<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = {
16
17
  description: string;
17
18
  schema: TSchema;
18
19
  title?: string;
20
+ annotations?: ToolAnnotations;
19
21
  execute: (
20
22
  input?: StandardSchemaV1.InferInput<TSchema>,
21
23
  ) => Promise<CallToolResult> | CallToolResult;
@@ -4315,4 +4315,5 @@ export type Resource = v.InferInput<typeof ResourceSchema>;
4315
4315
  export type JSONRPCRequest = v.InferInput<typeof JSONRPCRequestSchema>;
4316
4316
  export type JSONRPCResponse = v.InferInput<typeof JSONRPCResponseSchema>;
4317
4317
  export type LoggingLevel = v.InferInput<typeof LoggingLevelSchema>;
4318
+ export type ToolAnnotations = v.InferInput<typeof ToolAnnotationsSchema>;
4318
4319
  import * as v from 'valibot';
@@ -1530,3 +1530,6 @@ export const ServerResultSchema = v.union([
1530
1530
  /**
1531
1531
  * @typedef {v.InferInput<typeof LoggingLevelSchema>} LoggingLevel
1532
1532
  */
1533
+ /**
1534
+ * @typedef {v.InferInput<typeof ToolAnnotationsSchema>} ToolAnnotations
1535
+ */