xmcp 0.6.13 → 0.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.
Files changed (161) hide show
  1. package/dist/cli.js +8 -8
  2. package/dist/index.js +2 -2
  3. package/dist/runtime/adapter-express.js +2 -2
  4. package/dist/runtime/adapter-fastify.js +2 -2
  5. package/dist/runtime/adapter-nestjs.js +7 -7
  6. package/dist/runtime/adapter-nextjs.js +11 -11
  7. package/dist/runtime/http.js +3 -3
  8. package/dist/runtime/stdio.js +8 -8
  9. package/package.json +10 -11
  10. package/src/auth/api-key.ts +0 -120
  11. package/src/auth/jwt.ts +0 -52
  12. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  13. package/src/cli/commands/create/index.ts +0 -74
  14. package/src/cli/commands/create/templates/index.ts +0 -4
  15. package/src/cli/commands/create/templates/prompt.ts +0 -30
  16. package/src/cli/commands/create/templates/resource.ts +0 -20
  17. package/src/cli/commands/create/templates/tool.ts +0 -34
  18. package/src/cli/commands/create/templates/widget.ts +0 -33
  19. package/src/cli/utils/naming.ts +0 -39
  20. package/src/cli.ts +0 -125
  21. package/src/client/headers.ts +0 -61
  22. package/src/client/index.ts +0 -180
  23. package/src/client/types.ts +0 -122
  24. package/src/client/utils.ts +0 -133
  25. package/src/cloudflare.ts +0 -6
  26. package/src/compiler/build-telemetry.ts +0 -88
  27. package/src/compiler/client/component-compiler.ts +0 -250
  28. package/src/compiler/client/transpile.ts +0 -21
  29. package/src/compiler/compiler-context.ts +0 -61
  30. package/src/compiler/config/__tests__/config.test.ts +0 -459
  31. package/src/compiler/config/index.ts +0 -62
  32. package/src/compiler/config/injection.ts +0 -210
  33. package/src/compiler/config/schemas/bundler.ts +0 -12
  34. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  35. package/src/compiler/config/schemas/index.ts +0 -20
  36. package/src/compiler/config/schemas/paths.ts +0 -35
  37. package/src/compiler/config/schemas/template.ts +0 -80
  38. package/src/compiler/config/schemas/transport/http.ts +0 -116
  39. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  40. package/src/compiler/config/schemas/typescript.ts +0 -26
  41. package/src/compiler/config/utils.ts +0 -168
  42. package/src/compiler/generate-env-code.ts +0 -5
  43. package/src/compiler/generate-import-code.ts +0 -187
  44. package/src/compiler/generate-tools-code.ts +0 -174
  45. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  46. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  47. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  48. package/src/compiler/get-bundler-config/index.ts +0 -288
  49. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  50. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  51. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  52. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  53. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  54. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  55. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  56. package/src/compiler/index.ts +0 -484
  57. package/src/compiler/on-first-build.ts +0 -54
  58. package/src/compiler/parse-xmcp-config.ts +0 -200
  59. package/src/compiler/start-http-server.ts +0 -42
  60. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  61. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  62. package/src/compiler/utils/config-detection.ts +0 -34
  63. package/src/compiler/utils/path-utils.ts +0 -22
  64. package/src/compiler/watcher-recovery.ts +0 -72
  65. package/src/host-bridge.ts +0 -36
  66. package/src/index.ts +0 -94
  67. package/src/platforms/build-cloudflare-output.ts +0 -116
  68. package/src/platforms/build-vercel-output.ts +0 -131
  69. package/src/plugins/index.ts +0 -1
  70. package/src/plugins/x402/index.ts +0 -24
  71. package/src/runtime/adapters/express/index.ts +0 -75
  72. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  73. package/src/runtime/adapters/fastify/index.ts +0 -78
  74. package/src/runtime/adapters/nestjs/index.ts +0 -16
  75. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  76. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  77. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  78. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  79. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  80. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  81. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  82. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  83. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  84. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  85. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  86. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  87. package/src/runtime/adapters/nextjs/index.ts +0 -82
  88. package/src/runtime/contexts/client-info-context.ts +0 -16
  89. package/src/runtime/contexts/http-request-context.ts +0 -21
  90. package/src/runtime/contexts/http-transport-context.ts +0 -18
  91. package/src/runtime/headers.ts +0 -42
  92. package/src/runtime/middlewares/utils.ts +0 -72
  93. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  94. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  95. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  96. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  97. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  98. package/src/runtime/templates/home.ts +0 -746
  99. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  100. package/src/runtime/transports/http/cors/headers.ts +0 -58
  101. package/src/runtime/transports/http/cors/index.ts +0 -34
  102. package/src/runtime/transports/http/index.ts +0 -78
  103. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -311
  104. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  105. package/src/runtime/transports/stdio/index.ts +0 -109
  106. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  107. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  108. package/src/runtime/utils/client-info.ts +0 -114
  109. package/src/runtime/utils/elicitation.ts +0 -396
  110. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  111. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  112. package/src/runtime/utils/mcp-app-types.ts +0 -113
  113. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  114. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  115. package/src/runtime/utils/prompt-loader.ts +0 -151
  116. package/src/runtime/utils/prompts.ts +0 -69
  117. package/src/runtime/utils/react/generate-html.ts +0 -69
  118. package/src/runtime/utils/react/index.ts +0 -6
  119. package/src/runtime/utils/request-tool-names.ts +0 -48
  120. package/src/runtime/utils/resource-loader.ts +0 -151
  121. package/src/runtime/utils/resources.ts +0 -331
  122. package/src/runtime/utils/server.ts +0 -107
  123. package/src/runtime/utils/tool-loader.ts +0 -149
  124. package/src/runtime/utils/tools.ts +0 -183
  125. package/src/runtime/utils/transformers/prompt.ts +0 -120
  126. package/src/runtime/utils/transformers/resource.ts +0 -196
  127. package/src/runtime/utils/transformers/tool.ts +0 -400
  128. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  129. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  130. package/src/runtime/utils/ui/split-meta.ts +0 -78
  131. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  132. package/src/runtime/utils/validators/index.ts +0 -138
  133. package/src/telemetry/ci-info.ts +0 -6
  134. package/src/telemetry/debug.ts +0 -8
  135. package/src/telemetry/events/definitions.ts +0 -52
  136. package/src/telemetry/events/detached-flush.ts +0 -83
  137. package/src/telemetry/events/post-payload.ts +0 -141
  138. package/src/telemetry/events/tracker.ts +0 -281
  139. package/src/telemetry/index.ts +0 -7
  140. package/src/telemetry/metadata.ts +0 -49
  141. package/src/telemetry/project-id.ts +0 -35
  142. package/src/telemetry/storage.ts +0 -218
  143. package/src/types/adapter.d.ts +0 -5
  144. package/src/types/client-info.ts +0 -20
  145. package/src/types/declarations.ts +0 -37
  146. package/src/types/injected.d.ts +0 -62
  147. package/src/types/middleware.ts +0 -19
  148. package/src/types/prompt.ts +0 -6
  149. package/src/types/resource.ts +0 -15
  150. package/src/types/tool.ts +0 -192
  151. package/src/types/ui-meta.ts +0 -42
  152. package/src/utils/cli-icons.ts +0 -5
  153. package/src/utils/constants.ts +0 -31
  154. package/src/utils/context.ts +0 -105
  155. package/src/utils/detect-package-manager.ts +0 -46
  156. package/src/utils/file-watcher.ts +0 -66
  157. package/src/utils/fs-utils.ts +0 -16
  158. package/src/utils/path-validation.ts +0 -66
  159. package/src/utils/port-utils.ts +0 -43
  160. package/src/utils/spawn-process.ts +0 -49
  161. package/src/utils/subscribable.ts +0 -62
