mcp-from-openapi 2.6.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/errors.d.ts +7 -0
- package/esm/index.mjs +864 -60
- package/esm/package.json +3 -3
- package/generator.d.ts +8 -0
- package/index.d.ts +8 -2
- package/index.js +869 -60
- package/lint.d.ts +33 -0
- package/overlay.d.ts +43 -0
- package/package.json +3 -3
- package/schema-builder.d.ts +17 -0
- package/token-report.d.ts +65 -0
- package/types.d.ts +63 -0
package/lint.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OpenAPIDocument } from './types';
|
|
2
|
+
export type LintSeverity = 'error' | 'warning' | 'info';
|
|
3
|
+
/**
|
|
4
|
+
* One agent-readiness finding. `path` names the operation (`GET /users`);
|
|
5
|
+
* `hint` says how to fix it — in the spec or via generate options/overlays.
|
|
6
|
+
*/
|
|
7
|
+
export interface LintFinding {
|
|
8
|
+
severity: LintSeverity;
|
|
9
|
+
/** Stable kebab-case finding code */
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
path: string;
|
|
13
|
+
hint?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface LintResult {
|
|
16
|
+
/** Sorted: errors first, then warnings, then infos; by path within each */
|
|
17
|
+
findings: LintFinding[];
|
|
18
|
+
counts: {
|
|
19
|
+
error: number;
|
|
20
|
+
warning: number;
|
|
21
|
+
info: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Query-parameter names that read as pagination controls (shared with response hints) */
|
|
25
|
+
export declare const PAGINATION_PARAM: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* Lint an OpenAPI document for agent-readiness: the spec-quality gaps that
|
|
28
|
+
* measurably degrade tool-calling accuracy (missing operationIds, absent or
|
|
29
|
+
* vague descriptions, unpaginated list endpoints, oversized schemas, missing
|
|
30
|
+
* examples). Small spec fixes routinely take tool-call success rates from
|
|
31
|
+
* mediocre to near-perfect — each finding carries a concrete hint.
|
|
32
|
+
*/
|
|
33
|
+
export declare function lintDocument(document: OpenAPIDocument): LintResult;
|
package/overlay.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single Overlay action (OpenAPI Overlay Specification 1.0.0).
|
|
3
|
+
*/
|
|
4
|
+
export interface OverlayAction {
|
|
5
|
+
/** JSONPath expression selecting the nodes to act on (see supported subset below) */
|
|
6
|
+
target: string;
|
|
7
|
+
/** Human note; ignored by the processor */
|
|
8
|
+
description?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Value merged into each matched node: objects deep-merge, arrays append
|
|
11
|
+
* the value, primitives are replaced.
|
|
12
|
+
*/
|
|
13
|
+
update?: unknown;
|
|
14
|
+
/** Remove each matched node from its parent instead of updating */
|
|
15
|
+
remove?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* An OpenAPI Overlay document. Applied to specs at load time (before
|
|
19
|
+
* dereferencing and validation), overlays keep spec curation — agent-tuned
|
|
20
|
+
* descriptions, `x-mcp` flags — in a small separate file that survives every
|
|
21
|
+
* regeneration of the source spec.
|
|
22
|
+
*/
|
|
23
|
+
export interface OverlayDocument {
|
|
24
|
+
/** Overlay Specification version (1.x) */
|
|
25
|
+
overlay: string;
|
|
26
|
+
info?: {
|
|
27
|
+
title?: string;
|
|
28
|
+
version?: string;
|
|
29
|
+
};
|
|
30
|
+
/** URL of the spec this overlay targets; informational here */
|
|
31
|
+
extends?: string;
|
|
32
|
+
actions: OverlayAction[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Apply an OpenAPI Overlay 1.0 document to a spec, returning a NEW document
|
|
36
|
+
* (the input is never mutated). Actions run in order; targets that match
|
|
37
|
+
* nothing are skipped silently, per the Overlay specification.
|
|
38
|
+
*
|
|
39
|
+
* Update semantics: object targets deep-merge the update, array targets
|
|
40
|
+
* append it, primitive targets are replaced. `remove: true` deletes matched
|
|
41
|
+
* nodes (array elements are spliced, preserving order).
|
|
42
|
+
*/
|
|
43
|
+
export declare function applyOverlay<T extends object>(document: T, overlay: OverlayDocument): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-from-openapi",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Production-ready library for converting OpenAPI specifications into MCP tool definitions",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@apidevtools/json-schema-ref-parser": "^15.
|
|
52
|
+
"@apidevtools/json-schema-ref-parser": "^15.5.1",
|
|
53
53
|
"openapi-types": "^12.1.3",
|
|
54
|
-
"yaml": "^2.
|
|
54
|
+
"yaml": "^2.9.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"zod": "^4.0.0"
|
package/schema-builder.d.ts
CHANGED
|
@@ -127,6 +127,23 @@ export declare class SchemaBuilder {
|
|
|
127
127
|
/** Keys whose value is an array of schemas */
|
|
128
128
|
private static readonly TRUNCATE_LIST_KEYS;
|
|
129
129
|
private static truncateDepthRecursive;
|
|
130
|
+
private static walkCopy;
|
|
131
|
+
/**
|
|
132
|
+
* Limit every object node to its first `max` properties (declaration
|
|
133
|
+
* order). Dropped properties are pruned from `required` and counted in a
|
|
134
|
+
* note appended to the node's description.
|
|
135
|
+
*/
|
|
136
|
+
static limitProperties(schema: JsonSchema, max: number): JsonSchema;
|
|
137
|
+
/**
|
|
138
|
+
* Cap every description in the schema tree to `maxLength` characters,
|
|
139
|
+
* truncating with an ellipsis.
|
|
140
|
+
*/
|
|
141
|
+
static capDescriptions(schema: JsonSchema, maxLength: number): JsonSchema;
|
|
142
|
+
/**
|
|
143
|
+
* Remove every `examples` array from the schema tree (a token-budget
|
|
144
|
+
* trimming step — validation keywords are untouched).
|
|
145
|
+
*/
|
|
146
|
+
static stripExamples(schema: JsonSchema): JsonSchema;
|
|
130
147
|
/**
|
|
131
148
|
* Simplify schema by removing unnecessary fields
|
|
132
149
|
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { McpOpenAPITool } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Per-tool token estimate for the definition a client ships to the model.
|
|
4
|
+
*/
|
|
5
|
+
export interface ToolTokenEstimate {
|
|
6
|
+
name: string;
|
|
7
|
+
/** Estimated tokens for the full advertised definition */
|
|
8
|
+
tokens: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Context-budget report for a generated tool set.
|
|
12
|
+
*/
|
|
13
|
+
export interface ToolSetReport {
|
|
14
|
+
toolCount: number;
|
|
15
|
+
/** Sum of all per-tool estimates */
|
|
16
|
+
estimatedTokens: number;
|
|
17
|
+
/** Every tool, heaviest first */
|
|
18
|
+
perTool: ToolTokenEstimate[];
|
|
19
|
+
/** Human-readable budget warnings (empty when the set is comfortably sized) */
|
|
20
|
+
warnings: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Thresholds for {@link analyzeToolSet} warnings.
|
|
24
|
+
*/
|
|
25
|
+
export interface AnalyzeToolSetOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Estimated-token budget for the whole tool set before a warning fires.
|
|
28
|
+
* ~1,000 tokens per tool is typical; ecosystem guidance flags pain beyond
|
|
29
|
+
* ~10K tokens of definitions.
|
|
30
|
+
* @default 10000
|
|
31
|
+
*/
|
|
32
|
+
tokenBudget?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Tool count beyond which model selection accuracy measurably degrades
|
|
35
|
+
* (public evaluations put the cliff at ~30-40 tools).
|
|
36
|
+
* @default 40
|
|
37
|
+
*/
|
|
38
|
+
maxRecommendedTools?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Per-tool estimate that marks a single tool as disproportionately heavy.
|
|
41
|
+
* @default 2000
|
|
42
|
+
*/
|
|
43
|
+
perToolWarning?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Estimate the context-window cost of ONE tool definition — the fields a
|
|
47
|
+
* client advertises to the model (name, title, description, annotations,
|
|
48
|
+
* input/output schemas), serialized as JSON.
|
|
49
|
+
*
|
|
50
|
+
* The estimate is `ceil(chars / 4)` — the common BPE average for JSON-heavy
|
|
51
|
+
* English text. It is a sizing signal for curation decisions, not a
|
|
52
|
+
* tokenizer: real counts vary by model within roughly ±20%.
|
|
53
|
+
*/
|
|
54
|
+
export declare function estimateToolTokens(tool: McpOpenAPITool): number;
|
|
55
|
+
/**
|
|
56
|
+
* Analyze a generated tool set's context-window bill: per-tool estimates
|
|
57
|
+
* (heaviest first), the total, and curation warnings when the set crosses
|
|
58
|
+
* the thresholds where agent accuracy is known to degrade.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* const report = analyzeToolSet(await generator.generateTools());
|
|
62
|
+
* report.warnings.forEach((w) => console.warn(w));
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function analyzeToolSet(tools: McpOpenAPITool[], options?: AnalyzeToolSetOptions): ToolSetReport;
|
package/types.d.ts
CHANGED
|
@@ -292,6 +292,24 @@ export interface ToolMetadata {
|
|
|
292
292
|
* Contains annotations, cache config, codecall config, tags, etc.
|
|
293
293
|
*/
|
|
294
294
|
frontmcp?: FrontMcpExtensionData;
|
|
295
|
+
/**
|
|
296
|
+
* Response-shaping signals for consumers that paginate, truncate, or cache:
|
|
297
|
+
* present only when there is something to know.
|
|
298
|
+
*/
|
|
299
|
+
responseHints?: ResponseHints;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Detected response-shaping signals. Clients cap tool results hard (Claude
|
|
303
|
+
* Code: 25K tokens) — these hints tell a consumer WHICH tools need paging or
|
|
304
|
+
* truncation before the first oversized response happens.
|
|
305
|
+
*/
|
|
306
|
+
export interface ResponseHints {
|
|
307
|
+
/** The success response contains an array without `maxItems` */
|
|
308
|
+
unboundedArray?: boolean;
|
|
309
|
+
/** Query parameters that look like pagination controls (limit, cursor, ...) */
|
|
310
|
+
paginationParams?: string[];
|
|
311
|
+
/** Unbounded array AND no pagination controls: truncate or shape server-side */
|
|
312
|
+
largeResponseRisk?: boolean;
|
|
295
313
|
}
|
|
296
314
|
/**
|
|
297
315
|
* FrontMCP extension data extracted from x-frontmcp in OpenAPI operations.
|
|
@@ -461,6 +479,14 @@ export interface LoadOptions {
|
|
|
461
479
|
* @default true (false when `secureDefaults` is set)
|
|
462
480
|
*/
|
|
463
481
|
followRedirects?: boolean;
|
|
482
|
+
/**
|
|
483
|
+
* OpenAPI Overlay 1.0 document(s) applied to the spec at load time, BEFORE
|
|
484
|
+
* dereferencing and validation, in order. Overlays keep curation
|
|
485
|
+
* (agent-tuned descriptions, `x-mcp` flags) in a separate file that
|
|
486
|
+
* survives spec regeneration. See `applyOverlay` for the supported
|
|
487
|
+
* JSONPath subset.
|
|
488
|
+
*/
|
|
489
|
+
overlays?: import('./overlay').OverlayDocument | import('./overlay').OverlayDocument[];
|
|
464
490
|
/**
|
|
465
491
|
* Opt into the strictest loading posture in one flag: redirects are not
|
|
466
492
|
* followed and external `$ref` resolution is disabled entirely
|
|
@@ -562,6 +588,43 @@ export interface GenerateOptions {
|
|
|
562
588
|
* @default 10
|
|
563
589
|
*/
|
|
564
590
|
maxSchemaDepth?: number;
|
|
591
|
+
/**
|
|
592
|
+
* How the tool description is assembled from the operation:
|
|
593
|
+
* - `summaryOnly` (default): summary, else description, else `METHOD path`
|
|
594
|
+
* - `descriptionOnly`: description, else summary, else `METHOD path`
|
|
595
|
+
* - `combined`: summary + blank line + description (whichever exist)
|
|
596
|
+
* - `full`: summary, description, `Operation: <id>`, and `METHOD path`
|
|
597
|
+
* An `x-mcp`-family description override always wins over the strategy.
|
|
598
|
+
* @default 'summaryOnly'
|
|
599
|
+
*/
|
|
600
|
+
descriptionStrategy?: 'summaryOnly' | 'descriptionOnly' | 'combined' | 'full';
|
|
601
|
+
/**
|
|
602
|
+
* Append a compact `Returns: ...` line to each tool description,
|
|
603
|
+
* summarizing the output schema (top-level shape and field names) — cheap
|
|
604
|
+
* context that measurably improves result-handling without shipping the
|
|
605
|
+
* whole response schema in prose.
|
|
606
|
+
* @default false
|
|
607
|
+
*/
|
|
608
|
+
appendResponseSummary?: boolean;
|
|
609
|
+
/**
|
|
610
|
+
* Limit object nodes in generated schemas to their first N properties
|
|
611
|
+
* (declaration order). Dropped properties are pruned from `required` and
|
|
612
|
+
* counted in a description note. The ROOT of `inputSchema` is exempt: its
|
|
613
|
+
* properties are mapper-backed parameters, so the cap applies inside each
|
|
614
|
+
* parameter subtree (and throughout output schemas). Unset = no limit.
|
|
615
|
+
*/
|
|
616
|
+
maxProperties?: number;
|
|
617
|
+
/**
|
|
618
|
+
* Cap every description in generated schemas to N characters (ellipsis
|
|
619
|
+
* truncation). Unset = no cap.
|
|
620
|
+
*/
|
|
621
|
+
maxDescriptionLength?: number;
|
|
622
|
+
/**
|
|
623
|
+
* Remove all `examples` arrays from generated schemas — a token-budget
|
|
624
|
+
* trimming step that leaves validation keywords untouched.
|
|
625
|
+
* @default false
|
|
626
|
+
*/
|
|
627
|
+
stripExamples?: boolean;
|
|
565
628
|
/**
|
|
566
629
|
* Include OpenAPI parameter-level and media-type-level `example`/`examples`
|
|
567
630
|
* values in generated schemas (as JSON Schema `examples` arrays). These
|