@modelcontextprotocol/sdk 1.20.1 → 1.21.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.
Files changed (87) hide show
  1. package/dist/cjs/client/auth.d.ts +21 -6
  2. package/dist/cjs/client/auth.d.ts.map +1 -1
  3. package/dist/cjs/client/auth.js +11 -0
  4. package/dist/cjs/client/auth.js.map +1 -1
  5. package/dist/cjs/client/index.d.ts +42 -4
  6. package/dist/cjs/client/index.d.ts.map +1 -1
  7. package/dist/cjs/client/index.js +17 -18
  8. package/dist/cjs/client/index.js.map +1 -1
  9. package/dist/cjs/examples/client/simpleOAuthClient.js.map +1 -1
  10. package/dist/cjs/examples/client/simpleStreamableHttp.js +3 -6
  11. package/dist/cjs/examples/client/simpleStreamableHttp.js.map +1 -1
  12. package/dist/cjs/examples/server/elicitationExample.d.ts +2 -0
  13. package/dist/cjs/examples/server/elicitationExample.d.ts.map +1 -0
  14. package/dist/cjs/examples/server/elicitationExample.js +437 -0
  15. package/dist/cjs/examples/server/elicitationExample.js.map +1 -0
  16. package/dist/cjs/server/auth/handlers/metadata.js +1 -1
  17. package/dist/cjs/server/auth/handlers/metadata.js.map +1 -1
  18. package/dist/cjs/server/index.d.ts +34 -2
  19. package/dist/cjs/server/index.d.ts.map +1 -1
  20. package/dist/cjs/server/index.js +9 -12
  21. package/dist/cjs/server/index.js.map +1 -1
  22. package/dist/cjs/server/mcp.d.ts +7 -0
  23. package/dist/cjs/server/mcp.d.ts.map +1 -1
  24. package/dist/cjs/server/mcp.js +47 -49
  25. package/dist/cjs/server/mcp.js.map +1 -1
  26. package/dist/cjs/shared/auth.d.ts +1 -0
  27. package/dist/cjs/shared/auth.d.ts.map +1 -1
  28. package/dist/cjs/validation/ajv-provider.d.ts +53 -0
  29. package/dist/cjs/validation/ajv-provider.d.ts.map +1 -0
  30. package/dist/cjs/validation/ajv-provider.js +95 -0
  31. package/dist/cjs/validation/ajv-provider.js.map +1 -0
  32. package/dist/cjs/validation/cfworker-provider.d.ts +52 -0
  33. package/dist/cjs/validation/cfworker-provider.d.ts.map +1 -0
  34. package/dist/cjs/validation/cfworker-provider.js +71 -0
  35. package/dist/cjs/validation/cfworker-provider.js.map +1 -0
  36. package/dist/cjs/validation/index.d.ts +29 -0
  37. package/dist/cjs/validation/index.d.ts.map +1 -0
  38. package/dist/cjs/validation/index.js +30 -0
  39. package/dist/cjs/validation/index.js.map +1 -0
  40. package/dist/cjs/validation/types.d.ts +55 -0
  41. package/dist/cjs/validation/types.d.ts.map +1 -0
  42. package/dist/cjs/validation/types.js +3 -0
  43. package/dist/cjs/validation/types.js.map +1 -0
  44. package/dist/esm/client/auth.d.ts +21 -6
  45. package/dist/esm/client/auth.d.ts.map +1 -1
  46. package/dist/esm/client/auth.js +11 -1
  47. package/dist/esm/client/auth.js.map +1 -1
  48. package/dist/esm/client/index.d.ts +42 -4
  49. package/dist/esm/client/index.d.ts.map +1 -1
  50. package/dist/esm/client/index.js +18 -16
  51. package/dist/esm/client/index.js.map +1 -1
  52. package/dist/esm/examples/client/simpleOAuthClient.js.map +1 -1
  53. package/dist/esm/examples/client/simpleStreamableHttp.js +2 -2
  54. package/dist/esm/examples/client/simpleStreamableHttp.js.map +1 -1
  55. package/dist/esm/examples/server/elicitationExample.d.ts +2 -0
  56. package/dist/esm/examples/server/elicitationExample.d.ts.map +1 -0
  57. package/dist/esm/examples/server/elicitationExample.js +432 -0
  58. package/dist/esm/examples/server/elicitationExample.js.map +1 -0
  59. package/dist/esm/server/auth/handlers/metadata.js +1 -1
  60. package/dist/esm/server/auth/handlers/metadata.js.map +1 -1
  61. package/dist/esm/server/index.d.ts +34 -2
  62. package/dist/esm/server/index.d.ts.map +1 -1
  63. package/dist/esm/server/index.js +10 -10
  64. package/dist/esm/server/index.js.map +1 -1
  65. package/dist/esm/server/mcp.d.ts +7 -0
  66. package/dist/esm/server/mcp.d.ts.map +1 -1
  67. package/dist/esm/server/mcp.js +47 -49
  68. package/dist/esm/server/mcp.js.map +1 -1
  69. package/dist/esm/shared/auth.d.ts +1 -0
  70. package/dist/esm/shared/auth.d.ts.map +1 -1
  71. package/dist/esm/validation/ajv-provider.d.ts +53 -0
  72. package/dist/esm/validation/ajv-provider.d.ts.map +1 -0
  73. package/dist/esm/validation/ajv-provider.js +88 -0
  74. package/dist/esm/validation/ajv-provider.js.map +1 -0
  75. package/dist/esm/validation/cfworker-provider.d.ts +52 -0
  76. package/dist/esm/validation/cfworker-provider.d.ts.map +1 -0
  77. package/dist/esm/validation/cfworker-provider.js +67 -0
  78. package/dist/esm/validation/cfworker-provider.js.map +1 -0
  79. package/dist/esm/validation/index.d.ts +29 -0
  80. package/dist/esm/validation/index.d.ts.map +1 -0
  81. package/dist/esm/validation/index.js +29 -0
  82. package/dist/esm/validation/index.js.map +1 -0
  83. package/dist/esm/validation/types.d.ts +55 -0
  84. package/dist/esm/validation/types.d.ts.map +1 -0
  85. package/dist/esm/validation/types.js +2 -0
  86. package/dist/esm/validation/types.js.map +1 -0
  87. package/package.json +25 -3