@@ -1,459 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert";
3
- import {
4
- getResolvedHttpConfig,
5
- getResolvedStdioConfig,
6
- getResolvedPathsConfig,
7
- getResolvedTemplateConfig,
8
- getResolvedTypescriptConfig,
9
- getResolvedExperimentalConfig,
10
- getResolvedCorsConfig,
11
- } from "../utils";
12
- import {
13
- injectHttpVariables,
14
- injectCorsVariables,
15
- injectPathsVariables,
16
- injectTemplateVariables,
17
- injectTypescriptVariables,
18
- injectAdapterVariables,
19
- injectStdioVariables,
20
- injectServerInfoVariables,
21
- } from "../injection";
22
- import { configSchema } from "../index";
23
-
24
- describe("Config System - Zod Defaults", () => {
25
- it("should apply defaults when parsing empty config", () => {
26
- const parsed = configSchema.parse({});
27
-
28
- // All fields should be optional, so empty object should be valid
29
- assert.equal(typeof parsed, "object");
30
- assert.equal(parsed !== null, true);
31
- });
32
-
33
- it("should apply HTTP transport defaults", () => {
34
- const parsed = configSchema.parse({ http: true });
35
- const resolved = getResolvedHttpConfig(parsed.http);
36
-
37
- assert.notEqual(resolved, null);
38
- if (resolved) {
39
- assert.equal(resolved.port, 3001);
40
- assert.equal(resolved.host, "127.0.0.1");
41
- assert.equal(resolved.endpoint, "/mcp");
42
- assert.equal(resolved.bodySizeLimit, 1024 * 1024 * 10);
43
- assert.equal(resolved.debug, false);
44
- assert.notEqual(resolved.cors, undefined);
45
- }
46
- });
47
-
48
- it("should apply template defaults", () => {
49
- const parsed = configSchema.parse({ template: {} });
50
- const resolved = getResolvedTemplateConfig(parsed);
51
-
52
- assert.equal(resolved.name, "xmcp server");
53
- assert.equal(
54
- resolved.description,
55
- "This MCP server was bootstrapped with xmcp."
56
- );
57
- });
58
-
59
- it("should apply TypeScript defaults", () => {
60
- const parsed = configSchema.parse({ typescript: {} });
61
- const resolved = getResolvedTypescriptConfig(parsed);
62
-
63
- assert.equal(resolved.skipTypeCheck, false);
64
- });
65
-
66
- it("should apply CORS defaults", () => {
67
- const httpConfig = getResolvedHttpConfig(true);
68
- assert.notEqual(httpConfig, null);
69
-
70
- if (httpConfig) {
71
- const corsConfig = getResolvedCorsConfig(httpConfig);
72
- assert.equal(corsConfig.origin, "*");
73
- assert.deepEqual(corsConfig.methods, ["GET", "POST"]);
74
- assert.deepEqual(corsConfig.allowedHeaders, [
75
- "Content-Type",
76
- "Authorization",
77
- "mcp-session-id",
78
- "mcp-protocol-version",
79
- "x-mcp-client-name",
80
- "x-mcp-client-version",
81
- "x-mcp-client-title",
82
- "x-mcp-client-website-url",
83
- "x-mcp-client-description",
84
- ]);
85
- assert.equal(corsConfig.credentials, false);
86
- assert.equal(corsConfig.maxAge, 86400);
87
- }
88
- });
89
-
90
- it("should preserve client info headers when merging CORS allowedHeaders arrays", () => {
91
- const httpConfig = getResolvedHttpConfig({
92
- cors: {
93
- allowedHeaders: ["Content-Type", "Authorization"],
94
- },
95
- });
96
- assert.notEqual(httpConfig, null);
97
-
98
- if (httpConfig) {
99
- const corsConfig = getResolvedCorsConfig(httpConfig);
100
- assert.deepEqual(corsConfig.allowedHeaders, [
101
- "Content-Type",
102
- "Authorization",
103
- "mcp-session-id",
104
- "mcp-protocol-version",
105
- "x-mcp-client-name",
106
- "x-mcp-client-version",
107
- "x-mcp-client-title",
108
- "x-mcp-client-website-url",
109
- "x-mcp-client-description",
110
- ]);
111
- }
112
- });
113
- });
114
-
115
- describe("Config System - Boolean Transformations", () => {
116
- it("should transform http: true to object with defaults", () => {
117
- const resolved = getResolvedHttpConfig(true);
118
-
119
- assert.notEqual(resolved, null);
120
- if (resolved) {
121
- assert.equal(typeof resolved, "object");
122
- assert.equal(resolved.port, 3001);
123
- assert.notEqual(resolved.cors, undefined);
124
- }
125
- });
126
-
127
- it("should transform http: false to null", () => {
128
- const resolved = getResolvedHttpConfig(false);
129
- assert.equal(resolved, null);
130
- });
131
-
132
- it("should transform stdio: true to object with defaults", () => {
133
- const config = configSchema.parse({ stdio: true });
134
- const resolved = getResolvedStdioConfig(config);
135
-
136
- assert.notEqual(resolved, null);
137
- if (resolved) {
138
- assert.equal(typeof resolved, "object");
139
- assert.equal(resolved.debug, false);
140
- }
141
- });
142
-
143
- it("should transform stdio: false to null", () => {
144
- const config = configSchema.parse({ stdio: false });
145
- const resolved = getResolvedStdioConfig(config);
146
-
147
- assert.equal(resolved, null);
148
- });
149
-
150
- it("should transform paths boolean to string or null", () => {
151
- const config1 = configSchema.parse({ paths: { tools: true } });
152
- const resolved1 = getResolvedPathsConfig(config1);
153
- assert.equal(resolved1.tools, "src/tools");
154
-
155
- const config2 = configSchema.parse({ paths: { tools: false } });
156
- const resolved2 = getResolvedPathsConfig(config2);
157
- assert.equal(resolved2.tools, null);
158
-
159
- const config3 = configSchema.parse({ paths: { tools: "custom/path" } });
160
- const resolved3 = getResolvedPathsConfig(config3);
161
- assert.equal(resolved3.tools, "custom/path");
162
- });
163
- });
164
-
165
- describe("Config System - Resolution Functions", () => {
166
- it("should resolve HTTP config with custom values", () => {
167
- const resolved = getResolvedHttpConfig({
168
- port: 8080,
169
- host: "0.0.0.0",
170
- });
171
-
172
- assert.notEqual(resolved, null);
173
- if (resolved) {
174
- assert.equal(resolved.port, 8080);
175
- assert.equal(resolved.host, "0.0.0.0");
176
- // Defaults should still apply
177
- assert.equal(resolved.endpoint, "/mcp");
178
- assert.notEqual(resolved.cors, undefined);
179
- }
180
- });
181
-
182
- it("should resolve paths config with all fields", () => {
183
- const config = configSchema.parse({
184
- paths: {
185
- tools: "custom/tools",
186
- prompts: "custom/prompts",
187
- resources: "custom/resources",
188
- },
189
- });
190
- const resolved = getResolvedPathsConfig(config);
191
-
192
- assert.equal(resolved.tools, "custom/tools");
193
- assert.equal(resolved.prompts, "custom/prompts");
194
- assert.equal(resolved.resources, "custom/resources");
195
- });
196
-
197
- it("should resolve experimental config and extract adapter", () => {
198
- const config = configSchema.parse({
199
- experimental: {
200
- adapter: "express",
201
- },
202
- });
203
- const resolved = getResolvedExperimentalConfig(config);
204
-
205
- assert.equal(resolved.adapter, "express");
206
- });
207
-
208
- it("should resolve fastify adapter", () => {
209
- const config = configSchema.parse({
210
- experimental: {
211
- adapter: "fastify",
212
- },
213
- });
214
- const resolved = getResolvedExperimentalConfig(config);
215
-
216
- assert.equal(resolved.adapter, "fastify");
217
- });
218
-
219
- it("should reject unknown adapter values", () => {
220
- assert.throws(() => {
221
- configSchema.parse({
222
- experimental: {
223
- adapter: "unknown-framework",
224
- },
225
- });
226
- });
227
- });
228
- });
229
-
230
- describe("Config System - Injection Functions", () => {
231
- it("should inject HTTP variables", () => {
232
- const variables = injectHttpVariables(true, "development");
233
-
234
- assert.notEqual(variables.HTTP_CONFIG, undefined);
235
- const config = JSON.parse(variables.HTTP_CONFIG!);
236
- assert.equal(config.port, 3001);
237
- assert.equal(config.debug, true); // mode === "development"
238
- });
239
-
240
- it("should not inject HTTP variables when http is false", () => {
241
- const variables = injectHttpVariables(false, "development");
242
- assert.deepEqual(variables, {});
243
- });
244
-
245
- it("should inject CORS variables", () => {
246
- const httpConfig = getResolvedHttpConfig(true);
247
- assert.notEqual(httpConfig, null);
248
-
249
- if (httpConfig) {
250
- const variables = injectCorsVariables(httpConfig);
251
- assert.notEqual(variables.HTTP_CORS_CONFIG, undefined);
252
- const cors = JSON.parse(variables.HTTP_CORS_CONFIG);
253
- assert.equal(cors.origin, "*");
254
- }
255
- });
256
-
257
- it("should inject all path variables when paths are configured", () => {
258
- const config = configSchema.parse({
259
- paths: {
260
- tools: "src/tools",
261
- prompts: "src/prompts",
262
- resources: "src/resources",
263
- },
264
- });
265
- const variables = injectPathsVariables(config);
266
-
267
- assert.notEqual(variables.TOOLS_PATH, undefined);
268
- assert.notEqual(variables.PROMPTS_PATH, undefined);
269
- assert.notEqual(variables.RESOURCES_PATH, undefined);
270
- assert.equal(JSON.parse(variables.TOOLS_PATH), "src/tools");
271
- });
272
-
273
- it("should only inject non-null path variables", () => {
274
- const config = configSchema.parse({
275
- paths: {
276
- tools: "src/tools",
277
- prompts: false,
278
- resources: false,
279
- },
280
- });
281
- const variables = injectPathsVariables(config);
282
-
283
- assert.notEqual(variables.TOOLS_PATH, undefined);
284
- assert.equal(variables.PROMPTS_PATH, undefined);
285
- assert.equal(variables.RESOURCES_PATH, undefined);
286
- });
287
-
288
- it("should inject template variables", () => {
289
- const config = configSchema.parse({ template: {} });
290
- const variables = injectTemplateVariables(config);
291
-
292
- assert.notEqual(variables.TEMPLATE_CONFIG, undefined);
293
- const template = JSON.parse(variables.TEMPLATE_CONFIG);
294
- assert.equal(template.name, "xmcp server");
295
- });
296
-
297
- it("should inject TypeScript variables", () => {
298
- const config = configSchema.parse({ typescript: {} });
299
- const variables = injectTypescriptVariables(config);
300
-
301
- assert.notEqual(variables.TYPESCRIPT_CONFIG, undefined);
302
- const ts = JSON.parse(variables.TYPESCRIPT_CONFIG);
303
- assert.equal(ts.skipTypeCheck, false);
304
- });
305
-
306
- it("should not inject adapter variables when adapter is undefined", () => {
307
- const config = configSchema.parse({});
308
- const variables = injectAdapterVariables(config);
309
-
310
- assert.deepEqual(variables, {});
311
- });
312
-
313
- it("should inject adapter variables when adapter is configured", () => {
314
- const config = configSchema.parse({
315
- experimental: {
316
- adapter: "nextjs",
317
- },
318
- });
319
- const variables = injectAdapterVariables(config);
320
-
321
- assert.notEqual(variables.ADAPTER_CONFIG, undefined);
322
- assert.equal(JSON.parse(variables.ADAPTER_CONFIG!), "nextjs");
323
- });
324
-
325
- it("should inject STDIO variables when stdio is configured", () => {
326
- const config = configSchema.parse({ stdio: { debug: true } });
327
- const variables = injectStdioVariables(config.stdio);
328
-
329
- assert.notEqual(variables.STDIO_CONFIG, undefined);
330
- const stdio = JSON.parse(variables.STDIO_CONFIG!);
331
- assert.equal(stdio.debug, true);
332
- });
333
-
334
- it("should not inject STDIO variables when stdio is undefined", () => {
335
- const variables = injectStdioVariables(undefined);
336
- assert.deepEqual(variables, {});
337
- });
338
-
339
- it("should inject server info with empty icons when icons not configured", () => {
340
- const config = configSchema.parse({ template: {} });
341
- const variables = injectServerInfoVariables(config);
342
-
343
- assert.notEqual(variables.SERVER_INFO, undefined);
344
- const serverInfo = JSON.parse(variables.SERVER_INFO);
345
- assert.equal(serverInfo.name, "xmcp server");
346
- assert.deepEqual(serverInfo.icons, []);
347
- });
348
-
349
- it("should inject server info with user-supplied icons", () => {
350
- const config = configSchema.parse({
351
- template: {
352
- name: "My Server",
353
- icons: [{ src: "https://example.com/icon.png", mimeType: "image/png" }],
354
- },
355
- });
356
- const variables = injectServerInfoVariables(config);
357
-
358
- const serverInfo = JSON.parse(variables.SERVER_INFO);
359
- assert.equal(serverInfo.name, "My Server");
360
- assert.deepEqual(serverInfo.icons, [
361
- { src: "https://example.com/icon.png", mimeType: "image/png" },
362
- ]);
363
- });
364
-
365
- it("should inject server info with version as a string", () => {
366
- const config = configSchema.parse({});
367
- const variables = injectServerInfoVariables(config);
368
-
369
- const serverInfo = JSON.parse(variables.SERVER_INFO);
370
- assert.equal(typeof serverInfo.version, "string");
371
- assert.notEqual(serverInfo.version, "");
372
- });
373
- });
374
-
375
- describe("Config System - Edge Cases", () => {
376
- it("should handle partial HTTP config", () => {
377
- const resolved = getResolvedHttpConfig({
378
- port: 8080,
379
- // Other fields should use defaults
380
- });
381
-
382
- assert.notEqual(resolved, null);
383
- if (resolved) {
384
- assert.equal(resolved.port, 8080);
385
- assert.equal(resolved.host, "127.0.0.1"); // default
386
- assert.equal(resolved.endpoint, "/mcp"); // default
387
- }
388
- });
389
-
390
- it("should handle undefined config gracefully", () => {
391
- const resolved = getResolvedHttpConfig(undefined);
392
- assert.equal(resolved, null);
393
- });
394
-
395
- it("should handle empty paths config", () => {
396
- const config = configSchema.parse({ paths: {} });
397
- const resolved = getResolvedPathsConfig(config);
398
-
399
- // Should use defaults (true -> default paths)
400
- assert.equal(resolved.tools, "src/tools");
401
- assert.equal(resolved.prompts, "src/prompts");
402
- assert.equal(resolved.resources, "src/resources");
403
- });
404
-
405
- it("should handle mixed boolean and string paths", () => {
406
- const config = configSchema.parse({
407
- paths: {
408
- tools: true,
409
- prompts: "custom/prompts",
410
- resources: false,
411
- },
412
- });
413
- const resolved = getResolvedPathsConfig(config);
414
-
415
- assert.equal(resolved.tools, "src/tools"); // true -> default
416
- assert.equal(resolved.prompts, "custom/prompts"); // string -> string
417
- assert.equal(resolved.resources, null); // false -> null
418
- });
419
-
420
- it("should ensure CORS is always present in resolved HTTP config", () => {
421
- const resolved = getResolvedHttpConfig({
422
- port: 3001,
423
- // cors not specified
424
- });
425
-
426
- assert.notEqual(resolved, null);
427
- if (resolved) {
428
- assert.notEqual(resolved.cors, undefined);
429
- assert.notEqual(resolved.cors, null);
430
- assert.equal(typeof resolved.cors, "object");
431
- }
432
- });
433
- });
434
-
435
- describe("Config System - Backward Compatibility", () => {
436
- it("should accept boolean http config (backward compatible)", () => {
437
- const resolved = getResolvedHttpConfig(true);
438
- assert.notEqual(resolved, null);
439
-
440
- const resolved2 = getResolvedHttpConfig(false);
441
- assert.equal(resolved2, null);
442
- });
443
-
444
- it("should accept boolean stdio config (backward compatible)", () => {
445
- const config = configSchema.parse({ stdio: true });
446
- const resolved = getResolvedStdioConfig(config);
447
- assert.notEqual(resolved, null);
448
-
449
- const config2 = configSchema.parse({ stdio: false });
450
- const resolved2 = getResolvedStdioConfig(config2);
451
- assert.equal(resolved2, null);
452
- });
453
-
454
- it("should accept boolean paths config (backward compatible)", () => {
455
- const config = configSchema.parse({ paths: { tools: true } });
456
- const resolved = getResolvedPathsConfig(config);
457
- assert.equal(resolved.tools, "src/tools");
458
- });
459
- });
@@ -1,62 +0,0 @@
1
- import { z } from "zod/v3";
2
- import {
3
- stdioTransportConfigSchema,
4
- httpTransportConfigSchema,
5
- experimentalConfigSchema,
6
- pathsConfigSchema,
7
- templateConfigSchema,
8
- typescriptConfigSchema,
9
- bundlerConfigSchema,
10
- } from "./schemas";
11
- import type { RspackOptions } from "@rspack/core";
12
-
13
- /**
14
- * xmcp Config schema
15
- */
16
- export const configSchema = z.object({
17
- stdio: stdioTransportConfigSchema.optional(),
18
- http: httpTransportConfigSchema.optional(),
19
- experimental: experimentalConfigSchema.optional(),
20
- paths: pathsConfigSchema.optional(),
21
- bundler: bundlerConfigSchema.optional(),
22
- template: templateConfigSchema.optional(),
23
- typescript: typescriptConfigSchema.optional(),
24
- });
25
-
26
- type BundlerConfigType = { bundler?: (config: RspackOptions) => RspackOptions };
27
-
28
- export type XmcpConfigInputSchema = Omit<
29
- z.input<typeof configSchema>,
30
- "bundler"
31
- > &
32
- BundlerConfigType;
33
-
34
- export type XmcpConfigOutputSchema = Omit<
35
- z.output<typeof configSchema>,
36
- "bundler"
37
- > &
38
- BundlerConfigType;
39
-
40
- // Re-export resolved types from utils (where they're defined)
41
- // Types are derived from resolution functions using ReturnType
42
- export type {
43
- ResolvedHttpConfig,
44
- ResolvedStdioConfig,
45
- ResolvedPathsConfig,
46
- ResolvedExperimentalConfig,
47
- } from "./utils";
48
-
49
- // Template, TypeScript, and CORS configs don't need resolved types
50
- // They can use Zod's output types directly: z.output<typeof templateConfigSchema>
51
-
52
- // Re-export all types from schemas
53
- export type {
54
- HttpTransportConfig,
55
- StdioTransportConfig,
56
- CorsConfig,
57
- ExperimentalConfig,
58
- PathsConfig,
59
- BundlerConfig,
60
- TemplateConfig,
61
- TypescriptConfig,
62
- } from "./schemas";