@ttoss/http-server-mcp-openapi 0.8.8 → 0.9.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/dist/index.cjs CHANGED
@@ -494,7 +494,7 @@ var managedFields = flag => {
494
494
  var extractPathParams = args => {
495
495
  const toArgName = args.toArgName ?? snakeToCamel;
496
496
  const flag = args.serverManagedExtension ?? "x-mcp-server-managed";
497
- return dedupeByName((args.parameters || []).map(p => {
497
+ const params = (args.parameters || []).map(p => {
498
498
  return resolveParameter(p, args.spec, args.documents);
499
499
  }).filter(p => {
500
500
  return p.in === "path";
@@ -509,12 +509,13 @@ var extractPathParams = args => {
509
509
  extension: flag
510
510
  }))
511
511
  };
512
- }));
512
+ });
513
+ return dedupeByName(params);
513
514
  };
514
515
  var extractQueryParams = args => {
515
516
  const toArgName = args.toArgName ?? snakeToCamel;
516
517
  const flag = args.serverManagedExtension ?? "x-mcp-server-managed";
517
- return dedupeByName((args.parameters || []).map(p => {
518
+ const params = (args.parameters || []).map(p => {
518
519
  return resolveParameter(p, args.spec, args.documents);
519
520
  }).filter(p => {
520
521
  return p.in === "query";
@@ -533,7 +534,8 @@ var extractQueryParams = args => {
533
534
  extension: flag
534
535
  }))
535
536
  };
536
- }));
537
+ });
538
+ return dedupeByName(params);
537
539
  };