@@ -0,0 +1,29 @@
1
+ /**
2
+ * JSON Schema validation
3
+ *
4
+ * This module provides configurable JSON Schema validation for the MCP SDK.
5
+ * Choose a validator based on your runtime environment:
6
+ *
7
+ * - AjvJsonSchemaValidator: Best for Node.js (default, fastest)
8
+ * Import from: @modelcontextprotocol/sdk/validation/ajv
9
+ * Requires peer dependencies: ajv, ajv-formats
10
+ *
11
+ * - CfWorkerJsonSchemaValidator: Best for edge runtimes
12
+ * Import from: @modelcontextprotocol/sdk/validation/cfworker
13
+ * Requires peer dependency: @cfworker/json-schema
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // For Node.js with AJV
18
+ * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
19
+ * const validator = new AjvJsonSchemaValidator();
20
+ *
21
+ * // For Cloudflare Workers
22
+ * import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/cfworker';
23
+ * const validator = new CfWorkerJsonSchemaValidator();
24
+ * ```
25
+ *
26
+ * @module validation
27
+ */
28
+ export {};
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}
@@ -0,0 +1,55 @@
1
+ import type { Schema } from '@cfworker/json-schema';
2
+ /**
3
+ * Result of a JSON Schema validation operation
4
+ */
5
+ export type JsonSchemaValidatorResult<T> = {
6
+ valid: true;
7
+ data: T;
8
+ errorMessage: undefined;
9
+ } | {
10
+ valid: false;
11
+ data: undefined;
12
+ errorMessage: string;
13
+ };
14
+ /**
15
+ * A validator function that validates data against a JSON Schema
16
+ */
17
+ export type JsonSchemaValidator<T> = (input: unknown) => JsonSchemaValidatorResult<T>;
18
+ /**
19
+ * Provider interface for creating validators from JSON Schemas
20
+ *
21
+ * This is the main extension point for custom validator implementations.
22
+ * Implementations should:
23
+ * - Support JSON Schema Draft 2020-12 (or be compatible with it)
24
+ * - Return validator functions that can be called multiple times
25
+ * - Handle schema compilation/caching internally
26
+ * - Provide clear error messages on validation failure
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * class MyValidatorProvider implements jsonSchemaValidator {
31
+ * getValidator<T>(schema: JsonSchemaType<T>): JsonSchemaValidator<T> {
32
+ * // Compile/cache validator from schema
33
+ * return (input: unknown) => {
34
+ * // Validate input against schema
35
+ * if (valid) {
36
+ * return { valid: true, data: input as T, errorMessage: undefined };
37
+ * } else {
38
+ * return { valid: false, data: undefined, errorMessage: 'Error details' };
39
+ * }
40
+ * };
41
+ * }
42
+ * }
43
+ * ```
44
+ */
45
+ export interface jsonSchemaValidator {
46
+ /**
47
+ * Create a validator for the given JSON Schema
48
+ *
49
+ * @param schema - Standard JSON Schema object
50
+ * @returns A validator function that can be called multiple times
51
+ */
52
+ getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
53
+ }
54
+ export type JsonSchemaType = Schema;
55
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACjC;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,GACjD;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAEtF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,mBAAmB;IAChC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/validation/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelcontextprotocol/sdk",
3
- "version": "1.20.1",
3
+ "version": "1.21.0",
4
4
  "description": "Model Context Protocol implementation for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Anthropic, PBC (https://anthropic.com)",
