tmcp 1.19.3 → 1.20.0-next.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 CHANGED
@@ -582,7 +582,7 @@ server.tool(
582
582
 
583
583
  ##### `ctx`
584
584
 
585
- Access the current request context, including session ID, auth info, client metadata, and custom context.
585
+ Access the current request context, including session ID, auth info, client metadata, custom context, and cooperative cancellation.
586
586
 
587
587
  ```javascript
588
588
  server.tool(
@@ -591,7 +591,11 @@ server.tool(
591
591
  description: 'Tool that uses request context',
592
592
  },
593
593
  async () => {
594
- const { sessionId, auth, sessionInfo, custom } = server.ctx;
594
+ const { sessionId, auth, sessionInfo, custom, signal } = server.ctx;
595
+
596
+ if (signal?.aborted) {
597
+ throw new Error('Request cancelled');
598
+ }
595
599
 
596
600
  if (!custom?.userId) {
597
601
  throw new Error('User authentication required');
@@ -613,6 +617,24 @@ server.tool(
613
617
  );
614
618
  ```
615
619
 
620
+ Transports may provide `ctx.signal`. The HTTP transport aborts it when the request is aborted or its SSE response is closed. Handlers remain responsible for stopping their own work.
621
+
622
+ ##### `validateToolCall(name, args, validator)`
623
+
624
+ Run transport or integration validation against a registered tool's converted input JSON Schema without executing the tool:
625
+
626
+ ```javascript
627
+ const found = await server.validateToolCall(
628
+ 'tool-name',
629
+ args,
630
+ async (inputSchema, originalArgs) => {
631
+ // Inspect the JSON Schema and original arguments.
632
+ },
633
+ );
634
+ ```
635
+
636
+ The method returns `false` without invoking the validator when the tool is unknown. For a registered tool it converts the input schema with the configured adapter, awaits the validator, and returns `true`. It does not run the tool's `enabled` callback, Standard Schema validation, or handler. Adapter and validator errors are propagated.
637
+
616
638
  ##### `receive(request, context?)`
617
639
 
618
640
  Process an incoming MCP request with optional context.
@@ -634,6 +656,24 @@ const response = server.receive(jsonRpcRequest, {
634
656
  });
635
657
  ```
636
658
 
659
+ ##### `hasMethod(method)`
660
+
661
+ Check whether a JSON-RPC method is registered without invoking it:
662
+
663
+ ```javascript
664
+ if (server.hasMethod('tools/list')) {
665
+ // The method exists in this server's registry.
666
+ }
667
+ ```
668
+
669
+ This reports every registered method, including methods limited to initialization-based or per-request clients. Transports that need protocol-specific filtering can use the dedicated method-policy entry point:
670
+
671
+ ```javascript
672
+ import { isPerRequestMethodAllowed } from 'tmcp/method-policy';
673
+
674
+ const available = server.hasMethod(method) && isPerRequestMethodAllowed(method);
675
+ ```
676
+
637
677
  ##### `request({ method, params })`
638
678
 
639
679
  Send a raw JSON-RPC request to the connected client. This lets you call
@@ -674,12 +714,32 @@ const response = await server.request({
674
714
  Handle the resolved payload like any other JSON-RPC response—cast or (better) validate
675
715
  as needed when using this escape hatch.
676
716
 
677
- ##### `elicitation(schema)`
717
+ ##### `elicitation(message, schema | url, options?)`
678
718
 
679
719
  Request client elicitation with schema validation.
680
720
 
681
721
  ```javascript
682
- const result = await server.elicitation(schema);
722
+ const result = await server.elicitation(
723
+ 'Please provide the requested data',
724
+ schema,
725
+ );
726
+ ```
727
+
728
+ Pass a URL instead of a schema to request URL elicitation:
729
+
730
+ ```javascript
731
+ const result = await server.elicitation(
732
+ 'Authorize access',
733
+ 'https://example.com/authorize',
734
+ );
735
+ ```
736
+
737
+ Per-request input calls use an ordinal key by default. If conditional control flow can change the call order between retries, pass a stable key:
738
+
739
+ ```javascript
740
+ const result = await server.elicitation('Confirm?', schema, {
741
+ key: 'confirm',
742
+ });
683
743
  ```
684
744
 
685
745
  ##### `message(request)`
@@ -708,12 +768,14 @@ console.log(server.roots); // Access current roots
708
768
 
709
769
  ##### `changed(type, id)`
710
770
 
711
- Send notifications for subscriptions. When you call `changed('resource', uri)` the server now emits a broadcast notification, and the built-in transports look up which sessions subscribed to that URI before delivering it.
771
+ Send change notifications. Session-negotiated clients keep the existing broadcast and `resources/subscribe` behavior. Per-request clients receive only changes matching the filter on their open `subscriptions/listen` request.
712
772
 
713
773
  ```javascript
714
774
  server.changed('resource', 'file://path/to/resource');
715
775
  ```
716
776
 
777
+ Per-request subscription lifecycle belongs to the active transport. HTTP, stdio, and in-memory transports provide a stable connection origin and a `SubscriptionManager`; core validates filters, acknowledges the stream, and tags matching change notifications. Managers and their in-memory implementation are exported by `@tmcp/session-manager`, not configured on `McpServer`.
778
+
717
779
  ##### `progress(progress, total?, message?)`
718
780
 
719
781
  Report progress during long-running operations. Progress notifications are only sent when a progress token is provided by the client in the request's `_meta.progressToken` field.
@@ -782,8 +844,8 @@ Listen to server events.
782
844
  Available events:
783
845
 
784
846
  - `initialize` – fired after the client handshake with the parsed initialize payload
785
- - `send` – emitted for point-to-point responses/notifications destined for the active session
786
- - `broadcast` – emitted for fan-out notifications (for example `notifications/resources/updated`)
847
+ - `send` – emitted for point-to-point responses/notifications; subscription messages include `subscriptionId` and `subscriptionOrigin` routing fields
848
+ - `broadcast` – emitted for fan-out notifications; concrete template updates intended only for per-request subscribers include `subscriptionOnly: true`
787
849
  - `subscription` – raised when the client subscribes to a resource URI
788
850
  - `loglevelchange` – fired when the client requests a different log level
789
851
 
@@ -896,6 +958,7 @@ server.prompt(
896
958
  ```javascript
897
959
  // Elicitation - Request structured data from client
898
960
  const userData = await server.elicitation(
961
+ 'Please provide your profile',
899
962
  z.object({
900
963
  name: z.string(),
901
964
  age: z.number(),
@@ -1382,6 +1445,7 @@ server.prompt(
1382
1445
  },
1383
1446
  async (input) => {
1384
1447
  const username = await server.elicitation(
1448
+ 'Which username should be used?',
1385
1449
  v.object({
1386
1450
  value: v.string(),
1387
1451
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmcp",
3
- "version": "1.19.3",
3
+ "version": "1.20.0-next.0",
4
4
  "description": "The main tmcp library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -41,6 +41,10 @@
41
41
  "types": "./src/types/index.d.ts",
42
42
  "default": "./src/adapter.js"
43
43
  },
44
+ "./method-policy": {
45
+ "types": "./src/types/index.d.ts",
46
+ "default": "./src/method-policy.js"
47
+ },
44
48
  "./utils": {
45
49
  "types": "./src/types/index.d.ts",
46
50
  "default": "./src/utils/index.js"