tmcp 1.6.1 → 1.6.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +15 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmcp",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "The main tmcp library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -317,7 +317,7 @@ export class McpServer {
317
317
  async ({ name, arguments: args }) => {
318
318
  const tool = this.#tools.get(name);
319
319
  if (!tool) {
320
- throw new Error(`Tool ${name} not found`);
320
+ throw new McpError(-32601, `Tool ${name} not found`);
321
321
  }
322
322
  if (!tool.schema) {
323
323
  return v.parse(CallToolResultSchema, await tool.execute());
@@ -326,7 +326,8 @@ export class McpServer {
326
326
  if (validated_args instanceof Promise)
327
327
  validated_args = await validated_args;
328
328
  if (validated_args.issues) {
329
- throw new Error(
329
+ throw new McpError(
330
+ -32602,
330
331
  `Invalid arguments for tool ${name}: ${JSON.stringify(validated_args.issues)}`,
331
332
  );
332
333
  }
@@ -403,7 +404,7 @@ export class McpServer {
403
404
  async ({ name, arguments: args }) => {
404
405
  const prompt = this.#prompts.get(name);
405
406
  if (!prompt) {
406
- throw new Error(`Tool ${name} not found`);
407
+ throw new McpError(-32601, `Prompt ${name} not found`);
407
408
  }
408
409
  if (!prompt.schema) {
409
410
  return v.parse(
@@ -415,8 +416,9 @@ export class McpServer {
415
416
  if (validated_args instanceof Promise)
416
417
  validated_args = await validated_args;
417
418
  if (validated_args.issues) {
418
- throw new Error(
419
- `Invalid arguments for tool ${name}: ${JSON.stringify(validated_args.issues)}`,
419
+ throw new McpError(
420
+ -32602,
421
+ `Invalid arguments for prompt ${name}: ${JSON.stringify(validated_args.issues)}`,
420
422
  );
421
423
  }
422
424
  return v.parse(
@@ -512,12 +514,12 @@ export class McpServer {
512
514
  params = match.params;
513
515
  }
514
516
  if (!resource) {
515
- throw new Error(`Resource ${uri} not found`);
517
+ throw new McpError(-32601, `Resource ${uri} not found`);
516
518
  }
517
519
  }
518
520
  if (resource.template) {
519
521
  if (!params)
520
- throw new Error('Missing parameters for template resource');
522
+ throw new McpError(-32602, 'Missing parameters for template resource');
521
523
  return v.parse(
522
524
  ReadResourceResultSchema,
523
525
  await resource.execute(uri, params),
@@ -753,7 +755,7 @@ export class McpServer {
753
755
  */
754
756
  async elicitation(schema) {
755
757
  if (!this.#client_capabilities?.elicitation)
756
- throw new Error("Client doesn't support elicitation");
758
+ throw new McpError(-32601, "Client doesn't support elicitation");
757
759
 
758
760
  this.#lazyily_create_client();
759
761
  let validated_result = schema['~standard'].validate(
@@ -770,7 +772,8 @@ export class McpServer {
770
772
  if (validated_result instanceof Promise)
771
773
  validated_result = await validated_result;
772
774
  if (validated_result.issues) {
773
- throw new Error(
775
+ throw new McpError(
776
+ -32603,
774
777
  `Invalid elicitation result: ${JSON.stringify(validated_result.issues)}`,
775
778
  );
776
779
  }
@@ -784,7 +787,7 @@ export class McpServer {
784
787
  */
785
788
  async message(request) {
786
789
  if (!this.#client_capabilities?.sampling)
787
- throw new Error("Client doesn't support sampling");
790
+ throw new McpError(-32601, "Client doesn't support sampling");
788
791
 
789
792
  this.#lazyily_create_client();
790
793
 
@@ -815,7 +818,8 @@ export class McpServer {
815
818
  */
816
819
  log(level, data, logger) {
817
820
  if (!this.#options.capabilities?.logging) {
818
- throw new Error(
821
+ throw new McpError(
822
+ -32601,
819
823
  "The server doesn't support logging, please enable it in capabilities",
820
824
  );
821
825
  }