@@ -31,6 +31,18 @@
31
31
  "import": "./dist/esm/server/index.js",
32
32
  "require": "./dist/cjs/server/index.js"
33
33
  },
34
+ "./validation": {
35
+ "import": "./dist/esm/validation/index.js",
36
+ "require": "./dist/cjs/validation/index.js"
37
+ },
38
+ "./validation/ajv": {
39
+ "import": "./dist/esm/validation/ajv-provider.js",
40
+ "require": "./dist/cjs/validation/ajv-provider.js"
41
+ },
42
+ "./validation/cfworker": {
43
+ "import": "./dist/esm/validation/cfworker-provider.js",
44
+ "require": "./dist/cjs/validation/cfworker-provider.js"
45
+ },
34
46
  "./*": {
35
47
  "import": "./dist/esm/*",
36
48
  "require": "./dist/cjs/*"
@@ -63,7 +75,8 @@
63
75
  "client": "tsx src/cli.ts client"
64
76
  },
65
77
  "dependencies": {
66
- "ajv": "^6.12.6",
78
+ "ajv": "^8.17.1",
79
+ "ajv-formats": "^3.0.1",
67
80
  "content-type": "^1.0.5",
68
81
  "cors": "^2.8.5",
69
82
  "cross-spawn": "^7.0.5",
@@ -76,7 +89,16 @@
76
89
  "zod": "^3.23.8",
77
90
  "zod-to-json-schema": "^3.24.1"
78
91
  },
92
+ "peerDependencies": {
93
+ "@cfworker/json-schema": "^4.1.1"
94
+ },
95
+ "peerDependenciesMeta": {
96
+ "@cfworker/json-schema": {
97
+ "optional": true
98
+ }
99
+ },
79
100
  "devDependencies": {
101
+ "@cfworker/json-schema": "^4.1.1",
80
102
  "@eslint/js": "^9.8.0",
81
103
  "@jest-mock/express": "^3.0.0",
82
104
  "@types/content-type": "^1.1.8",
@@ -91,8 +113,8 @@
91
113
  "@types/ws": "^8.5.12",
92
114
  "eslint": "^9.8.0",
93
115
  "eslint-config-prettier": "^10.1.8",
94
- "prettier": "3.6.2",
95
116
  "jest": "^29.7.0",
117
+ "prettier": "3.6.2",
96
118
  "supertest": "^7.0.0",
97
119
  "ts-jest": "^29.2.4",
98
120
  "tsx": "^4.16.5",