mcp-expose 1.0.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 (48) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE +21 -0
  3. package/README.md +708 -0
  4. package/dist/adonisjs/index.cjs +708 -0
  5. package/dist/adonisjs/index.cjs.map +1 -0
  6. package/dist/adonisjs/index.d.cts +68 -0
  7. package/dist/adonisjs/index.d.ts +68 -0
  8. package/dist/adonisjs/index.js +684 -0
  9. package/dist/adonisjs/index.js.map +1 -0
  10. package/dist/express/index.cjs +789 -0
  11. package/dist/express/index.cjs.map +1 -0
  12. package/dist/express/index.d.cts +61 -0
  13. package/dist/express/index.d.ts +61 -0
  14. package/dist/express/index.js +763 -0
  15. package/dist/express/index.js.map +1 -0
  16. package/dist/fastify/index.cjs +660 -0
  17. package/dist/fastify/index.cjs.map +1 -0
  18. package/dist/fastify/index.d.cts +42 -0
  19. package/dist/fastify/index.d.ts +42 -0
  20. package/dist/fastify/index.js +635 -0
  21. package/dist/fastify/index.js.map +1 -0
  22. package/dist/hono/index.cjs +656 -0
  23. package/dist/hono/index.cjs.map +1 -0
  24. package/dist/hono/index.d.cts +44 -0
  25. package/dist/hono/index.d.ts +44 -0
  26. package/dist/hono/index.js +630 -0
  27. package/dist/hono/index.js.map +1 -0
  28. package/dist/index.cjs +720 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.cts +81 -0
  31. package/dist/index.d.ts +81 -0
  32. package/dist/index.js +686 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/koa/index.cjs +739 -0
  35. package/dist/koa/index.cjs.map +1 -0
  36. package/dist/koa/index.d.cts +68 -0
  37. package/dist/koa/index.d.ts +68 -0
  38. package/dist/koa/index.js +709 -0
  39. package/dist/koa/index.js.map +1 -0
  40. package/dist/nestjs/index.cjs +1117 -0
  41. package/dist/nestjs/index.cjs.map +1 -0
  42. package/dist/nestjs/index.d.cts +104 -0
  43. package/dist/nestjs/index.d.ts +104 -0
  44. package/dist/nestjs/index.js +1079 -0
  45. package/dist/nestjs/index.js.map +1 -0
  46. package/dist/server-fzkb-wJo.d.cts +194 -0
  47. package/dist/server-fzkb-wJo.d.ts +194 -0
  48. package/package.json +225 -0
