@ttoss/http-server-mcp-openapi 0.1.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.
@@ -0,0 +1,335 @@
1
+
2
+ import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * A single JSON Schema property descriptor as emitted for a tool's
7
+ * `inputSchema`. Only the subset of JSON Schema the generator produces is
8
+ * modelled here; the value is forwarded verbatim over the MCP wire protocol.
9
+ */
10
+ interface JsonSchemaProperty {
11
+ type: 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
12
+ description?: string;
13
+ items?: unknown;
14
+ }
15
+ /**
16
+ * A REST-backed MCP tool derived from a single OpenAPI operation.
17
+ *
18
+ * The `path` / `query` / `body` builders turn the camelCase arguments an MCP
19
+ * client sends into the pieces of an HTTP request against the original REST
20
+ * API. They intentionally hold no transport concerns (base URL, auth); the
21
+ * caller wires those in when it performs the request.
22
+ */
23
+ interface ToolDefinition {
24
+ /** kebab-case tool name derived from the operation's `operationId`. */
25
+ name: string;
26
+ /** Sanitised operation description (quotes escaped, newlines flattened). */
27
+ description: string;
28
+ /** Plain JSON Schema describing the tool's camelCase input object. */
29
+ inputSchema: JsonObjectSchema;
30
+ /** Uppercase HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`). */
31
+ method: string;
32
+ /** The raw OpenAPI path template, e.g. `/agents/{agent_id}`. */
33
+ pathTemplate: string;
34
+ /** The operation's `operationId`. */
35
+ operationId: string;
36
+ /** Builds the request path, substituting path params from the args. */
37
+ path: (args: Record<string, unknown>) => string;
38
+ /** Builds the query string (including leading `?`), or `undefined` if none. */
39
+ query?: (args: Record<string, unknown>) => string;
40
+ /** Builds the snake_case request body, or `undefined` if the op has no body. */
41
+ body?: (args: Record<string, unknown>) => Record<string, unknown>;
42
+ /**
43
+ * snake_case names of every top-level request-body property the operation's
44
+ * schema declares, including server-managed ones hidden from `inputSchema`.
45
+ */
46
+ acceptedBodyFields: string[];
47
+ /**
48
+ * Every `x-` prefixed extension declared on the operation, forwarded
49
+ * verbatim. Lets consumers read custom metadata (e.g. `x-iam-action`)
50
+ * without this package needing to know about it.
51
+ */
52
+ extensions: Record<string, unknown>;
53
+ }
54
+ /** Minimal shape of an OpenAPI document consumed by the generator. */
55
+ interface OpenApiSpec {
56
+ paths?: Record<string, Record<string, unknown>>;
57
+ components?: {
58
+ schemas?: Record<string, unknown>;
59
+ parameters?: Record<string, unknown>;
60
+ };
61
+ }
62
+ type RequestBodySpec = {
63
+ required?: boolean;
64
+ content?: {
65
+ 'application/json'?: {
66
+ schema?: {
67
+ type?: string;
68
+ required?: string[];
69
+ properties?: Record<string, unknown>;
70
+ oneOf?: Array<Record<string, unknown>>;
71
+ anyOf?: Array<Record<string, unknown>>;
72
+ $ref?: string;
73
+ };
74
+ };
75
+ };
76
+ };
77
+ interface OperationSpec {
78
+ operationId?: string;
79
+ description?: string;
80
+ parameters?: Array<{
81
+ name?: string;
82
+ in?: string;
83
+ required?: boolean;
84
+ description?: string;
85
+ schema?: {
86
+ type?: string;
87
+ items?: {
88
+ type?: string;
89
+ };
90
+ };
91
+ $ref?: string;
92
+ }>;
93
+ requestBody?: RequestBodySpec;
94
+ [extension: string]: unknown;
95
+ }
96
+ /** Options that tune how operations and body properties are translated. */
97
+ interface OpenApiToToolsOptions {
98
+ /**
99
+ * Operation-level extension flag that, when truthy, excludes the operation
100
+ * from the generated tool surface.
101
+ * @default 'x-mcp-exclude'
102
+ */
103
+ excludeExtension?: string;
104
+ /**
105
+ * Body-property extension flag that, when truthy, hides the property from the
106
+ * generated `inputSchema` while keeping it in `acceptedBodyFields` (for
107
+ * server-managed fields the API sets itself).
108
+ * @default 'x-mcp-server-managed'
109
+ */
110
+ serverManagedExtension?: string;
111
+ }
112
+ declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
113
+ declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
114
+ //#endregion
115
+ //#region src/registerOpenApiTools.d.ts
116
+ /** The resolved HTTP request a tool call maps to, before transport concerns. */
117
+ interface ResolvedRequest {
118
+ /** Uppercase HTTP method. */
119
+ method: string;
120
+ /** Request path including the query string, e.g. `/agents/agt_1?limit=10`. */
121
+ url: string;
122
+ /** snake_case request body, or `undefined` when the operation has none. */
123
+ body?: Record<string, unknown>;
124
+ /** The tool definition the call resolved to (for auth/metadata lookups). */
125
+ tool: ToolDefinition;
126
+ }
127
+ interface RegisterOpenApiToolsArgs {
128
+ /** The MCP server the generated tools are registered on. */
129
+ server: McpServer;
130
+ /** One or more OpenAPI documents to derive tools from. */
131
+ spec: OpenApiSpec | OpenApiSpec[];
132
+ /** Tuning options forwarded to {@link openApiToToolDefinitions}. */
133
+ options?: OpenApiToToolsOptions;
134
+ /**
135
+ * Performs the HTTP request for a resolved tool call and returns the raw
136
+ * response data. This package builds the method/url/body; the caller owns
137
+ * how the request is executed — base URL, auth headers, fetch impl, etc.
138
+ */
139
+ callApi: (request: ResolvedRequest) => Promise<unknown> | unknown;
140
+ /**
141
+ * Serialises the raw API data into the MCP tool's text payload.
142
+ * @default (data) => JSON.stringify(data, null, 2)
143
+ */
144
+ toText?: (data: unknown) => string;
145
+ }
146
+ /**
147
+ * Derives MCP tools from OpenAPI document(s) and registers each on the given
148
+ * MCP server. Every tool's handler resolves the incoming camelCase args into a
149
+ * concrete HTTP request and delegates execution to `callApi`.
150
+ *
151
+ * @returns The list of {@link ToolDefinition} that were registered.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { McpServer } from '@ttoss/http-server-mcp';
156
+ * import { registerOpenApiTools } from '@ttoss/http-server-mcp-openapi';
157
+ *
158
+ * const server = new McpServer({ name: 'my-api', version: '1.0.0' });
159
+ *
160
+ * registerOpenApiTools({
161
+ * server,
162
+ * spec: myOpenApiDocument,
163
+ * callApi: async ({ method, url, body }) => {
164
+ * const res = await fetch(`https://api.example.com${url}`, {
165
+ * method,
166
+ * headers: { 'Content-Type': 'application/json' },
167
+ * body: body ? JSON.stringify(body) : undefined,
168
+ * });
169
+ * return res.json();
170
+ * },
171
+ * });
172
+ * ```
173
+ */
174
+ declare const registerOpenApiTools: (args: RegisterOpenApiToolsArgs) => ToolDefinition[];
175
+ //#endregion
176
+ //#region src/schema.d.ts
177
+ type ResolvedSchema = {
178
+ type?: string;
179
+ required?: string[];
180
+ properties?: Record<string, unknown>;
181
+ oneOf?: Array<Record<string, unknown>>;
182
+ anyOf?: Array<Record<string, unknown>>;
183
+ };
184
+ /**
185
+ * Recursively inlines every `$ref` in a schema (including refs nested inside
186
+ * `properties`, `items`, `oneOf`, `anyOf`, etc.), producing a self-contained
187
+ * schema safe to hand to an MCP client or LLM provider as a tool definition —
188
+ * provider tool schemas have no `components` section to resolve refs against.
189
+ */
190
+ declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec) => Record<string, unknown> | undefined;
191
+ /**
192
+ * Resolves a schema down to a single object shape: follows a top-level `$ref`
193
+ * and merges `oneOf` / `anyOf` alternatives (union of properties, intersection
194
+ * of `required`) so the caller sees one flat property set.
195
+ */
196
+ declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec) => ResolvedSchema;
197
+ /** Follows a parameter `$ref` into `components.parameters`, if present. */
198
+ declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec) => {
199
+ name?: string;
200
+ in?: string;
201
+ required?: boolean;
202
+ description?: string;
203
+ schema?: {
204
+ type?: string;
205
+ items?: {
206
+ type?: string;
207
+ };
208
+ };
209
+ };
210
+ /** Builds a function that substitutes path params into the path template. */
211
+ declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
212
+ name: string;
213
+ camelName: string;
214
+ }>) => ((args: Record<string, unknown>) => string);
215
+ /**
216
+ * Builds a function that serialises query params into a query string
217
+ * (including the leading `?`). Returns `undefined` when the op has no query
218
+ * params. Array values are appended once per element.
219
+ */
220
+ declare const buildQueryFn: (queryParams: Array<{
221
+ name: string;
222
+ camelName: string;
223
+ }>) => ((args: Record<string, unknown>) => string) | undefined;
224
+ /**
225
+ * Builds a function that maps camelCase args back to a snake_case request
226
+ * body, skipping `undefined` args. Returns `undefined` when the op has no body.
227
+ */
228
+ declare const buildBodyFn: (bodyProps: Array<{
229
+ snakeName: string;
230
+ camelName: string;
231
+ }>) => ((args: Record<string, unknown>) => Record<string, unknown>) | undefined;
232
+ //#endregion
233
+ //#region src/toolDefinitions.d.ts
234
+ /**
235
+ * Folds `_` and `-` separators into camelCase. OpenAPI operation and parameter
236
+ * names may be snake_case (`agent_id`) or kebab-case (`list-tools`), and MCP
237
+ * tool inputs are camelCase by convention, so both are folded here.
238
+ */
239
+ declare const snakeToCamel: (str: string) => string;
240
+ /** Converts a camelCase `operationId` to a kebab-case tool name. */
241
+ declare const operationIdToToolName: (operationId: string) => string;
242
+ declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
243
+ declare const buildInputSchema: (pathParams: Array<{
244
+ name: string;
245
+ camelName: string;
246
+ }>, queryParams: Array<{
247
+ name: string;
248
+ camelName: string;
249
+ description: string;
250
+ required: boolean;
251
+ type: string;
252
+ }>, bodyProps: Array<{
253
+ snakeName: string;
254
+ camelName: string;
255
+ description: string;
256
+ required: boolean;
257
+ type: string;
258
+ items?: unknown;
259
+ }>) => JsonObjectSchema;
260
+ declare const extractPathParams: (args: {
261
+ parameters?: Array<{
262
+ name?: string;
263
+ in?: string;
264
+ [key: string]: unknown;
265
+ }>;
266
+ spec: OpenApiSpec;
267
+ }) => Array<{
268
+ name: string;
269
+ camelName: string;
270
+ }>;
271
+ declare const extractQueryParams: (args: {
272
+ parameters?: Array<{
273
+ name?: string;
274
+ in?: string;
275
+ [key: string]: unknown;
276
+ }>;
277
+ spec: OpenApiSpec;
278
+ }) => Array<{
279
+ name: string;
280
+ camelName: string;
281
+ description: string;
282
+ required: boolean;
283
+ type: string;
284
+ }>;
285
+ /**
286
+ * snake_case names of every top-level property an operation's request schema
287
+ * declares, including server-managed ones.
288
+ */
289
+ declare const extractAcceptedBodyFields: (args: {
290
+ requestBody?: RequestBodySpec;
291
+ spec: OpenApiSpec;
292
+ }) => string[];
293
+ declare const extractBodyProps: (args: {
294
+ requestBody?: RequestBodySpec;
295
+ spec: OpenApiSpec;
296
+ serverManagedExtension: string;
297
+ }) => Array<{
298
+ snakeName: string;
299
+ camelName: string;
300
+ description: string;
301
+ required: boolean;
302
+ type: string;
303
+ items?: unknown;
304
+ }>;
305
+ declare const processOperation: (args: {
306
+ pathTemplate: string;
307
+ method: string;
308
+ operation: OperationSpec;
309
+ spec: OpenApiSpec;
310
+ options: Required<OpenApiToToolsOptions>;
311
+ }) => ToolDefinition | null;
312
+ declare const processPath: (args: {
313
+ pathTemplate: string;
314
+ pathItem: Record<string, OperationSpec>;
315
+ spec: OpenApiSpec;
316
+ options: Required<OpenApiToToolsOptions>;
317
+ }) => ToolDefinition[];
318
+ /**
319
+ * Translates one or more OpenAPI documents into REST-backed MCP tool
320
+ * definitions. Each translatable operation (has an `operationId`, a supported
321
+ * HTTP method, and is not excluded) becomes one {@link ToolDefinition}.
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * import { openApiToToolDefinitions } from '@ttoss/http-server-mcp-openapi';
326
+ *
327
+ * const tools = openApiToToolDefinitions({ spec: myOpenApiDocument });
328
+ * ```
329
+ */
330
+ declare const openApiToToolDefinitions: (args: {
331
+ spec: OpenApiSpec | OpenApiSpec[];
332
+ options?: OpenApiToToolsOptions;
333
+ }) => ToolDefinition[];
334
+ //#endregion
335
+ export { DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type RegisterOpenApiToolsArgs, type RequestBodySpec, type ResolvedRequest, type ToolDefinition, buildBodyFn, buildInputSchema, buildPathFn, buildQueryFn, dereferenceSchema, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel };
@@ -0,0 +1,335 @@
1
+
2
+ import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * A single JSON Schema property descriptor as emitted for a tool's
7
+ * `inputSchema`. Only the subset of JSON Schema the generator produces is
8
+ * modelled here; the value is forwarded verbatim over the MCP wire protocol.
9
+ */
10
+ interface JsonSchemaProperty {
11
+ type: 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
12
+ description?: string;
13
+ items?: unknown;
14
+ }
15
+ /**
16
+ * A REST-backed MCP tool derived from a single OpenAPI operation.
17
+ *
18
+ * The `path` / `query` / `body` builders turn the camelCase arguments an MCP
19
+ * client sends into the pieces of an HTTP request against the original REST
20
+ * API. They intentionally hold no transport concerns (base URL, auth); the
21
+ * caller wires those in when it performs the request.
22
+ */
23
+ interface ToolDefinition {
24
+ /** kebab-case tool name derived from the operation's `operationId`. */
25
+ name: string;
26
+ /** Sanitised operation description (quotes escaped, newlines flattened). */
27
+ description: string;
28
+ /** Plain JSON Schema describing the tool's camelCase input object. */
29
+ inputSchema: JsonObjectSchema;
30
+ /** Uppercase HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`). */
31
+ method: string;
32
+ /** The raw OpenAPI path template, e.g. `/agents/{agent_id}`. */
33
+ pathTemplate: string;
34
+ /** The operation's `operationId`. */
35
+ operationId: string;
36
+ /** Builds the request path, substituting path params from the args. */
37
+ path: (args: Record<string, unknown>) => string;
38
+ /** Builds the query string (including leading `?`), or `undefined` if none. */
39
+ query?: (args: Record<string, unknown>) => string;
40
+ /** Builds the snake_case request body, or `undefined` if the op has no body. */
41
+ body?: (args: Record<string, unknown>) => Record<string, unknown>;
42
+ /**
43
+ * snake_case names of every top-level request-body property the operation's
44
+ * schema declares, including server-managed ones hidden from `inputSchema`.
45
+ */
46
+ acceptedBodyFields: string[];
47
+ /**
48
+ * Every `x-` prefixed extension declared on the operation, forwarded
49
+ * verbatim. Lets consumers read custom metadata (e.g. `x-iam-action`)
50
+ * without this package needing to know about it.
51
+ */
52
+ extensions: Record<string, unknown>;
53
+ }
54
+ /** Minimal shape of an OpenAPI document consumed by the generator. */
55
+ interface OpenApiSpec {
56
+ paths?: Record<string, Record<string, unknown>>;
57
+ components?: {
58
+ schemas?: Record<string, unknown>;
59
+ parameters?: Record<string, unknown>;
60
+ };
61
+ }
62
+ type RequestBodySpec = {
63
+ required?: boolean;
64
+ content?: {
65
+ 'application/json'?: {
66
+ schema?: {
67
+ type?: string;
68
+ required?: string[];
69
+ properties?: Record<string, unknown>;
70
+ oneOf?: Array<Record<string, unknown>>;
71
+ anyOf?: Array<Record<string, unknown>>;
72
+ $ref?: string;
73
+ };
74
+ };
75
+ };
76
+ };
77
+ interface OperationSpec {
78
+ operationId?: string;
79
+ description?: string;
80
+ parameters?: Array<{
81
+ name?: string;
82
+ in?: string;
83
+ required?: boolean;
84
+ description?: string;
85
+ schema?: {
86
+ type?: string;
87
+ items?: {
88
+ type?: string;
89
+ };
90
+ };
91
+ $ref?: string;
92
+ }>;
93
+ requestBody?: RequestBodySpec;
94
+ [extension: string]: unknown;
95
+ }
96
+ /** Options that tune how operations and body properties are translated. */
97
+ interface OpenApiToToolsOptions {
98
+ /**
99
+ * Operation-level extension flag that, when truthy, excludes the operation
100
+ * from the generated tool surface.
101
+ * @default 'x-mcp-exclude'
102
+ */
103
+ excludeExtension?: string;
104
+ /**
105
+ * Body-property extension flag that, when truthy, hides the property from the
106
+ * generated `inputSchema` while keeping it in `acceptedBodyFields` (for
107
+ * server-managed fields the API sets itself).
108
+ * @default 'x-mcp-server-managed'
109
+ */
110
+ serverManagedExtension?: string;
111
+ }
112
+ declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
113
+ declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
114
+ //#endregion
115
+ //#region src/registerOpenApiTools.d.ts
116
+ /** The resolved HTTP request a tool call maps to, before transport concerns. */
117
+ interface ResolvedRequest {
118
+ /** Uppercase HTTP method. */
119
+ method: string;
120
+ /** Request path including the query string, e.g. `/agents/agt_1?limit=10`. */
121
+ url: string;
122
+ /** snake_case request body, or `undefined` when the operation has none. */
123
+ body?: Record<string, unknown>;
124
+ /** The tool definition the call resolved to (for auth/metadata lookups). */
125
+ tool: ToolDefinition;
126
+ }
127
+ interface RegisterOpenApiToolsArgs {
128
+ /** The MCP server the generated tools are registered on. */
129
+ server: McpServer;
130
+ /** One or more OpenAPI documents to derive tools from. */
131
+ spec: OpenApiSpec | OpenApiSpec[];
132
+ /** Tuning options forwarded to {@link openApiToToolDefinitions}. */
133
+ options?: OpenApiToToolsOptions;
134
+ /**
135
+ * Performs the HTTP request for a resolved tool call and returns the raw
136
+ * response data. This package builds the method/url/body; the caller owns
137
+ * how the request is executed — base URL, auth headers, fetch impl, etc.
138
+ */
139
+ callApi: (request: ResolvedRequest) => Promise<unknown> | unknown;
140
+ /**
141
+ * Serialises the raw API data into the MCP tool's text payload.
142
+ * @default (data) => JSON.stringify(data, null, 2)
143
+ */
144
+ toText?: (data: unknown) => string;
145
+ }
146
+ /**
147
+ * Derives MCP tools from OpenAPI document(s) and registers each on the given
148
+ * MCP server. Every tool's handler resolves the incoming camelCase args into a
149
+ * concrete HTTP request and delegates execution to `callApi`.
150
+ *
151
+ * @returns The list of {@link ToolDefinition} that were registered.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { McpServer } from '@ttoss/http-server-mcp';
156
+ * import { registerOpenApiTools } from '@ttoss/http-server-mcp-openapi';
157
+ *
158
+ * const server = new McpServer({ name: 'my-api', version: '1.0.0' });
159
+ *
160
+ * registerOpenApiTools({
161
+ * server,
162
+ * spec: myOpenApiDocument,
163
+ * callApi: async ({ method, url, body }) => {
164
+ * const res = await fetch(`https://api.example.com${url}`, {
165
+ * method,
166
+ * headers: { 'Content-Type': 'application/json' },
167
+ * body: body ? JSON.stringify(body) : undefined,
168
+ * });
169
+ * return res.json();
170
+ * },
171
+ * });
172
+ * ```
173
+ */
174
+ declare const registerOpenApiTools: (args: RegisterOpenApiToolsArgs) => ToolDefinition[];
175
+ //#endregion
176
+ //#region src/schema.d.ts
177
+ type ResolvedSchema = {
178
+ type?: string;
179
+ required?: string[];
180
+ properties?: Record<string, unknown>;
181
+ oneOf?: Array<Record<string, unknown>>;
182
+ anyOf?: Array<Record<string, unknown>>;
183
+ };
184
+ /**
185
+ * Recursively inlines every `$ref` in a schema (including refs nested inside
186
+ * `properties`, `items`, `oneOf`, `anyOf`, etc.), producing a self-contained
187
+ * schema safe to hand to an MCP client or LLM provider as a tool definition —
188
+ * provider tool schemas have no `components` section to resolve refs against.
189
+ */
190
+ declare const dereferenceSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec) => Record<string, unknown> | undefined;
191
+ /**
192
+ * Resolves a schema down to a single object shape: follows a top-level `$ref`
193
+ * and merges `oneOf` / `anyOf` alternatives (union of properties, intersection
194
+ * of `required`) so the caller sees one flat property set.
195
+ */
196
+ declare const resolveSchema: (schema: Record<string, unknown> | undefined, spec: OpenApiSpec) => ResolvedSchema;
197
+ /** Follows a parameter `$ref` into `components.parameters`, if present. */
198
+ declare const resolveParameter: (param: Record<string, unknown> | undefined, spec: OpenApiSpec) => {
199
+ name?: string;
200
+ in?: string;
201
+ required?: boolean;
202
+ description?: string;
203
+ schema?: {
204
+ type?: string;
205
+ items?: {
206
+ type?: string;
207
+ };
208
+ };
209
+ };
210
+ /** Builds a function that substitutes path params into the path template. */
211
+ declare const buildPathFn: (pathTemplate: string, pathParams: Array<{
212
+ name: string;
213
+ camelName: string;
214
+ }>) => ((args: Record<string, unknown>) => string);
215
+ /**
216
+ * Builds a function that serialises query params into a query string
217
+ * (including the leading `?`). Returns `undefined` when the op has no query
218
+ * params. Array values are appended once per element.
219
+ */
220
+ declare const buildQueryFn: (queryParams: Array<{
221
+ name: string;
222
+ camelName: string;
223
+ }>) => ((args: Record<string, unknown>) => string) | undefined;
224
+ /**
225
+ * Builds a function that maps camelCase args back to a snake_case request
226
+ * body, skipping `undefined` args. Returns `undefined` when the op has no body.
227
+ */
228
+ declare const buildBodyFn: (bodyProps: Array<{
229
+ snakeName: string;
230
+ camelName: string;
231
+ }>) => ((args: Record<string, unknown>) => Record<string, unknown>) | undefined;
232
+ //#endregion
233
+ //#region src/toolDefinitions.d.ts
234
+ /**
235
+ * Folds `_` and `-` separators into camelCase. OpenAPI operation and parameter
236
+ * names may be snake_case (`agent_id`) or kebab-case (`list-tools`), and MCP
237
+ * tool inputs are camelCase by convention, so both are folded here.
238
+ */
239
+ declare const snakeToCamel: (str: string) => string;
240
+ /** Converts a camelCase `operationId` to a kebab-case tool name. */
241
+ declare const operationIdToToolName: (operationId: string) => string;
242
+ declare const getJsonSchemaType: (schemaType: string | undefined) => JsonSchemaProperty["type"];
243
+ declare const buildInputSchema: (pathParams: Array<{
244
+ name: string;
245
+ camelName: string;
246
+ }>, queryParams: Array<{
247
+ name: string;
248
+ camelName: string;
249
+ description: string;
250
+ required: boolean;
251
+ type: string;
252
+ }>, bodyProps: Array<{
253
+ snakeName: string;
254
+ camelName: string;
255
+ description: string;
256
+ required: boolean;
257
+ type: string;
258
+ items?: unknown;
259
+ }>) => JsonObjectSchema;
260
+ declare const extractPathParams: (args: {
261
+ parameters?: Array<{
262
+ name?: string;
263
+ in?: string;
264
+ [key: string]: unknown;
265
+ }>;
266
+ spec: OpenApiSpec;
267
+ }) => Array<{
268
+ name: string;
269
+ camelName: string;
270
+ }>;
271
+ declare const extractQueryParams: (args: {
272
+ parameters?: Array<{
273
+ name?: string;
274
+ in?: string;
275
+ [key: string]: unknown;
276
+ }>;
277
+ spec: OpenApiSpec;
278
+ }) => Array<{
279
+ name: string;
280
+ camelName: string;
281
+ description: string;
282
+ required: boolean;
283
+ type: string;
284
+ }>;
285
+ /**
286
+ * snake_case names of every top-level property an operation's request schema
287
+ * declares, including server-managed ones.
288
+ */
289
+ declare const extractAcceptedBodyFields: (args: {
290
+ requestBody?: RequestBodySpec;
291
+ spec: OpenApiSpec;
292
+ }) => string[];
293
+ declare const extractBodyProps: (args: {
294
+ requestBody?: RequestBodySpec;
295
+ spec: OpenApiSpec;
296
+ serverManagedExtension: string;
297
+ }) => Array<{
298
+ snakeName: string;
299
+ camelName: string;
300
+ description: string;
301
+ required: boolean;
302
+ type: string;
303
+ items?: unknown;
304
+ }>;
305
+ declare const processOperation: (args: {
306
+ pathTemplate: string;
307
+ method: string;
308
+ operation: OperationSpec;
309
+ spec: OpenApiSpec;
310
+ options: Required<OpenApiToToolsOptions>;
311
+ }) => ToolDefinition | null;
312
+ declare const processPath: (args: {
313
+ pathTemplate: string;
314
+ pathItem: Record<string, OperationSpec>;
315
+ spec: OpenApiSpec;
316
+ options: Required<OpenApiToToolsOptions>;
317
+ }) => ToolDefinition[];
318
+ /**
319
+ * Translates one or more OpenAPI documents into REST-backed MCP tool
320
+ * definitions. Each translatable operation (has an `operationId`, a supported
321
+ * HTTP method, and is not excluded) becomes one {@link ToolDefinition}.
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * import { openApiToToolDefinitions } from '@ttoss/http-server-mcp-openapi';
326
+ *
327
+ * const tools = openApiToToolDefinitions({ spec: myOpenApiDocument });
328
+ * ```
329
+ */
330
+ declare const openApiToToolDefinitions: (args: {
331
+ spec: OpenApiSpec | OpenApiSpec[];
332
+ options?: OpenApiToToolsOptions;
333
+ }) => ToolDefinition[];
334
+ //#endregion
335
+ export { DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type RegisterOpenApiToolsArgs, type RequestBodySpec, type ResolvedRequest, type ToolDefinition, buildBodyFn, buildInputSchema, buildPathFn, buildQueryFn, dereferenceSchema, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel };