@ttoss/http-server-mcp-openapi 0.5.7 → 0.7.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/README.md +106 -8
- package/dist/index.cjs +293 -33
- package/dist/index.d.cts +156 -4
- package/dist/index.d.mts +156 -4
- package/dist/index.mjs +289 -33
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
|
|
3
|
+
import { App, InProcessResponse } from "@ttoss/http-server";
|
|
3
4
|
|
|
4
5
|
//#region src/types.d.ts
|
|
5
6
|
/** The JSON Schema primitive types this generator can derive from an OpenAPI `type`. */
|
|
@@ -121,6 +122,7 @@ type RequestBodySpec = {
|
|
|
121
122
|
};
|
|
122
123
|
interface OperationSpec {
|
|
123
124
|
operationId?: string;
|
|
125
|
+
summary?: string;
|
|
124
126
|
description?: string;
|
|
125
127
|
parameters?: Array<{
|
|
126
128
|
name?: string;
|
|
@@ -183,9 +185,39 @@ interface OpenApiToToolsOptions {
|
|
|
183
185
|
* to an empty schema, which accepts any value.
|
|
184
186
|
*/
|
|
185
187
|
documents?: OpenApiDocuments;
|
|
188
|
+
/**
|
|
189
|
+
* How much of each parameter's and body property's schema reaches the
|
|
190
|
+
* tool's `inputSchema`.
|
|
191
|
+
*
|
|
192
|
+
* - `'compact'` keeps the `type`, `items` and `description` of each
|
|
193
|
+
* top-level argument, with descriptions flattened to one line.
|
|
194
|
+
* - `'full'` keeps the whole schema — `enum`, `format`, `pattern`,
|
|
195
|
+
* `minimum`, `default`, nested `properties` and `required`, `oneOf` — and
|
|
196
|
+
* changes only what JSON Schema cannot say: `allOf` is merged, `nullable`
|
|
197
|
+
* becomes a `'null'` type (and joins an `enum`), and OpenAPI-only keywords
|
|
198
|
+
* and `x-` extensions are dropped. Descriptions stay verbatim.
|
|
199
|
+
*
|
|
200
|
+
* @default 'compact'
|
|
201
|
+
*/
|
|
202
|
+
schemaDetail?: 'compact' | 'full';
|
|
203
|
+
/**
|
|
204
|
+
* Builds each tool's description from its operation. The default is the
|
|
205
|
+
* operation's `description`, flattened to one line.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* describe: ({ operation, method, pathTemplate }) =>
|
|
210
|
+
* `${operation.summary}\n\n${operation.description}\n\n(${method} ${pathTemplate})`,
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
describe?: (args: {
|
|
214
|
+
operation: OperationSpec; /** Uppercase HTTP method. */
|
|
215
|
+
method: string;
|
|
216
|
+
pathTemplate: string;
|
|
217
|
+
}) => string;
|
|
186
218
|
}
|
|
187
219
|
/** {@link OpenApiToToolsOptions} with every default applied. */
|
|
188
|
-
type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents'>> & Pick<OpenApiToToolsOptions, 'documents'>;
|
|
220
|
+
type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>> & Pick<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>;
|
|
189
221
|
declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
|
|
190
222
|
declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
|
|
191
223
|
//#endregion
|
|
@@ -217,6 +249,8 @@ type ExtractParamsArgs = {
|
|
|
217
249
|
declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
|
|
218
250
|
name: string;
|
|
219
251
|
argName: string;
|
|
252
|
+
description?: string; /** The parameter's schema with every `$ref` inlined. */
|
|
253
|
+
schema?: Record<string, unknown>;
|
|
220
254
|
serverManaged: boolean;
|
|
221
255
|
pinnedValue?: string;
|
|
222
256
|
}>;
|
|
@@ -225,7 +259,8 @@ declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
|
|
|
225
259
|
argName: string;
|
|
226
260
|
description: string;
|
|
227
261
|
required: boolean;
|
|
228
|
-
type: string;
|
|
262
|
+
type: string; /** The parameter's schema with every `$ref` inlined. */
|
|
263
|
+
schema?: Record<string, unknown>;
|
|
229
264
|
style?: string;
|
|
230
265
|
explode?: boolean;
|
|
231
266
|
serverManaged: boolean;
|
|
@@ -258,7 +293,8 @@ declare const extractBodyProps: (args: {
|
|
|
258
293
|
nullable: boolean;
|
|
259
294
|
oneOf?: unknown[];
|
|
260
295
|
anyOf?: unknown[];
|
|
261
|
-
allOf?: unknown[];
|
|
296
|
+
allOf?: unknown[]; /** The property's whole schema, with every `$ref` inlined. */
|
|
297
|
+
schema: Record<string, unknown>;
|
|
262
298
|
}>;
|
|
263
299
|
/**
|
|
264
300
|
* The value each server-managed body property pins, typed by its schema and
|
|
@@ -273,6 +309,39 @@ declare const extractPinnedBody: (args: {
|
|
|
273
309
|
operationId: string;
|
|
274
310
|
}) => Record<string, string | number | boolean>;
|
|
275
311
|
//#endregion
|
|
312
|
+
//#region src/fullSchema.d.ts
|
|
313
|
+
/**
|
|
314
|
+
* Turns an already-dereferenced OpenAPI schema into the JSON Schema a tool
|
|
315
|
+
* argument carries, keeping every constraint it declares — `enum`, `format`,
|
|
316
|
+
* `pattern`, `minimum`, `default`, nested `properties` and `required`,
|
|
317
|
+
* `oneOf` — and changing only what JSON Schema cannot express: `allOf` is
|
|
318
|
+
* merged, `nullable` becomes a `'null'` type, and OpenAPI-only keywords and
|
|
319
|
+
* `x-` extensions are dropped. Descriptions are kept verbatim.
|
|
320
|
+
*/
|
|
321
|
+
declare const toToolSchema: (value: unknown) => unknown;
|
|
322
|
+
type FullParam = {
|
|
323
|
+
argName: string;
|
|
324
|
+
required?: boolean;
|
|
325
|
+
description?: string;
|
|
326
|
+
schema?: unknown;
|
|
327
|
+
serverManaged?: boolean;
|
|
328
|
+
};
|
|
329
|
+
type FullBodyProp = {
|
|
330
|
+
argName: string;
|
|
331
|
+
required: boolean;
|
|
332
|
+
schema: Record<string, unknown>;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* The `inputSchema` of a tool under `schemaDetail: 'full'`: every parameter
|
|
336
|
+
* and body property with its whole schema. `properties` is always present,
|
|
337
|
+
* even when empty, because some clients refuse an object schema without it.
|
|
338
|
+
*/
|
|
339
|
+
declare const buildFullInputSchema: (args: {
|
|
340
|
+
pathParams: FullParam[];
|
|
341
|
+
queryParams: FullParam[];
|
|
342
|
+
bodyProps: FullBodyProp[];
|
|
343
|
+
}) => JsonObjectSchema;
|
|
344
|
+
//#endregion
|
|
276
345
|
//#region src/registerOpenApiTools.d.ts
|
|
277
346
|
/** The resolved HTTP request a tool call maps to, before transport concerns. */
|
|
278
347
|
interface ResolvedRequest {
|
|
@@ -310,6 +379,37 @@ interface RegisterOpenApiToolsArgs {
|
|
|
310
379
|
* {@link NO_CONTENT_TEXT} for an empty body (e.g. a `204`).
|
|
311
380
|
*/
|
|
312
381
|
toText?: (data: unknown) => string;
|
|
382
|
+
/**
|
|
383
|
+
* Builds the tool result's `structuredContent` from the raw API data, sent
|
|
384
|
+
* beside the text payload. Return `undefined` to keep a result text-only,
|
|
385
|
+
* which is every result when this is unset.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* toStructuredContent: ({ data }) =>
|
|
390
|
+
* typeof data === 'object' && data !== null && !Array.isArray(data)
|
|
391
|
+
* ? (data as Record<string, unknown>)
|
|
392
|
+
* : undefined,
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
toStructuredContent?: (args: {
|
|
396
|
+
data: unknown;
|
|
397
|
+
tool: ToolDefinition;
|
|
398
|
+
}) => Record<string, unknown> | undefined;
|
|
399
|
+
/**
|
|
400
|
+
* Builds each tool's `_meta`, advertised on `tools/list`. This is how a
|
|
401
|
+
* generated tool links to an MCP Apps view: return the bag from
|
|
402
|
+
* `registerAppResource(...).toolMeta()`. `undefined` registers no `_meta`.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* toolMeta: ({ tool }) =>
|
|
407
|
+
* tool.name === 'get-agent' ? agentCard.toolMeta() : undefined,
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
toolMeta?: (args: {
|
|
411
|
+
tool: ToolDefinition;
|
|
412
|
+
}) => Record<string, unknown> | undefined;
|
|
313
413
|
/**
|
|
314
414
|
* Supplies the values of the tool's server-managed path and query
|
|
315
415
|
* parameters (`tool.serverManagedParameters`), keyed by their spec name.
|
|
@@ -360,6 +460,58 @@ declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
|
|
|
360
460
|
*/
|
|
361
461
|
declare const registerOpenApiTools: (args: RegisterOpenApiToolsArgs) => ToolDefinition[];
|
|
362
462
|
//#endregion
|
|
463
|
+
//#region src/inProcessCallApi.d.ts
|
|
464
|
+
interface CreateInProcessCallApiArgs {
|
|
465
|
+
/**
|
|
466
|
+
* The Koa app serving the REST API the tools were generated from, or a
|
|
467
|
+
* function returning it — for an app that mounts the MCP router itself and
|
|
468
|
+
* so is not built yet when the tools are registered.
|
|
469
|
+
*/
|
|
470
|
+
app: App | (() => App | Promise<App>);
|
|
471
|
+
/**
|
|
472
|
+
* Headers added to every dispatched request, after the ones the MCP request
|
|
473
|
+
* carried — e.g. a marker that tells a request log the call came from a tool.
|
|
474
|
+
*/
|
|
475
|
+
headers?: (request: ResolvedRequest) => Record<string, string | undefined>;
|
|
476
|
+
/**
|
|
477
|
+
* Builds the error a non-2xx response throws. The default reads the message
|
|
478
|
+
* out of the common error envelopes (see {@link errorMessageOf}).
|
|
479
|
+
*/
|
|
480
|
+
toError?: (response: InProcessResponse, request: ResolvedRequest) => Error;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The message an error response carries, read from the envelopes REST APIs
|
|
484
|
+
* commonly answer with: a plain string, `{ error: '…' }`,
|
|
485
|
+
* `{ error: { code, message } }` (as `code: message`) or `{ message: '…' }`.
|
|
486
|
+
* `null` when the body is none of them.
|
|
487
|
+
*/
|
|
488
|
+
declare const errorMessageOf: (body: unknown) => string | null;
|
|
489
|
+
/**
|
|
490
|
+
* A `callApi` for {@link registerOpenApiTools} that serves each tool call
|
|
491
|
+
* against the REST app in this same process, with no socket: validation,
|
|
492
|
+
* authorization and error handling run once, in the routes, for both
|
|
493
|
+
* surfaces.
|
|
494
|
+
*
|
|
495
|
+
* The MCP request's headers (what `createMcpRouter`'s `getApiHeaders`
|
|
496
|
+
* produced — typically the caller's `Authorization`) are forwarded onto the
|
|
497
|
+
* dispatched request. A 2xx answers its body; anything else throws, so the
|
|
498
|
+
* client sees a tool error rather than an error body rendered as a result.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* registerOpenApiTools({
|
|
503
|
+
* server,
|
|
504
|
+
* spec,
|
|
505
|
+
* callApi: createInProcessCallApi({ app }),
|
|
506
|
+
* });
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
declare const createInProcessCallApi: ({
|
|
510
|
+
app,
|
|
511
|
+
headers,
|
|
512
|
+
toError
|
|
513
|
+
}: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
|
|
514
|
+
//#endregion
|
|
363
515
|
//#region src/schema.d.ts
|
|
364
516
|
type ResolvedSchema = {
|
|
365
517
|
type?: string;
|
|
@@ -498,4 +650,4 @@ declare const openApiToToolDefinitions: (args: {
|
|
|
498
650
|
options?: OpenApiToToolsOptions;
|
|
499
651
|
}) => ToolDefinition[];
|
|
500
652
|
//#endregion
|
|
501
|
-
export { DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type QueryParamSerialization, type RegisterOpenApiToolsArgs, type RequestBodySpec, type ResolvedParameter, type ResolvedRequest, type ResolvedToolOptions, type ServerManagedParameter, type ToolDefinition, buildBodyFn, buildInputSchema, buildPathFn, buildQueryFn, dereferenceSchema, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractPinnedBody, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel };
|
|
653
|
+
export { type CreateInProcessCallApiArgs, DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type QueryParamSerialization, type RegisterOpenApiToolsArgs, 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, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel, toToolSchema };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { App, InProcessResponse } from "@ttoss/http-server";
|
|
2
3
|
import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
|
|
3
4
|
|
|
4
5
|
//#region src/types.d.ts
|
|
@@ -121,6 +122,7 @@ type RequestBodySpec = {
|
|
|
121
122
|
};
|
|
122
123
|
interface OperationSpec {
|
|
123
124
|
operationId?: string;
|
|
125
|
+
summary?: string;
|
|
124
126
|
description?: string;
|
|
125
127
|
parameters?: Array<{
|
|
126
128
|
name?: string;
|
|
@@ -183,9 +185,39 @@ interface OpenApiToToolsOptions {
|
|
|
183
185
|
* to an empty schema, which accepts any value.
|
|
184
186
|
*/
|
|
185
187
|
documents?: OpenApiDocuments;
|
|
188
|
+
/**
|
|
189
|
+
* How much of each parameter's and body property's schema reaches the
|
|
190
|
+
* tool's `inputSchema`.
|
|
191
|
+
*
|
|
192
|
+
* - `'compact'` keeps the `type`, `items` and `description` of each
|
|
193
|
+
* top-level argument, with descriptions flattened to one line.
|
|
194
|
+
* - `'full'` keeps the whole schema — `enum`, `format`, `pattern`,
|
|
195
|
+
* `minimum`, `default`, nested `properties` and `required`, `oneOf` — and
|
|
196
|
+
* changes only what JSON Schema cannot say: `allOf` is merged, `nullable`
|
|
197
|
+
* becomes a `'null'` type (and joins an `enum`), and OpenAPI-only keywords
|
|
198
|
+
* and `x-` extensions are dropped. Descriptions stay verbatim.
|
|
199
|
+
*
|
|
200
|
+
* @default 'compact'
|
|
201
|
+
*/
|
|
202
|
+
schemaDetail?: 'compact' | 'full';
|
|
203
|
+
/**
|
|
204
|
+
* Builds each tool's description from its operation. The default is the
|
|
205
|
+
* operation's `description`, flattened to one line.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* describe: ({ operation, method, pathTemplate }) =>
|
|
210
|
+
* `${operation.summary}\n\n${operation.description}\n\n(${method} ${pathTemplate})`,
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
describe?: (args: {
|
|
214
|
+
operation: OperationSpec; /** Uppercase HTTP method. */
|
|
215
|
+
method: string;
|
|
216
|
+
pathTemplate: string;
|
|
217
|
+
}) => string;
|
|
186
218
|
}
|
|
187
219
|
/** {@link OpenApiToToolsOptions} with every default applied. */
|
|
188
|
-
type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents'>> & Pick<OpenApiToToolsOptions, 'documents'>;
|
|
220
|
+
type ResolvedToolOptions = Required<Omit<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>> & Pick<OpenApiToToolsOptions, 'documents' | 'describe' | 'schemaDetail'>;
|
|
189
221
|
declare const DEFAULT_EXCLUDE_EXTENSION = "x-mcp-exclude";
|
|
190
222
|
declare const DEFAULT_SERVER_MANAGED_EXTENSION = "x-mcp-server-managed";
|
|
191
223
|
//#endregion
|
|
@@ -217,6 +249,8 @@ type ExtractParamsArgs = {
|
|
|
217
249
|
declare const extractPathParams: (args: ExtractParamsArgs) => Array<{
|
|
218
250
|
name: string;
|
|
219
251
|
argName: string;
|
|
252
|
+
description?: string; /** The parameter's schema with every `$ref` inlined. */
|
|
253
|
+
schema?: Record<string, unknown>;
|
|
220
254
|
serverManaged: boolean;
|
|
221
255
|
pinnedValue?: string;
|
|
222
256
|
}>;
|
|
@@ -225,7 +259,8 @@ declare const extractQueryParams: (args: ExtractParamsArgs) => Array<{
|
|
|
225
259
|
argName: string;
|
|
226
260
|
description: string;
|
|
227
261
|
required: boolean;
|
|
228
|
-
type: string;
|
|
262
|
+
type: string; /** The parameter's schema with every `$ref` inlined. */
|
|
263
|
+
schema?: Record<string, unknown>;
|
|
229
264
|
style?: string;
|
|
230
265
|
explode?: boolean;
|
|
231
266
|
serverManaged: boolean;
|
|
@@ -258,7 +293,8 @@ declare const extractBodyProps: (args: {
|
|
|
258
293
|
nullable: boolean;
|
|
259
294
|
oneOf?: unknown[];
|
|
260
295
|
anyOf?: unknown[];
|
|
261
|
-
allOf?: unknown[];
|
|
296
|
+
allOf?: unknown[]; /** The property's whole schema, with every `$ref` inlined. */
|
|
297
|
+
schema: Record<string, unknown>;
|
|
262
298
|
}>;
|
|
263
299
|
/**
|
|
264
300
|
* The value each server-managed body property pins, typed by its schema and
|
|
@@ -273,6 +309,39 @@ declare const extractPinnedBody: (args: {
|
|
|
273
309
|
operationId: string;
|
|
274
310
|
}) => Record<string, string | number | boolean>;
|
|
275
311
|
//#endregion
|
|
312
|
+
//#region src/fullSchema.d.ts
|
|
313
|
+
/**
|
|
314
|
+
* Turns an already-dereferenced OpenAPI schema into the JSON Schema a tool
|
|
315
|
+
* argument carries, keeping every constraint it declares — `enum`, `format`,
|
|
316
|
+
* `pattern`, `minimum`, `default`, nested `properties` and `required`,
|
|
317
|
+
* `oneOf` — and changing only what JSON Schema cannot express: `allOf` is
|
|
318
|
+
* merged, `nullable` becomes a `'null'` type, and OpenAPI-only keywords and
|
|
319
|
+
* `x-` extensions are dropped. Descriptions are kept verbatim.
|
|
320
|
+
*/
|
|
321
|
+
declare const toToolSchema: (value: unknown) => unknown;
|
|
322
|
+
type FullParam = {
|
|
323
|
+
argName: string;
|
|
324
|
+
required?: boolean;
|
|
325
|
+
description?: string;
|
|
326
|
+
schema?: unknown;
|
|
327
|
+
serverManaged?: boolean;
|
|
328
|
+
};
|
|
329
|
+
type FullBodyProp = {
|
|
330
|
+
argName: string;
|
|
331
|
+
required: boolean;
|
|
332
|
+
schema: Record<string, unknown>;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* The `inputSchema` of a tool under `schemaDetail: 'full'`: every parameter
|
|
336
|
+
* and body property with its whole schema. `properties` is always present,
|
|
337
|
+
* even when empty, because some clients refuse an object schema without it.
|
|
338
|
+
*/
|
|
339
|
+
declare const buildFullInputSchema: (args: {
|
|
340
|
+
pathParams: FullParam[];
|
|
341
|
+
queryParams: FullParam[];
|
|
342
|
+
bodyProps: FullBodyProp[];
|
|
343
|
+
}) => JsonObjectSchema;
|
|
344
|
+
//#endregion
|
|
276
345
|
//#region src/registerOpenApiTools.d.ts
|
|
277
346
|
/** The resolved HTTP request a tool call maps to, before transport concerns. */
|
|
278
347
|
interface ResolvedRequest {
|
|
@@ -310,6 +379,37 @@ interface RegisterOpenApiToolsArgs {
|
|
|
310
379
|
* {@link NO_CONTENT_TEXT} for an empty body (e.g. a `204`).
|
|
311
380
|
*/
|
|
312
381
|
toText?: (data: unknown) => string;
|
|
382
|
+
/**
|
|
383
|
+
* Builds the tool result's `structuredContent` from the raw API data, sent
|
|
384
|
+
* beside the text payload. Return `undefined` to keep a result text-only,
|
|
385
|
+
* which is every result when this is unset.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* toStructuredContent: ({ data }) =>
|
|
390
|
+
* typeof data === 'object' && data !== null && !Array.isArray(data)
|
|
391
|
+
* ? (data as Record<string, unknown>)
|
|
392
|
+
* : undefined,
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
toStructuredContent?: (args: {
|
|
396
|
+
data: unknown;
|
|
397
|
+
tool: ToolDefinition;
|
|
398
|
+
}) => Record<string, unknown> | undefined;
|
|
399
|
+
/**
|
|
400
|
+
* Builds each tool's `_meta`, advertised on `tools/list`. This is how a
|
|
401
|
+
* generated tool links to an MCP Apps view: return the bag from
|
|
402
|
+
* `registerAppResource(...).toolMeta()`. `undefined` registers no `_meta`.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* toolMeta: ({ tool }) =>
|
|
407
|
+
* tool.name === 'get-agent' ? agentCard.toolMeta() : undefined,
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
toolMeta?: (args: {
|
|
411
|
+
tool: ToolDefinition;
|
|
412
|
+
}) => Record<string, unknown> | undefined;
|
|
313
413
|
/**
|
|
314
414
|
* Supplies the values of the tool's server-managed path and query
|
|
315
415
|
* parameters (`tool.serverManagedParameters`), keyed by their spec name.
|
|
@@ -360,6 +460,58 @@ declare const NO_CONTENT_TEXT = "Succeeded. The operation returned no content.";
|
|
|
360
460
|
*/
|
|
361
461
|
declare const registerOpenApiTools: (args: RegisterOpenApiToolsArgs) => ToolDefinition[];
|
|
362
462
|
//#endregion
|
|
463
|
+
//#region src/inProcessCallApi.d.ts
|
|
464
|
+
interface CreateInProcessCallApiArgs {
|
|
465
|
+
/**
|
|
466
|
+
* The Koa app serving the REST API the tools were generated from, or a
|
|
467
|
+
* function returning it — for an app that mounts the MCP router itself and
|
|
468
|
+
* so is not built yet when the tools are registered.
|
|
469
|
+
*/
|
|
470
|
+
app: App | (() => App | Promise<App>);
|
|
471
|
+
/**
|
|
472
|
+
* Headers added to every dispatched request, after the ones the MCP request
|
|
473
|
+
* carried — e.g. a marker that tells a request log the call came from a tool.
|
|
474
|
+
*/
|
|
475
|
+
headers?: (request: ResolvedRequest) => Record<string, string | undefined>;
|
|
476
|
+
/**
|
|
477
|
+
* Builds the error a non-2xx response throws. The default reads the message
|
|
478
|
+
* out of the common error envelopes (see {@link errorMessageOf}).
|
|
479
|
+
*/
|
|
480
|
+
toError?: (response: InProcessResponse, request: ResolvedRequest) => Error;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The message an error response carries, read from the envelopes REST APIs
|
|
484
|
+
* commonly answer with: a plain string, `{ error: '…' }`,
|
|
485
|
+
* `{ error: { code, message } }` (as `code: message`) or `{ message: '…' }`.
|
|
486
|
+
* `null` when the body is none of them.
|
|
487
|
+
*/
|
|
488
|
+
declare const errorMessageOf: (body: unknown) => string | null;
|
|
489
|
+
/**
|
|
490
|
+
* A `callApi` for {@link registerOpenApiTools} that serves each tool call
|
|
491
|
+
* against the REST app in this same process, with no socket: validation,
|
|
492
|
+
* authorization and error handling run once, in the routes, for both
|
|
493
|
+
* surfaces.
|
|
494
|
+
*
|
|
495
|
+
* The MCP request's headers (what `createMcpRouter`'s `getApiHeaders`
|
|
496
|
+
* produced — typically the caller's `Authorization`) are forwarded onto the
|
|
497
|
+
* dispatched request. A 2xx answers its body; anything else throws, so the
|
|
498
|
+
* client sees a tool error rather than an error body rendered as a result.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* registerOpenApiTools({
|
|
503
|
+
* server,
|
|
504
|
+
* spec,
|
|
505
|
+
* callApi: createInProcessCallApi({ app }),
|
|
506
|
+
* });
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
declare const createInProcessCallApi: ({
|
|
510
|
+
app,
|
|
511
|
+
headers,
|
|
512
|
+
toError
|
|
513
|
+
}: CreateInProcessCallApiArgs) => ((request: ResolvedRequest) => Promise<unknown>);
|
|
514
|
+
//#endregion
|
|
363
515
|
//#region src/schema.d.ts
|
|
364
516
|
type ResolvedSchema = {
|
|
365
517
|
type?: string;
|
|
@@ -498,4 +650,4 @@ declare const openApiToToolDefinitions: (args: {
|
|
|
498
650
|
options?: OpenApiToToolsOptions;
|
|
499
651
|
}) => ToolDefinition[];
|
|
500
652
|
//#endregion
|
|
501
|
-
export { DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type QueryParamSerialization, type RegisterOpenApiToolsArgs, type RequestBodySpec, type ResolvedParameter, type ResolvedRequest, type ResolvedToolOptions, type ServerManagedParameter, type ToolDefinition, buildBodyFn, buildInputSchema, buildPathFn, buildQueryFn, dereferenceSchema, extractAcceptedBodyFields, extractBodyProps, extractPathParams, extractPinnedBody, extractQueryParams, getJsonSchemaType, openApiToToolDefinitions, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel };
|
|
653
|
+
export { type CreateInProcessCallApiArgs, DEFAULT_EXCLUDE_EXTENSION, DEFAULT_SERVER_MANAGED_EXTENSION, type JsonSchemaProperty, NO_CONTENT_TEXT, type OpenApiDocuments, type OpenApiSpec, type OpenApiToToolsOptions, type OperationSpec, type QueryParamSerialization, type RegisterOpenApiToolsArgs, 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, operationIdToToolName, processOperation, processPath, registerOpenApiTools, resolveParameter, resolveSchema, snakeToCamel, toToolSchema };
|