@@ -0,0 +1,630 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/core/dispatch.ts
5
+ function buildUrl(base, req) {
6
+ const url = new URL(base.replace(/\/+$/, "") + req.path);
7
+ for (const [k, v] of Object.entries(req.query)) {
8
+ for (const item of Array.isArray(v) ? v : [
9
+ v
10
+ ]) url.searchParams.append(k, item);
11
+ }
12
+ return url.toString();
13
+ }
14
+ __name(buildUrl, "buildUrl");
15
+
16
+ // src/core/marker.ts
17
+ var MCP_TOOL = /* @__PURE__ */ Symbol.for("mcp-expose.tool");
18
+ function markerOf(fn) {
19
+ return typeof fn === "function" ? fn[MCP_TOOL] : void 0;
20
+ }
21
+ __name(markerOf, "markerOf");
22
+ function mark(fn, opts) {
23
+ Object.defineProperty(fn, MCP_TOOL, {
24
+ value: opts,
25
+ enumerable: false
26
+ });
27
+ return fn;
28
+ }
29
+ __name(mark, "mark");
30
+
31
+ // src/core/schema.ts
32
+ function isStandard(s) {
33
+ return typeof s === "object" && s !== null && "~standard" in s;
34
+ }
35
+ __name(isStandard, "isStandard");
36
+ function toJsonSchema(schema) {
37
+ if (schema === void 0 || schema === null) return void 0;
38
+ let out;
39
+ if (isStandard(schema) && typeof schema["~standard"].jsonSchema?.input === "function") {
40
+ out = schema["~standard"].jsonSchema.input({
41
+ target: "draft-2020-12"
42
+ });
43
+ } else if (typeof schema.toJSONSchema === "function") {
44
+ out = schema.toJSONSchema();
45
+ } else if (isStandard(schema)) {
46
+ throw new Error("mcp-expose: this schema library does not support JSON Schema export. Pass a plain JSON Schema instead.");
47
+ } else {
48
+ out = schema;
49
+ }
50
+ const { $schema: _ignored, ...rest } = out;
51
+ return rest;
52
+ }
53
+ __name(toJsonSchema, "toJsonSchema");
54
+ function toValidator(schema) {
55
+ if (!isStandard(schema) || typeof schema["~standard"].validate !== "function") return void 0;
56
+ const validate = schema["~standard"].validate;
57
+ return async (value) => {
58
+ const result = await validate(value);
59
+ if (!result.issues) return {
60
+ ok: true,
61
+ value: result.value
62
+ };
63
+ const message = result.issues.map((i) => {
64
+ const path = (i.path ?? []).map((p) => typeof p === "object" ? String(p.key) : String(p)).join(".");
65
+ return path ? `${path}: ${i.message}` : i.message;
66
+ }).join("; ");
67
+ return {
68
+ ok: false,
69
+ message
70
+ };
71
+ };
72
+ }
73
+ __name(toValidator, "toValidator");
74
+ function checkRequired(schema, args) {
75
+ const missing = (schema.required ?? []).filter((k) => args[k] === void 0);
76
+ return missing.length ? `Missing required argument(s): ${missing.join(", ")}` : void 0;
77
+ }
78
+ __name(checkRequired, "checkRequired");
79
+
80
+ // src/core/route-tool.ts
81
+ var DEFAULT_FORWARD_HEADERS = [
82
+ "authorization",
83
+ "cookie",
84
+ "x-api-key",
85
+ "accept-language"
86
+ ];
87
+ var BODY_METHODS = /* @__PURE__ */ new Set([
88
+ "POST",
89
+ "PUT",
90
+ "PATCH"
91
+ ]);
92
+ var PARAM_RE = /:([A-Za-z0-9_]+)\??|\{([A-Za-z0-9_]+)\}/g;
93
+ function pathParams(path) {
94
+ return [
95
+ ...path.matchAll(PARAM_RE)
96
+ ].map((m) => m[1] ?? m[2]);
97
+ }
98
+ __name(pathParams, "pathParams");
99
+ function encodeSegment(name, value) {
100
+ const raw = String(value);
101
+ if (raw === "" || raw === "." || raw === "..") {
102
+ throw new Error(`Invalid value for path parameter "${name}": ${JSON.stringify(raw)}`);
103
+ }
104
+ return encodeURIComponent(raw);
105
+ }
106
+ __name(encodeSegment, "encodeSegment");
107
+ function interpolatePath(path, values) {
108
+ return path.replace(/\/:([A-Za-z0-9_]+)\?/g, (_, k) => values[k] === void 0 ? "" : `/${encodeSegment(k, values[k])}`).replace(PARAM_RE, (_, a, b) => {
109
+ const k = a ?? b;
110
+ return encodeSegment(k, values[k]);
111
+ });
112
+ }
113
+ __name(interpolatePath, "interpolatePath");
114
+ function toolNameFromRoute(method, path) {
115
+ const segments = path.split("/").filter(Boolean).map((s) => {
116
+ const m = /^(?::([A-Za-z0-9_]+)\??|\{([A-Za-z0-9_]+)\})$/.exec(s);
117
+ return m ? `by_${m[1] ?? m[2]}` : s;
118
+ });
119
+ return sanitizeToolName([
120
+ method.toLowerCase(),
121
+ ...segments
122
+ ].join("_"));
123
+ }
124
+ __name(toolNameFromRoute, "toolNameFromRoute");
125
+ function sanitizeToolName(name) {
126
+ return name.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "").slice(0, 64);
127
+ }
128
+ __name(sanitizeToolName, "sanitizeToolName");
129
+ function defaultAnnotations(method) {
130
+ switch (method) {
131
+ case "GET":
132
+ case "HEAD":
133
+ return {
134
+ readOnlyHint: true,
135
+ openWorldHint: false
136
+ };
137
+ case "DELETE":
138
+ return {
139
+ readOnlyHint: false,
140
+ destructiveHint: true,
141
+ idempotentHint: true,
142
+ openWorldHint: false
143
+ };
144
+ case "PUT":
145
+ return {
146
+ readOnlyHint: false,
147
+ destructiveHint: false,
148
+ idempotentHint: true,
149
+ openWorldHint: false
150
+ };
151
+ default:
152
+ return {
153
+ readOnlyHint: false,
154
+ destructiveHint: false,
155
+ openWorldHint: false
156
+ };
157
+ }
158
+ }
159
+ __name(defaultAnnotations, "defaultAnnotations");
160
+ function buildInputSchema(route, opts) {
161
+ const method = route.method.toUpperCase();
162
+ const params = pathParams(route.path);
163
+ const mapping = {
164
+ params,
165
+ query: /* @__PURE__ */ new Set(),
166
+ body: /* @__PURE__ */ new Set(),
167
+ wholeBody: false,
168
+ bodyMethod: BODY_METHODS.has(method)
169
+ };
170
+ if (opts.input) {
171
+ const schema2 = toJsonSchema(opts.input);
172
+ return {
173
+ schema: {
174
+ type: "object",
175
+ ...schema2
176
+ },
177
+ mapping
178
+ };
179
+ }
180
+ const properties = {};
181
+ const required = /* @__PURE__ */ new Set();
182
+ const paramSchema = toJsonSchema(opts.params);
183
+ for (const p of params) {
184
+ properties[p] = paramSchema?.properties?.[p] ?? {
185
+ type: "string",
186
+ description: `Path parameter "${p}"`
187
+ };
188
+ if (!route.path.includes(`:${p}?`)) required.add(p);
189
+ }
190
+ const querySchema = toJsonSchema(opts.query);
191
+ for (const [k, v] of Object.entries(querySchema?.properties ?? {})) {
192
+ properties[k] = v;
193
+ mapping.query.add(k);
194
+ }
195
+ for (const k of querySchema?.required ?? []) required.add(k);
196
+ const bodySchema = toJsonSchema(opts.body);
197
+ if (bodySchema) {
198
+ if (bodySchema.properties && (bodySchema.type === void 0 || bodySchema.type === "object")) {
199
+ for (const [k, v] of Object.entries(bodySchema.properties)) {
200
+ properties[k] = v;
201
+ mapping.body.add(k);
202
+ }
203
+ for (const k of bodySchema.required ?? []) required.add(k);
204
+ } else {
205
+ properties.body = bodySchema;
206
+ required.add("body");
207
+ mapping.wholeBody = true;
208
+ }
209
+ }
210
+ const schema = {
211
+ type: "object",
212
+ properties
213
+ };
214
+ if (required.size) schema.required = [
215
+ ...required
216
+ ];
217
+ return {
218
+ schema,
219
+ mapping
220
+ };
221
+ }
222
+ __name(buildInputSchema, "buildInputSchema");
223
+ function splitArgs(args, mapping) {
224
+ const pathValues = {};
225
+ const query = {};
226
+ let body;
227
+ for (const [k, v] of Object.entries(args)) {
228
+ if (v === void 0) continue;
229
+ if (mapping.params.includes(k)) {
230
+ pathValues[k] = v;
231
+ } else if (mapping.wholeBody && k === "body") {
232
+ body = v;
233
+ } else if (mapping.query.has(k) || !mapping.body.has(k) && !mapping.bodyMethod) {
234
+ query[k] = Array.isArray(v) ? v.map(String) : typeof v === "object" && v !== null ? JSON.stringify(v) : String(v);
235
+ } else {
236
+ body = {
237
+ ...body ?? {},
238
+ [k]: v
239
+ };
240
+ }
241
+ }
242
+ if (body === void 0 && mapping.bodyMethod) body = {};
243
+ return {
244
+ pathValues,
245
+ query,
246
+ body
247
+ };
248
+ }
249
+ __name(splitArgs, "splitArgs");
250
+ function responseToResult(res, maxChars) {
251
+ let text = res.body;
252
+ if (text.length > maxChars) text = `${text.slice(0, maxChars)}
253
+ \u2026[truncated ${text.length - maxChars} chars]`;
254
+ const isError = res.status >= 400;
255
+ const result = {
256
+ content: [
257
+ {
258
+ type: "text",
259
+ text: isError ? `HTTP ${res.status}
260
+ ${text}` : text || `HTTP ${res.status}`
261
+ }
262
+ ]
263
+ };
264
+ if (isError) {
265
+ result.isError = true;
266
+ return result;
267
+ }
268
+ if ((res.headers["content-type"] ?? "").includes("json") && text === res.body) {
269
+ try {
270
+ const parsed = JSON.parse(res.body);
271
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) result.structuredContent = parsed;
272
+ } catch {
273
+ }
274
+ }
275
+ return result;
276
+ }
277
+ __name(responseToResult, "responseToResult");
278
+ function pickForwardHeaders(ctx, names) {
279
+ const out = {};
280
+ for (const name of names) {
281
+ const v = ctx.headers[name.toLowerCase()];
282
+ if (v !== void 0) out[name.toLowerCase()] = v;
283
+ }
284
+ return out;
285
+ }
286
+ __name(pickForwardHeaders, "pickForwardHeaders");
287
+ function createRouteTool(route, opts, dispatch, serverOpts = {}) {
288
+ const method = route.method.toUpperCase();
289
+ const name = sanitizeToolName(opts.name ?? toolNameFromRoute(method, route.path));
290
+ const { schema, mapping } = buildInputSchema(route, opts);
291
+ const forward = serverOpts.forwardHeaders ?? DEFAULT_FORWARD_HEADERS;
292
+ const maxChars = serverOpts.maxResponseChars ?? 1e5;
293
+ return {
294
+ name,
295
+ title: opts.title,
296
+ description: opts.description ?? `${method} ${route.path}`,
297
+ inputSchema: schema,
298
+ annotations: {
299
+ ...defaultAnnotations(method),
300
+ ...opts.annotations
301
+ },
302
+ validate: toValidator(opts.input),
303
+ async handler(args, ctx) {
304
+ const missing = opts.input ? void 0 : checkRequired(schema, args);
305
+ if (missing) return {
306
+ isError: true,
307
+ content: [
308
+ {
309
+ type: "text",
310
+ text: missing
311
+ }
312
+ ]
313
+ };
314
+ const { pathValues, query, body } = splitArgs(args, mapping);
315
+ const headers = {
316
+ accept: "application/json",
317
+ ...pickForwardHeaders(ctx, forward),
318
+ ...opts.headers,
319
+ "x-mcp-tool": name
320
+ };
321
+ if (ctx.clientIp) headers["x-forwarded-for"] = ctx.clientIp;
322
+ if (body !== void 0) headers["content-type"] = "application/json";
323
+ let path;
324
+ try {
325
+ path = interpolatePath(route.path, pathValues);
326
+ } catch (err) {
327
+ return {
328
+ isError: true,
329
+ content: [
330
+ {
331
+ type: "text",
332
+ text: err.message
333
+ }
334
+ ]
335
+ };
336
+ }
337
+ const res = await dispatch({
338
+ method,
339
+ path,
340
+ query,
341
+ body,
342
+ headers
343
+ }, ctx);
344
+ return responseToResult(res, maxChars);
345
+ }
346
+ };
347
+ }
348
+ __name(createRouteTool, "createRouteTool");
349
+
350
+ // src/core/server.ts
351
+ var SUPPORTED_PROTOCOL_VERSIONS = [
352
+ "2025-11-25",
353
+ "2025-06-18",
354
+ "2025-03-26",
355
+ "2024-11-05"
356
+ ];
357
+ var LATEST_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0];
358
+ var PARSE_ERROR = -32700;
359
+ var INVALID_REQUEST = -32600;
360
+ var METHOD_NOT_FOUND = -32601;
361
+ var INVALID_PARAMS = -32602;
362
+ var ok = /* @__PURE__ */ __name((id, result) => ({
363
+ jsonrpc: "2.0",
364
+ id,
365
+ result
366
+ }), "ok");
367
+ var fail = /* @__PURE__ */ __name((id, code, message) => ({
368
+ jsonrpc: "2.0",
369
+ id,
370
+ error: {
371
+ code,
372
+ message
373
+ }
374
+ }), "fail");
375
+ var McpServer = class {
376
+ static {
377
+ __name(this, "McpServer");
378
+ }
379
+ options;
380
+ tools = /* @__PURE__ */ new Map();
381
+ loaders = [];
382
+ constructor(options) {
383
+ this.options = options;
384
+ }
385
+ /** Register a tool. Throws on duplicate names. */
386
+ addTool(tool) {
387
+ if (this.tools.has(tool.name)) {
388
+ throw new Error(`mcp-expose: duplicate tool name "${tool.name}". Set an explicit \`name\`.`);
389
+ }
390
+ this.tools.set(tool.name, tool);
391
+ return this;
392
+ }
393
+ /** Register a function that adds tools lazily, right before the first MCP request is served. */
394
+ onLoad(loader) {
395
+ this.loaders.push(loader);
396
+ return this;
397
+ }
398
+ async listTools() {
399
+ await this.load();
400
+ return [
401
+ ...this.tools.values()
402
+ ];
403
+ }
404
+ async load() {
405
+ if (!this.loaders.length) return;
406
+ const loaders = this.loaders;
407
+ this.loaders = [];
408
+ for (const l of loaders) await l();
409
+ }
410
+ /** Handle one JSON-RPC message (or a batch). Returns null when no response is due. */
411
+ async handleMessage(message, ctx) {
412
+ if (Array.isArray(message)) {
413
+ const results = (await Promise.all(message.map((m) => this.handleOne(m, ctx)))).filter((r) => r !== null);
414
+ return results.length ? results : null;
415
+ }
416
+ return this.handleOne(message, ctx);
417
+ }
418
+ async handleOne(message, ctx) {
419
+ const msg = message;
420
+ if (!msg || typeof msg !== "object" || msg.jsonrpc !== "2.0") {
421
+ return fail(null, INVALID_REQUEST, "Invalid JSON-RPC message");
422
+ }
423
+ if (typeof msg.method !== "string" || msg.id === void 0) return null;
424
+ const id = msg.id;
425
+ const params = msg.params ?? {};
426
+ await this.load();
427
+ switch (msg.method) {
428
+ case "initialize": {
429
+ const requested = params.protocolVersion;
430
+ const protocolVersion = requested && SUPPORTED_PROTOCOL_VERSIONS.includes(requested) ? requested : LATEST_PROTOCOL_VERSION;
431
+ return ok(id, {
432
+ protocolVersion,
433
+ capabilities: {
434
+ tools: {
435
+ listChanged: false
436
+ }
437
+ },
438
+ serverInfo: {
439
+ name: this.options.name,
440
+ version: this.options.version ?? "1.0.0"
441
+ },
442
+ ...this.options.instructions ? {
443
+ instructions: this.options.instructions
444
+ } : {}
445
+ });
446
+ }
447
+ case "ping":
448
+ return ok(id, {});
449
+ case "tools/list":
450
+ return ok(id, {
451
+ tools: [
452
+ ...this.tools.values()
453
+ ].map((t) => ({
454
+ name: t.name,
455
+ ...t.title ? {
456
+ title: t.title
457
+ } : {},
458
+ description: t.description,
459
+ inputSchema: t.inputSchema,
460
+ ...t.annotations ? {
461
+ annotations: t.annotations
462
+ } : {}
463
+ }))
464
+ });
465
+ case "tools/call": {
466
+ const tool = this.tools.get(params.name);
467
+ if (!tool) return fail(id, INVALID_PARAMS, `Unknown tool: ${String(params.name)}`);
468
+ return ok(id, await this.callTool(tool, params.arguments ?? {}, ctx));
469
+ }
470
+ case "resources/list":
471
+ return ok(id, {
472
+ resources: []
473
+ });
474
+ case "prompts/list":
475
+ return ok(id, {
476
+ prompts: []
477
+ });
478
+ default:
479
+ return fail(id, METHOD_NOT_FOUND, `Method not found: ${msg.method}`);
480
+ }
481
+ }
482
+ async callTool(tool, args, ctx) {
483
+ try {
484
+ if (tool.validate) {
485
+ const v = await tool.validate(args);
486
+ if (!v.ok) return {
487
+ isError: true,
488
+ content: [
489
+ {
490
+ type: "text",
491
+ text: `Invalid arguments: ${v.message}`
492
+ }
493
+ ]
494
+ };
495
+ args = v.value;
496
+ }
497
+ return await tool.handler(args, ctx);
498
+ } catch (err) {
499
+ return {
500
+ isError: true,
501
+ content: [
502
+ {
503
+ type: "text",
504
+ text: `Tool error: ${err.message}`
505
+ }
506
+ ]
507
+ };
508
+ }
509
+ }
510
+ /** Check the Origin header (DNS rebinding protection). */
511
+ isOriginAllowed(origin) {
512
+ if (!origin) return true;
513
+ const allowed = this.options.allowedOrigins;
514
+ if (allowed === "*") return true;
515
+ return (allowed ?? []).includes(origin);
516
+ }
517
+ /**
518
+ * Framework-neutral Streamable HTTP handler. Adapters convert their request
519
+ * into McpHttpRequest, call this, and write the McpHttpResponse back.
520
+ */
521
+ async handleHttp(req, ctx) {
522
+ const json = {
523
+ "content-type": "application/json"
524
+ };
525
+ if (!this.isOriginAllowed(req.headers.origin)) {
526
+ return {
527
+ status: 403,
528
+ headers: json,
529
+ body: JSON.stringify(fail(null, INVALID_REQUEST, "Origin not allowed"))
530
+ };
531
+ }
532
+ if (req.method.toUpperCase() !== "POST") {
533
+ return {
534
+ status: 405,
535
+ headers: {
536
+ allow: "POST"
537
+ }
538
+ };
539
+ }
540
+ let body = req.body;
541
+ if (typeof body === "string" || body instanceof Uint8Array) {
542
+ try {
543
+ body = JSON.parse(typeof body === "string" ? body : new TextDecoder().decode(body));
544
+ } catch {
545
+ return {
546
+ status: 400,
547
+ headers: json,
548
+ body: JSON.stringify(fail(null, PARSE_ERROR, "Parse error"))
549
+ };
550
+ }
551
+ }
552
+ const response = await this.handleMessage(body, ctx);
553
+ if (response === null) return {
554
+ status: 202,
555
+ headers: {}
556
+ };
557
+ return {
558
+ status: 200,
559
+ headers: json,
560
+ body: JSON.stringify(response)
561
+ };
562
+ }
563
+ };
564
+
565
+ // src/hono/index.ts
566
+ function mcpTool(options = {}) {
567
+ return mark(async (_c, next) => {
568
+ await next();
569
+ }, options);
570
+ }
571
+ __name(mcpTool, "mcpTool");
572
+ function mountMcp(app, options) {
573
+ const path = options.path ?? "/mcp";
574
+ const server = new McpServer(options);
575
+ const dispatch = /* @__PURE__ */ __name(async (req, ctx) => {
576
+ const res = await app.request(buildUrl("http://localhost", req), {
577
+ method: req.method,
578
+ headers: req.headers,
579
+ body: req.body === void 0 ? void 0 : JSON.stringify(req.body)
580
+ }, ctx.raw?.env);
581
+ const headers = {};
582
+ res.headers.forEach((v, k) => headers[k] = v);
583
+ return {
584
+ status: res.status,
585
+ headers,
586
+ body: await res.text()
587
+ };
588
+ }, "dispatch");
589
+ for (const t of options.tools ?? []) server.addTool(t);
590
+ server.onLoad(() => {
591
+ const seen = /* @__PURE__ */ new Set();
592
+ for (const r of app.routes) {
593
+ const marker = markerOf(r.handler);
594
+ const key = `${r.method} ${r.path}`;
595
+ if (!marker || seen.has(key) || r.method === "ALL") continue;
596
+ seen.add(key);
597
+ server.addTool(createRouteTool({
598
+ method: r.method,
599
+ path: r.path
600
+ }, marker, dispatch, options));
601
+ }
602
+ for (const r of options.routes ?? []) server.addTool(createRouteTool(r, r, dispatch, options));
603
+ });
604
+ app.all(path, async (c) => {
605
+ const request = c.req.raw ?? c.req;
606
+ const headers = {};
607
+ request.headers.forEach((v, k) => headers[k] = v);
608
+ const ctx = {
609
+ headers,
610
+ raw: c
611
+ };
612
+ const body = c.req.method === "POST" ? await request.text() : void 0;
613
+ const out = await server.handleHttp({
614
+ method: c.req.method,
615
+ headers,
616
+ body
617
+ }, ctx);
618
+ return new Response(out.body ?? null, {
619
+ status: out.status,
620
+ headers: out.headers
621
+ });
622
+ });
623
+ return server;
624
+ }
625
+ __name(mountMcp, "mountMcp");
626
+ export {
627
+ mcpTool,
628
+ mountMcp
629
+ };
630
+ //# sourceMappingURL=index.js.map