538
540
  var collectServerManagedParameters = args => {
539
541
  return [...args.pathParams.map(p => {
@@ -564,7 +566,8 @@ var collectServerManagedParameters = args => {
564
566
  //#region src/body.ts
565
567
  var resolveBodySchema = args => {
566
568
  const rawBodySchema = args.requestBody?.content?.["application/json"]?.schema;
567
- return resolveSchema(dereferenceSchema(rawBodySchema, args.spec, args.documents), args.spec, args.documents);
569
+ const dereferencedBodySchema = dereferenceSchema(rawBodySchema, args.spec, args.documents);
570
+ return resolveSchema(dereferencedBodySchema, args.spec, args.documents);
568
571
  };
569
572
  /**
570
573
  * snake_case names of every top-level property an operation's request schema
@@ -654,10 +657,10 @@ var extractPinnedBody = args => {
654
657
  var isRecord = value => {
655
658
  return typeof value === "object" && value !== null && !Array.isArray(value);
656
659
  };
657
- var OPENAPI_ONLY_KEYWORDS = new Set(["discriminator", "example", "externalDocs", "xml"]);
658
- var SCHEMA_MAPS = new Set(["$defs", "definitions", "dependentSchemas", "patternProperties", "properties"]);
659
- var SCHEMA_VALUES = new Set(["additionalProperties", "contains", "else", "if", "items", "not", "propertyNames", "then", "unevaluatedItems", "unevaluatedProperties"]);
660
- var SCHEMA_LISTS = new Set(["anyOf", "oneOf", "prefixItems"]);
660
+ var OPENAPI_ONLY_KEYWORDS = /* @__PURE__ */new Set(["discriminator", "example", "externalDocs", "xml"]);
661
+ var SCHEMA_MAPS = /* @__PURE__ */new Set(["$defs", "definitions", "dependentSchemas", "patternProperties", "properties"]);
662
+ var SCHEMA_VALUES = /* @__PURE__ */new Set(["additionalProperties", "contains", "else", "if", "items", "not", "propertyNames", "then", "unevaluatedItems", "unevaluatedProperties"]);
663
+ var SCHEMA_LISTS = /* @__PURE__ */new Set(["anyOf", "oneOf", "prefixItems"]);
661
664
  /**
662
665
  * OpenAPI 3.0's `nullable: true` in JSON Schema: `'null'` joins the `type`,
663
666
  * and `null` joins an `enum`, which would otherwise still refuse it.
@@ -836,8 +839,9 @@ var createInProcessCallApi = ({
836
839
  toError = defaultToError
837
840
  }) => {
838
841
  return async request => {
842
+ const target = typeof app === "function" ? await app() : app;
839
843
  const response = await (0, _ttoss_http_server.dispatchInProcess)({
840
- app: typeof app === "function" ? await app() : app,
844
+ app: target,
841
845
  method: request.method,
842
846
  path: request.url,
843
847
  headers: {
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  import { JsonObjectSchema, Tool } from "@ttoss/http-server-mcp";
3
3
  import { App, InProcessResponse } from "@ttoss/http-server";
4
-
5
4
  //#region src/types.d.ts
6
5
  /** The JSON Schema primitive types this generator can derive from an OpenAPI `type`. */
7
6
  type JsonSchemaPrimitiveType = 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
@@ -134,8 +133,10 @@ interface OperationSpec {
134
133
  name?: string;
135
134
  in?: string;
136
135
  required?: boolean;
137
- description?: string; /** Query serialisation style, e.g. `form` (default) or `deepObject`. */
138
- style?: string; /** Whether each value gets its own key. Defaults to `true` for `form`. */
136
+ description?: string;
137
+ /** Query serialisation style, e.g. `form` (default) or `deepObject`. */
138
+ style?: string;
139
+ /** Whether each value gets its own key. Defaults to `true` for `form`. */
139
140
  explode?: boolean;
140
141
  schema?: {
141
142
  type?: string;
@@ -217,15 +218,16 @@ interface OpenApiToToolsOptions {
217
218
  * ```
218
219
  */
219
220
  describe?: (args: {
220
- operation: OperationSpec; /** Uppercase HTTP method. */
221
+ operation: OperationSpec;
222
+ /** Uppercase HTTP method. */
221
223
  method: string;
222
224
  pathTemplate: string;
223
225
  }) => string;
224
226
  }
225
227
  /** {@link OpenApiToToolsOptions} with every default applied. */
226
228
  type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>> & Pick<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>;
227
- declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
228
- declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
229
+ export declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
230
+ export declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
229
231
  //#endregion
230
232
  //#region src/serverManaged.d.ts
231
233
  /** One extension name, or several that all mean "the server sets this". */
@@ -237,7 +239,7 @@ type ServerManagedExtension = string | string[];
237
239
  * names may be snake_case (`agent_id`) or kebab-case (`list-tools`); with the
238
240
  * default `argumentNames: 'camelCase'` both are folded into tool arguments.
239
241
  */
240
- declare const snakeToCamel: (str: string) => string;
242
+ export declare const snakeToCamel: (str: string) => string;
241
243
  /** Maps a spec parameter or property name to a tool argument name. */
242
244
  type ToArgName = (name: string) => string;
243
245
  /** Arguments shared by the parameter extractors. */
@@ -247,25 +249,30 @@ type ExtractParamsArgs = {
247
249
  in?: string;
248
250
  [key: string]: unknown;
249
251
  }>;
250
- spec: OpenApiSpec; /** Sibling documents cross-file `$ref`s resolve against. */
251
- documents?: OpenApiDocuments; /** Maps a spec name to its tool argument name. @default snakeToCamel */
252
- toArgName?: ToArgName; /** @default DEFAULT_SERVER_MANAGED_EXTENSION */
252
+ spec: OpenApiSpec;
253
+ /** Sibling documents cross-file `$ref`s resolve against. */
254
+ documents?: OpenApiDocuments;
255
+ /** Maps a spec name to its tool argument name. @default snakeToCamel */
256
+ toArgName?: ToArgName;
257
+ /** @default DEFAULT_SERVER_MANAGED_EXTENSION */
253
258
  serverManagedExtension?: ServerManagedExtension;
254
259
  };
255
- declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
260
+ export declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
256
261
  name: string;
257
262
  argName: string;
258
- description?: string; /** The parameter's schema with every `$ref` inlined. */
263
+ description?: string;
264
+ /** The parameter's schema with every `$ref` inlined. */
259
265
  schema?: Record<string, unknown>;
260
266
  serverManaged: boolean;
261
267
  pinnedValue?: string;
262
268
  }>;
263
- declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
269
+ export declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
264
270
  name: string;
265
271
  argName: string;
266
272
  description: string;
267
273
  required: boolean;
268
- type: string; /** The parameter's schema with every `$ref` inlined. */
274
+ type: string;
275
+ /** The parameter's schema with every `$ref` inlined. */
269
276
  schema?: Record<string, unknown>;
270
277
  style?: string;
271
278
  explode?: boolean;
@@ -278,16 +285,17 @@ declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
278
285
  * snake_case names of every top-level property an operation's request schema
279
286
  * declares, including server-managed ones.
280
287
  */
281
- declare const extractAcceptedBodyFields: (args: {
288
+ export declare const extractAcceptedBodyFields: (args: {
282
289
  requestBody?: RequestBodySpec;
283
290
  spec: OpenApiSpec;
284
291
  documents?: OpenApiDocuments;
285
292
  }) => string[];
286
- declare const extractBodyProps: (args: {
293
+ export declare const extractBodyProps: (args: {
287
294
  requestBody?: RequestBodySpec;
288
295
  spec: OpenApiSpec;
289
296
  serverManagedExtension: ServerManagedExtension;
290
- documents?: OpenApiDocuments; /** Maps a spec name to its tool argument name. @default snakeToCamel */
297
+ documents?: OpenApiDocuments;
298
+ /** Maps a spec name to its tool argument name. @default snakeToCamel */
291
299
  toArgName?: ToArgName;
292
300
  }) => Array<{
293
301
  snakeName: string;
@@ -299,7 +307,8 @@ declare const extractBodyProps: (args: {
299
307
  nullable: boolean;
300
308
  oneOf?: unknown[];
301
309
  anyOf?: unknown[];
302
- allOf?: unknown[]; /** The property's whole schema, with every `$ref` inlined. */
310
+ allOf?: unknown[];
311
+ /** The property's whole schema, with every `$ref` inlined. */
303
312
  schema: Record<string, unknown>;
304
313
  }>;
305
314
  /**
@@ -307,7 +316,7 @@ declare const extractBodyProps: (args: {
307
316
  * keyed by its spec name. A property whose extension is not a string pins
308
317
  * nothing: it is only hidden, for the consumer to fill.
309
318
  */
310
- declare const extractPinnedBody: (args: {
319
+ export declare const extractPinnedBody: (args: {
311
320
  requestBody?: RequestBodySpec;
312
321
  spec: OpenApiSpec;
313
322
  serverManagedExtension: ServerManagedExtension;
@@ -324,7 +333,7 @@ declare const extractPinnedBody: (args: {
324
333
  * merged, `nullable` becomes a `'null'` type, and OpenAPI-only keywords and
325
334
  * `x-` extensions are dropped. Descriptions are kept verbatim.
326
335
  */
327
- declare const toToolSchema: (value: unknown) => unknown;
336
+ export declare const toToolSchema: (value: unknown) => unknown;
328
337
  type FullParam = {
329
338
  argName: string;
330
339
  required?: boolean;
@@ -342,7 +351,7 @@ type FullBodyProp = {
342
351
  * and body property with its whole schema. `properties` is always present,
343
352
  * even when empty, because some clients refuse an object schema without it.
344
353
  */
345
- declare const buildFullInputSchema: (args: {
354
+ export declare const buildFullInputSchema: (args: {
346
355
  pathParams: FullParam[];
347
356
  queryParams: FullParam[];
348
357
  bodyProps: FullBodyProp[];
@@ -449,7 +458,7 @@ interface OpenApiTool extends Tool {
449
458
  definition: ToolDefinition;
450
459
  }
451
460
  /** The text the default `toText` answers when the API returned no body. */
452
- declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
461
+ export declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
453
462
  /**
454
463
  * Derives MCP tools from OpenAPI document(s). Each tool's handler resolves
455
464
  * the incoming args into a concrete HTTP request and delegates execution to
@@ -480,7 +489,7 @@ declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
480
489
  * registerTools({ server, tools });
481
490
  * ```
482
491
  */
483
- declare const openApiToTools: (args: OpenApiToToolsArgs) => OpenApiTool[];
492
+ export declare const openApiToTools: (args: OpenApiToToolsArgs) => OpenApiTool[];
484
493
  //#endregion
485
494
  //#region src/inProcessCallApi.d.ts
486
495
  interface CreateInProcessCallApiArgs {
@@ -507,7 +516,7 @@ interface CreateInProcessCallApiArgs {
507
516
  * `{ error: { code, message } }` (as `code: message`) or `{ message: '…' }`.
508
517
  * `null` when the body is none of them.
509
518
  */
510
- declare const errorMessageOf: (body: unknown) => string | null;
519
+ export declare const errorMessageOf: (body: unknown) => string | null;
511
520
  /**
512
521
  * A `callApi` for {@link openApiToTools} that serves each tool call
513
522
  * against the REST app in this same process, with no socket: validation,
@@ -527,11 +536,7 @@ declare const errorMessageOf: (body: unknown) => string | null;
527
536
  * });
528
537
  * ```
529
538
  */
530
- declare const createInProcessCallApi: ({
531
- app,
532
- headers,
533
- toError
534
- }: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
539
+ export declare const createInProcessCallApi: ({ app, headers, toError }: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
535
540
  //#endregion
536
541
  //#region src/schema.d.ts
537
542
  type ResolvedSchema = {
@@ -549,13 +554,13 @@ type ResolvedSchema = {
549
554
  *
550
555
  * Refs into other files resolve against `documents`; see {@link OpenApiDocuments}.
551
556
  */
552
- declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => Record<string, unknown> | undefined;
557
+ export declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => Record<string, unknown> | undefined;
553
558
  /**
554
559
  * Resolves a schema down to a single object shape: follows a top-level `$ref`
555
560
  * and merges `oneOf` / `anyOf` alternatives (union of properties, intersection
556
561
  * of `required`) so the caller sees one flat property set.
557
562
  */
558
- declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedSchema;
563
+ export declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedSchema;
559
564
  /** A parameter object after its `$ref` (if any) is followed. */
560
565
  type ResolvedParameter = {
561
566
  name?: string;
@@ -576,17 +581,19 @@ type ResolvedParameter = {
576
581
  * Follows a parameter `$ref` — into `components.parameters`, or into another
577
582
  * file through `documents` — if present.
578
583
  */
579
- declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedParameter;
584
+ export declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedParameter;
580
585
  /** Builds a function that substitutes path params into the path template. */
581
- declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
586
+ export declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
582
587
  name: string;
583
588
  argName: string;
584
589
  }>) => ((args: Record<string, unknown>) => string);
585
590
  /** Query parameter with the OpenAPI serialisation rules declared for it. */
586
591
  type QueryParamSerialization = {
587
592
  name: string;
588
- argName: string; /** OpenAPI `style` (`form`, `deepObject`, `spaceDelimited`, `pipeDelimited`). */
589
- style?: string; /** OpenAPI `explode`. Defaults to `true` for `form`, `false` otherwise. */
593
+ argName: string;
594
+ /** OpenAPI `style` (`form`, `deepObject`, `spaceDelimited`, `pipeDelimited`). */
595
+ style?: string;
596
+ /** OpenAPI `explode`. Defaults to `true` for `form`, `false` otherwise. */
590
597
  explode?: boolean;
591
598
  };
592
599
  /**
@@ -594,21 +601,21 @@ type QueryParamSerialization = {
594
601
  * (including the leading `?`), honouring each param's OpenAPI `style` and
595
602
  * `explode`. Returns `undefined` when the op has no query params.
596
603
  */
597
- declare const buildQueryFn: (queryParams: QueryParamSerialization[]) => ((args: Record<string, unknown>) => string) | undefined;
604
+ export declare const buildQueryFn: (queryParams: QueryParamSerialization[]) => ((args: Record<string, unknown>) => string) | undefined;
598
605
  /**
599
606
  * Builds a function that maps tool args back to a request body keyed by the
600
607
  * spec's property names, skipping `undefined` args. Returns `undefined` when the op has no body.
601
608
  */
602
- declare const buildBodyFn: (bodyProps: Array<{
609
+ export declare const buildBodyFn: (bodyProps: Array<{
603
610
  snakeName: string;
604
611
  argName: string;
605
612
  }>) => ((args: Record<string, unknown>) => Record<string, unknown>) | undefined;
606
613
  //#endregion
607
614
  //#region src/toolDefinitions.d.ts
608
615
  /** Converts a camelCase `operationId` to a kebab-case tool name. */
609
- declare const operationIdToToolName: (operationId: string) => string;
610
- declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
611
- declare const buildInputSchema: (pathParams: Array<{
616
+ export declare const operationIdToToolName: (operationId: string) => string;
617
+ export declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
618
+ export declare const buildInputSchema: (pathParams: Array<{
612
619
  name: string;
613
620
  argName: string;
614
621
  description?: string;
@@ -632,7 +639,7 @@ declare const buildInputSchema: (pathParams: Array<{
632
639
  anyOf?: unknown[];
633
640
  allOf?: unknown[];
634
641
  }>) => JsonObjectSchema;
635
- declare const processOperation: (args: {
642
+ export declare const processOperation: (args: {
636
643
  pathTemplate: string;
637
644
  method: string;
638
645
  operation: OperationSpec;
@@ -649,7 +656,7 @@ declare const processOperation: (args: {
649
656
  [key: string]: unknown;
650
657
  }>;
651
658
  }) => ToolDefinition | null;
652
- declare const processPath: (args: {
659
+ export declare const processPath: (args: {
653
660
  pathTemplate: string;
654
661
  pathItem: Record<string, OperationSpec>;
655
662
  spec: OpenApiSpec;
@@ -667,9 +674,9 @@ declare const processPath: (args: {
667
674
  * const tools = openApiToToolDefinitions({ spec: myOpenApiDocument });
668
675
  * ```
669
676
  */
670
- declare const openApiToToolDefinitions: (args: {
677
+ export declare const openApiToToolDefinitions: (args: {
671
678
  spec: OpenApiSpec | OpenApiSpec[];
672
679
  options?: OpenApiToToolsOptions;
673
680
  }) => ToolDefinition[];
674
681
  //#endregion
675
- export { type CreateInProcessCallApiArgs, DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsArgs, type OpenApiToToolsOptions, type OpenApiTool, type OperationSpec, type QueryParamSerialization, type RequestBodySpec, type ResolvedParameter, type ResolvedRequest, type ResolvedToolOptions, type ServerManagedParameter, type ToolDefinition, buildBodyFn, buildFullInputSchema, buildInputSchema, buildPathFn, buildQueryFn, createInProcessCallApi, dereferenceSchema, errorMessageOf, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractPinnedBody, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, openApiToTools, operationIdToToolName, processOperation, processPath, resolveParameter, resolveSchema, snakeToCamel, toToolSchema };
682
+ export type { CreateInProcessCallApiArgs, JsonSchemaProperty, OpenApiDocuments, OpenApiSpec, OpenApiToToolsArgs, OpenApiToToolsOptions, OpenApiTool, OperationSpec, QueryParamSerialization, RequestBodySpec, ResolvedParameter, ResolvedRequest, ResolvedToolOptions, ServerManagedParameter, ToolDefinition };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  import { App, InProcessResponse } from "@ttoss/http-server";
3
3
  import { JsonObjectSchema, Tool } from "@ttoss/http-server-mcp";
4
-
5
4
  //#region src/types.d.ts
6
5
  /** The JSON Schema primitive types this generator can derive from an OpenAPI `type`. */
7
6
  type JsonSchemaPrimitiveType = 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
@@ -134,8 +133,10 @@ interface OperationSpec {
134
133
  name?: string;
135
134
  in?: string;
136
135
  required?: boolean;
137
- description?: string; /** Query serialisation style, e.g. `form` (default) or `deepObject`. */
138
- style?: string; /** Whether each value gets its own key. Defaults to `true` for `form`. */
136
+ description?: string;
137
+ /** Query serialisation style, e.g. `form` (default) or `deepObject`. */
138
+ style?: string;
139
+ /** Whether each value gets its own key. Defaults to `true` for `form`. */
139
140
  explode?: boolean;
140
141
  schema?: {
141
142
  type?: string;
@@ -217,15 +218,16 @@ interface OpenApiToToolsOptions {
217
218
  * ```
218
219
  */
219
220
  describe?: (args: {
220
- operation: OperationSpec; /** Uppercase HTTP method. */
221
+ operation: OperationSpec;
222
+ /** Uppercase HTTP method. */
221
223
  method: string;
222
224
  pathTemplate: string;
223
225
  }) => string;
224
226
  }
225
227
  /** {@link OpenApiToToolsOptions} with every default applied. */
226
228
  type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>> & Pick<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>;
227
- declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
228
- declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
229
+ export declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
230
+ export declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
229
231
  //#endregion
230
232
  //#region src/serverManaged.d.ts
231
233
  /** One extension name, or several that all mean "the server sets this". */
@@ -237,7 +239,7 @@ type ServerManagedExtension = string | string[];
237
239
  * names may be snake_case (`agent_id`) or kebab-case (`list-tools`); with the
238
240
  * default `argumentNames: 'camelCase'` both are folded into tool arguments.
239
241
  */
240
- declare const snakeToCamel: (str: string) => string;
242
+ export declare const snakeToCamel: (str: string) => string;
241
243
  /** Maps a spec parameter or property name to a tool argument name. */
242
244
  type ToArgName = (name: string) => string;
243
245
  /** Arguments shared by the parameter extractors. */
@@ -247,25 +249,30 @@ type ExtractParamsArgs = {
247
249
  in?: string;
248
250
  [key: string]: unknown;
249
251
  }>;
250
- spec: OpenApiSpec; /** Sibling documents cross-file `$ref`s resolve against. */
251
- documents?: OpenApiDocuments; /** Maps a spec name to its tool argument name. @default snakeToCamel */
252
- toArgName?: ToArgName; /** @default DEFAULT_SERVER_MANAGED_EXTENSION */
252
+ spec: OpenApiSpec;
253
+ /** Sibling documents cross-file `$ref`s resolve against. */
254
+ documents?: OpenApiDocuments;
255
+ /** Maps a spec name to its tool argument name. @default snakeToCamel */
256
+ toArgName?: ToArgName;
257
+ /** @default DEFAULT_SERVER_MANAGED_EXTENSION */
253
258
  serverManagedExtension?: ServerManagedExtension;
254
259
  };
255
- declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
260
+ export declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
256
261
  name: string;
257
262
  argName: string;
258
- description?: string; /** The parameter's schema with every `$ref` inlined. */
263
+ description?: string;
264
+ /** The parameter's schema with every `$ref` inlined. */
259
265
  schema?: Record<string, unknown>;
260
266
  serverManaged: boolean;
261
267
  pinnedValue?: string;
262
268
  }>;
263
- declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
269
+ export declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
264
270
  name: string;
265
271
  argName: string;
266
272
  description: string;
267
273
  required: boolean;
268
- type: string; /** The parameter's schema with every `$ref` inlined. */
274
+ type: string;
275
+ /** The parameter's schema with every `$ref` inlined. */
269
276
  schema?: Record<string, unknown>;
270
277
  style?: string;
271
278
  explode?: boolean;
@@ -278,16 +285,17 @@ declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
278
285
  * snake_case names of every top-level property an operation's request schema
279
286
  * declares, including server-managed ones.
280
287
  */
281
- declare const extractAcceptedBodyFields: (args: {
288
+ export declare const extractAcceptedBodyFields: (args: {
282
289
  requestBody?: RequestBodySpec;
283
290
  spec: OpenApiSpec;
284
291
  documents?: OpenApiDocuments;
285
292
  }) => string[];
286
- declare const extractBodyProps: (args: {
293
+ export declare const extractBodyProps: (args: {
287
294
  requestBody?: RequestBodySpec;
288
295
  spec: OpenApiSpec;
289
296
  serverManagedExtension: ServerManagedExtension;
290
- documents?: OpenApiDocuments; /** Maps a spec name to its tool argument name. @default snakeToCamel */
297
+ documents?: OpenApiDocuments;
298
+ /** Maps a spec name to its tool argument name. @default snakeToCamel */
291
299
  toArgName?: ToArgName;
292
300
  }) => Array<{
293
301
  snakeName: string;
@@ -299,7 +307,8 @@ declare const extractBodyProps: (args: {
299
307
  nullable: boolean;
300
308
  oneOf?: unknown[];
301
309
  anyOf?: unknown[];
302
- allOf?: unknown[]; /** The property's whole schema, with every `$ref` inlined. */
310
+ allOf?: unknown[];
311
+ /** The property's whole schema, with every `$ref` inlined. */
303
312
  schema: Record<string, unknown>;
304
313
  }>;
305
314
  /**
@@ -307,7 +316,7 @@ declare const extractBodyProps: (args: {
307
316
  * keyed by its spec name. A property whose extension is not a string pins
308
317
  * nothing: it is only hidden, for the consumer to fill.
309
318
  */
310
- declare const extractPinnedBody: (args: {
319
+ export declare const extractPinnedBody: (args: {
311
320
  requestBody?: RequestBodySpec;
312
321
  spec: OpenApiSpec;
313
322
  serverManagedExtension: ServerManagedExtension;
@@ -324,7 +333,7 @@ declare const extractPinnedBody: (args: {
324
333
  * merged, `nullable` becomes a `'null'` type, and OpenAPI-only keywords and
325
334
  * `x-` extensions are dropped. Descriptions are kept verbatim.
326
335
  */
327
- declare const toToolSchema: (value: unknown) => unknown;
336
+ export declare const toToolSchema: (value: unknown) => unknown;
328
337
  type FullParam = {
329
338
  argName: string;
330
339
  required?: boolean;
@@ -342,7 +351,7 @@ type FullBodyProp = {
342
351
  * and body property with its whole schema. `properties` is always present,
343
352
  * even when empty, because some clients refuse an object schema without it.
344
353
  */
345
- declare const buildFullInputSchema: (args: {
354
+ export declare const buildFullInputSchema: (args: {
346
355
  pathParams: FullParam[];
347
356
  queryParams: FullParam[];
348
357
  bodyProps: FullBodyProp[];
@@ -449,7 +458,7 @@ interface OpenApiTool extends Tool {
449
458
  definition: ToolDefinition;
450
459
  }
451
460
  /** The text the default `toText` answers when the API returned no body. */
452
- declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
461
+ export declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
453
462
  /**
454
463
  * Derives MCP tools from OpenAPI document(s). Each tool's handler resolves
455
464
  * the incoming args into a concrete HTTP request and delegates execution to
@@ -480,7 +489,7 @@ declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
480
489
  * registerTools({ server, tools });
481
490
  * ```
482
491
  */
483
- declare const openApiToTools: (args: OpenApiToToolsArgs) => OpenApiTool[];
492
+ export declare const openApiToTools: (args: OpenApiToToolsArgs) => OpenApiTool[];
484
493
  //#endregion
485
494
  //#region src/inProcessCallApi.d.ts
486
495
  interface CreateInProcessCallApiArgs {
@@ -507,7 +516,7 @@ interface CreateInProcessCallApiArgs {
507
516
  * `{ error: { code, message } }` (as `code: message`) or `{ message: '…' }`.
508
517
  * `null` when the body is none of them.
509
518
  */
510
- declare const errorMessageOf: (body: unknown) => string | null;
519
+ export declare const errorMessageOf: (body: unknown) => string | null;
511
520
  /**
512
521
  * A `callApi` for {@link openApiToTools} that serves each tool call
513
522
  * against the REST app in this same process, with no socket: validation,
@@ -527,11 +536,7 @@ declare const errorMessageOf: (body: unknown) => string | null;
527
536
  * });
528
537
  * ```
529
538
  */
530
- declare const createInProcessCallApi: ({
531
- app,
532
- headers,
533
- toError
534
- }: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
539
+ export declare const createInProcessCallApi: ({ app, headers, toError }: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
535
540
  //#endregion
536
541
  //#region src/schema.d.ts
537
542
  type ResolvedSchema = {
@@ -549,13 +554,13 @@ type ResolvedSchema = {
549
554
  *
550
555
  * Refs into other files resolve against `documents`; see {@link OpenApiDocuments}.
551
556
  */
552
- declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => Record<string, unknown> | undefined;
557
+ export declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => Record<string, unknown> | undefined;
553
558
  /**
554
559
  * Resolves a schema down to a single object shape: follows a top-level `$ref`
555
560
  * and merges `oneOf` / `anyOf` alternatives (union of properties, intersection
556
561
  * of `required`) so the caller sees one flat property set.
557
562
  */
558
- declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedSchema;
563
+ export declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedSchema;
559
564
  /** A parameter object after its `$ref` (if any) is followed. */
560
565
  type ResolvedParameter = {
561
566
  name?: string;
@@ -576,17 +581,19 @@ type ResolvedParameter = {
576
581
  * Follows a parameter `$ref` — into `components.parameters`, or into another
577
582
  * file through `documents` — if present.
578
583
  */
579
- declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedParameter;
584
+ export declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec, documents?: OpenApiDocuments) => ResolvedParameter;
580
585
  /** Builds a function that substitutes path params into the path template. */
581
- declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
586
+ export declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
582
587
  name: string;
583
588
  argName: string;
584
589
  }>) => ((args: Record<string, unknown>) => string);
585
590
  /** Query parameter with the OpenAPI serialisation rules declared for it. */
586
591
  type QueryParamSerialization = {
587
592
  name: string;
588
- argName: string; /** OpenAPI `style` (`form`, `deepObject`, `spaceDelimited`, `pipeDelimited`). */
589
- style?: string; /** OpenAPI `explode`. Defaults to `true` for `form`, `false` otherwise. */
593
+ argName: string;
594
+ /** OpenAPI `style` (`form`, `deepObject`, `spaceDelimited`, `pipeDelimited`). */
595
+ style?: string;
596
+ /** OpenAPI `explode`. Defaults to `true` for `form`, `false` otherwise. */
590
597
  explode?: boolean;
591
598
  };
592
599
  /**
@@ -594,21 +601,21 @@ type QueryParamSerialization = {
594
601
  * (including the leading `?`), honouring each param's OpenAPI `style` and
595
602
  * `explode`. Returns `undefined` when the op has no query params.
596
603
  */
597
- declare const buildQueryFn: (queryParams: QueryParamSerialization[]) => ((args: Record<string, unknown>) => string) | undefined;
604
+ export declare const buildQueryFn: (queryParams: QueryParamSerialization[]) => ((args: Record<string, unknown>) => string) | undefined;
598
605
  /**
599
606
  * Builds a function that maps tool args back to a request body keyed by the
600
607
  * spec's property names, skipping `undefined` args. Returns `undefined` when the op has no body.
601
608
  */
602
- declare const buildBodyFn: (bodyProps: Array<{
609
+ export declare const buildBodyFn: (bodyProps: Array<{
603
610
  snakeName: string;
604
611
  argName: string;
605
612
  }>) => ((args: Record<string, unknown>) => Record<string, unknown>) | undefined;
606
613
  //#endregion
607
614
  //#region src/toolDefinitions.d.ts
608
615
  /** Converts a camelCase `operationId` to a kebab-case tool name. */
609
- declare const operationIdToToolName: (operationId: string) => string;
610
- declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
611
- declare const buildInputSchema: (pathParams: Array<{
616
+ export declare const operationIdToToolName: (operationId: string) => string;
617
+ export declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
618
+ export declare const buildInputSchema: (pathParams: Array<{
612
619
  name: string;
613
620
  argName: string;
614
621
  description?: string;
@@ -632,7 +639,7 @@ declare const buildInputSchema: (pathParams: Array<{
632
639
  anyOf?: unknown[];
633
640
  allOf?: unknown[];
634
641
  }>) => JsonObjectSchema;
635
- declare const processOperation: (args: {
642
+ export declare const processOperation: (args: {
636
643
  pathTemplate: string;
637
644
  method: string;
638
645
  operation: OperationSpec;
@@ -649,7 +656,7 @@ declare const processOperation: (args: {
649
656
  [key: string]: unknown;
650
657
  }>;
651
658
  }) => ToolDefinition | null;
652
- declare const processPath: (args: {
659
+ export declare const processPath: (args: {
653
660
  pathTemplate: string;
654
661
  pathItem: Record<string, OperationSpec>;
655
662
  spec: OpenApiSpec;
@@ -667,9 +674,9 @@ declare const processPath: (args: {
667
674
  * const tools = openApiToToolDefinitions({ spec: myOpenApiDocument });
668
675
  * ```
669
676
  */
670
- declare const openApiToToolDefinitions: (args: {
677
+ export declare const openApiToToolDefinitions: (args: {
671
678
  spec: OpenApiSpec | OpenApiSpec[];
672
679
  options?: OpenApiToToolsOptions;
673
680
  }) => ToolDefinition[];
674
681
  //#endregion
675
- export { type CreateInProcessCallApiArgs, DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsArgs, type OpenApiToToolsOptions, type OpenApiTool, type OperationSpec, type QueryParamSerialization, type RequestBodySpec, type ResolvedParameter, type ResolvedRequest, type ResolvedToolOptions, type ServerManagedParameter, type ToolDefinition, buildBodyFn, buildFullInputSchema, buildInputSchema, buildPathFn, buildQueryFn, createInProcessCallApi, dereferenceSchema, errorMessageOf, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractPinnedBody, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, openApiToTools, operationIdToToolName, processOperation, processPath, resolveParameter, resolveSchema, snakeToCamel, toToolSchema };
682
+ export type { CreateInProcessCallApiArgs, JsonSchemaProperty, OpenApiDocuments, OpenApiSpec, OpenApiToToolsArgs, OpenApiToToolsOptions, OpenApiTool, OperationSpec, QueryParamSerialization, RequestBodySpec, ResolvedParameter, ResolvedRequest, ResolvedToolOptions, ServerManagedParameter, ToolDefinition };
package/dist/index.mjs CHANGED
@@ -491,7 +491,7 @@ var managedFields = flag => {
491
491
  var extractPathParams = args => {
492
492
  const toArgName = args.toArgName ?? snakeToCamel;
493
493
  const flag = args.serverManagedExtension ?? "x-mcp-server-managed";
494
- return dedupeByName((args.parameters || []).map(p => {
494
+ const params = (args.parameters || []).map(p => {
495
495
  return resolveParameter(p, args.spec, args.documents);
496
496
  }).filter(p => {
497
497
  return p.in === "path";
@@ -506,12 +506,13 @@ var extractPathParams = args => {
506
506
  extension: flag
507
507
  }))
508
508
  };
509
- }));
509
+ });
510
+ return dedupeByName(params);
510
511
  };
511
512
  var extractQueryParams = args => {
512
513
  const toArgName = args.toArgName ?? snakeToCamel;
513
514
  const flag = args.serverManagedExtension ?? "x-mcp-server-managed";
514
- return dedupeByName((args.parameters || []).map(p => {
515
+ const params = (args.parameters || []).map(p => {
515
516
  return resolveParameter(p, args.spec, args.documents);
516
517
  }).filter(p => {
517
518
  return p.in === "query";
@@ -530,7 +531,8 @@ var extractQueryParams = args => {
530
531
  extension: flag
531
532
  }))
532
533
  };
533
- }));
534
+ });
535
+ return dedupeByName(params);
534
536
  };
535
537
  var collectServerManagedParameters = args => {
536
538
  return [...args.pathParams.map(p => {
@@ -561,7 +563,8 @@ var collectServerManagedParameters = args => {
561
563
  //#region src/body.ts
562
564
  var resolveBodySchema = args => {
563
565
  const rawBodySchema = args.requestBody?.content?.["application/json"]?.schema;
564
- return resolveSchema(dereferenceSchema(rawBodySchema, args.spec, args.documents), args.spec, args.documents);
566
+ const dereferencedBodySchema = dereferenceSchema(rawBodySchema, args.spec, args.documents);
567
+ return resolveSchema(dereferencedBodySchema, args.spec, args.documents);
565
568
  };
566
569
  /**
567
570
  * snake_case names of every top-level property an operation's request schema
@@ -651,10 +654,10 @@ var extractPinnedBody = args => {
651
654
  var isRecord = value => {
652
655
  return typeof value === "object" && value !== null && !Array.isArray(value);
653
656
  };
654
- var OPENAPI_ONLY_KEYWORDS = new Set(["discriminator", "example", "externalDocs", "xml"]);
655
- var SCHEMA_MAPS = new Set(["$defs", "definitions", "dependentSchemas", "patternProperties", "properties"]);
656
- var SCHEMA_VALUES = new Set(["additionalProperties", "contains", "else", "if", "items", "not", "propertyNames", "then", "unevaluatedItems", "unevaluatedProperties"]);
657
- var SCHEMA_LISTS = new Set(["anyOf", "oneOf", "prefixItems"]);
657
+ var OPENAPI_ONLY_KEYWORDS = /* @__PURE__ */new Set(["discriminator", "example", "externalDocs", "xml"]);
658
+ var SCHEMA_MAPS = /* @__PURE__ */new Set(["$defs", "definitions", "dependentSchemas", "patternProperties", "properties"]);
659
+ var SCHEMA_VALUES = /* @__PURE__ */new Set(["additionalProperties", "contains", "else", "if", "items", "not", "propertyNames", "then", "unevaluatedItems", "unevaluatedProperties"]);
660
+ var SCHEMA_LISTS = /* @__PURE__ */new Set(["anyOf", "oneOf", "prefixItems"]);
658
661
  /**
659
662
  * OpenAPI 3.0's `nullable: true` in JSON Schema: `'null'` joins the `type`,
660
663
  * and `null` joins an `enum`, which would otherwise still refuse it.
@@ -833,8 +836,9 @@ var createInProcessCallApi = ({
833
836
  toError = defaultToError
834
837
  }) => {
835
838
  return async request => {
839
+ const target = typeof app === "function" ? await app() : app;
836
840
  const response = await dispatchInProcess({
837
- app: typeof app === "function" ? await app() : app,
841
+ app: target,
838
842
  method: request.method,
839
843
  path: request.url,
840
844
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/http-server-mcp-openapi",
3
- "version": "0.8.8",
3
+ "version": "0.9.0",
4
4
  "description": "Generate Model Context Protocol (MCP) tools from an OpenAPI specification for @ttoss/http-server-mcp",
5
5
  "keywords": [
6
6
  "ai",
@@ -36,15 +36,15 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@ttoss/http-server": "^0.13.1",
40
- "@ttoss/http-server-mcp": "^0.37.0"
39
+ "@ttoss/http-server": "^0.14.0",
40
+ "@ttoss/http-server-mcp": "^0.38.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@modelcontextprotocol/server": "^2.0.0",
44
- "jest": "^30.4.2",
45
- "supertest": "^7.2.2",
46
- "tsdown": "^0.22.2",
47
- "@ttoss/config": "^1.41.0"
43
+ "@modelcontextprotocol/server": "^2.3.1",
44
+ "jest": "^30.5.2",
45
+ "supertest": "^7.3.1",
46
+ "tsdown": "^0.23.1",
47
+ "@ttoss/config": "^2.0.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public",