mcp-from-openapi 2.6.1 → 2.8.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 +10 -3
- package/annotations.d.ts +16 -1
- package/arazzo-expressions.d.ts +19 -0
- package/arazzo-types.d.ts +262 -0
- package/arazzo.d.ts +45 -0
- package/elicitation.d.ts +44 -0
- package/errors.d.ts +8 -0
- package/esm/index.mjs +1807 -34
- package/esm/package.json +10 -8
- package/generator.d.ts +14 -0
- package/index.d.ts +12 -2
- package/index.js +1815 -34
- package/naming-presets.d.ts +49 -0
- package/package.json +10 -8
- package/ssrf.d.ts +5 -3
- package/type-signature.d.ts +43 -0
- package/types.d.ts +91 -4
- package/validator.d.ts +5 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming presets.
|
|
3
|
+
*
|
|
4
|
+
* `dottedNaming` produces two-segment `ns.method` tool names whose halves are
|
|
5
|
+
* valid JavaScript identifiers — the shape code-execution surfaces (FrontMCP
|
|
6
|
+
* CodeCall) bind as ergonomic namespaces: a tool named `billing.listInvoices`
|
|
7
|
+
* becomes `await billing.listInvoices({...})` in sandbox code. Names with any
|
|
8
|
+
* other shape (no dot, or a half that is not an identifier) still work via
|
|
9
|
+
* `callTool('name', input)` but get no namespace binding.
|
|
10
|
+
*/
|
|
11
|
+
import type { NamingStrategy } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Namespace identifiers reserved by FrontMCP CodeCall's sandbox globals —
|
|
14
|
+
* a namespace equal to one of these would shadow (or be shadowed by) a
|
|
15
|
+
* sandbox binding, so `dottedNaming` suffixes it with `_`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CODECALL_RESERVED_NAMESPACES: readonly string[];
|
|
18
|
+
/** Options for the {@link dottedNaming} preset. */
|
|
19
|
+
export interface DottedNamingOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Where the namespace half comes from: the operation's first tag, or the
|
|
22
|
+
* first path segment. `'tag'` falls back to the first path segment when the
|
|
23
|
+
* operation has no tags, then to `'api'`.
|
|
24
|
+
* @default 'tag'
|
|
25
|
+
*/
|
|
26
|
+
namespaceFrom?: 'tag' | 'firstPathSegment';
|
|
27
|
+
/**
|
|
28
|
+
* Additional reserved namespace names, merged with
|
|
29
|
+
* {@link CODECALL_RESERVED_NAMESPACES}.
|
|
30
|
+
*/
|
|
31
|
+
reservedNamespaces?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Naming preset producing two-segment `ns.method` tool names bindable by
|
|
35
|
+
* code-execution namespaces (e.g. FrontMCP CodeCall's `await ns.method({...})`).
|
|
36
|
+
*
|
|
37
|
+
* The namespace half comes from the operation's first tag (or first path
|
|
38
|
+
* segment); the method half from the operationId (an `x-mcp` family name
|
|
39
|
+
* override arrives through the operationId argument), falling back to the
|
|
40
|
+
* HTTP method plus the path. Both halves are sanitized to identifiers, so the
|
|
41
|
+
* emitted name contains exactly one dot.
|
|
42
|
+
*
|
|
43
|
+
* Collision dedup in `generateTools()` appends `_<hash>` to the method half,
|
|
44
|
+
* which keeps the name namespace-parseable. Hash truncation can remove the
|
|
45
|
+
* dot when the namespace half alone approaches `maxToolNameLength` (≥ 55
|
|
46
|
+
* chars at the default cap of 64) — such names remain valid MCP names but
|
|
47
|
+
* lose namespace binding.
|
|
48
|
+
*/
|
|
49
|
+
export declare function dottedNaming(options?: DottedNamingOptions): NamingStrategy;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-from-openapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/agentfront/mcp-from-openapi#readme",
|
|
30
30
|
"engines": {
|
|
31
|
-
"node": ">=
|
|
31
|
+
"node": ">=22.19.0"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
|
34
34
|
"main": "./index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@apidevtools/json-schema-ref-parser": "^
|
|
52
|
+
"@apidevtools/json-schema-ref-parser": "^16.0.2",
|
|
53
53
|
"openapi-types": "^12.1.3",
|
|
54
54
|
"yaml": "^2.9.0"
|
|
55
55
|
},
|
|
@@ -57,14 +57,16 @@
|
|
|
57
57
|
"zod": "^4.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@
|
|
60
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
61
|
+
"@swc/core": "~1.16.1",
|
|
61
62
|
"@swc/helpers": "^0.5.18",
|
|
62
63
|
"@swc/jest": "~0.2.38",
|
|
63
|
-
"@types/jest": "^
|
|
64
|
+
"@types/jest": "^30.0.0",
|
|
64
65
|
"@types/json-schema": "^7.0.15",
|
|
65
|
-
"@types/node": "^
|
|
66
|
-
"
|
|
67
|
-
"
|
|
66
|
+
"@types/node": "^26.4.1",
|
|
67
|
+
"ajv": "^8.17.0",
|
|
68
|
+
"esbuild": "^0.28.2",
|
|
69
|
+
"jest": "^30.5.1",
|
|
68
70
|
"tslib": "^2.8.1",
|
|
69
71
|
"typescript": "^5.0.0",
|
|
70
72
|
"zod": "^4.0.0"
|
package/ssrf.d.ts
CHANGED
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
* guard and the socket share one DNS resolution. This closes the
|
|
27
27
|
* DNS-rebinding TOCTOU where the client would otherwise re-resolve the
|
|
28
28
|
* hostname at connect time and reach a different (internal) address. The
|
|
29
|
-
* original hostname is preserved for the `Host` header and TLS SNI
|
|
29
|
+
* original hostname is preserved for the `Host` header and TLS SNI, and
|
|
30
|
+
* every request opens a fresh socket (never a pooled keep-alive one);
|
|
30
31
|
* - re-validates every redirect hop ({@link safeFetch}) instead of letting the
|
|
31
32
|
* HTTP client follow 3xx blindly.
|
|
32
33
|
*
|
|
@@ -154,8 +155,9 @@ export declare function makePinnedLookup(pinned: ResolvedAddress[]): (_hostname:
|
|
|
154
155
|
/**
|
|
155
156
|
* Node transport that pins the connection to the validated address(es) via a
|
|
156
157
|
* custom `lookup`, preserving the original hostname for the `Host` header and
|
|
157
|
-
* TLS SNI.
|
|
158
|
-
*
|
|
158
|
+
* TLS SNI. Each request uses a one-off agent so a shared keep-alive pool can't
|
|
159
|
+
* hand it a socket connected elsewhere. Manual redirects only (no `lookup`
|
|
160
|
+
* re-resolution between hops). Exported for tests.
|
|
159
161
|
*/
|
|
160
162
|
export declare function nodePinnedTransport(modules: NodeHttpModules): SsrfTransport;
|
|
161
163
|
/**
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript call-signature emission.
|
|
3
|
+
*
|
|
4
|
+
* Renders a tool's final JSON Schemas (2020-12, post client-target transforms)
|
|
5
|
+
* as TypeScript type text for code-execution surfaces such as FrontMCP
|
|
6
|
+
* CodeCall, which present tools as importable typed functions instead of raw
|
|
7
|
+
* tool JSON. The emitted return type is always the UNWRAPPED OpenAPI response
|
|
8
|
+
* type — consumers that wrap results (e.g. `{status, ok, data, error}`) must
|
|
9
|
+
* wrap the type themselves.
|
|
10
|
+
*/
|
|
11
|
+
import type { JsonSchema } from './types';
|
|
12
|
+
/** TypeScript rendering of one tool's call contract. */
|
|
13
|
+
export interface ToolTypeScriptInfo {
|
|
14
|
+
/**
|
|
15
|
+
* One-line arrow type with inline anonymous types, e.g.
|
|
16
|
+
* `(input: { id: string; limit?: number }) => Promise<{ name: string }>`
|
|
17
|
+
*/
|
|
18
|
+
signature: string;
|
|
19
|
+
/**
|
|
20
|
+
* Self-contained declaration text: JSDoc from schema descriptions, named
|
|
21
|
+
* `<ToolName>Input` / `<ToolName>Output` types, and a `declare function`.
|
|
22
|
+
*/
|
|
23
|
+
declaration: string;
|
|
24
|
+
}
|
|
25
|
+
/** Options for the type-signature printer. */
|
|
26
|
+
export interface TypeSignatureOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Nesting depth beyond which types collapse to `unknown`.
|
|
29
|
+
* @default 8
|
|
30
|
+
*/
|
|
31
|
+
maxDepth?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Derive a PascalCase TypeScript identifier from an MCP tool name
|
|
35
|
+
* (`[A-Za-z0-9_.-]`). Empty results become `Tool`; a leading digit is
|
|
36
|
+
* prefixed with `T` (`3d.scan` → `T3dScan`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function toPascalIdentifier(toolName: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Render a tool's TypeScript signature and self-contained declaration from
|
|
41
|
+
* its final (post-transform) schemas. Pure and deterministic.
|
|
42
|
+
*/
|
|
43
|
+
export declare function emitToolTypeScript(toolName: string, description: string | undefined, inputSchema: JsonSchema, outputSchema: JsonSchema | undefined, options?: TypeSignatureOptions): ToolTypeScriptInfo;
|
package/types.d.ts
CHANGED
|
@@ -84,6 +84,23 @@ export interface ToolAnnotations {
|
|
|
84
84
|
*/
|
|
85
85
|
openWorldHint?: boolean;
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Tool icon (MCP spec 2025-11-25).
|
|
89
|
+
*/
|
|
90
|
+
export interface ToolIcon {
|
|
91
|
+
/**
|
|
92
|
+
* Icon URI (`https:` or `data:`).
|
|
93
|
+
*/
|
|
94
|
+
src: string;
|
|
95
|
+
/**
|
|
96
|
+
* MIME type, e.g. `image/png`.
|
|
97
|
+
*/
|
|
98
|
+
mimeType?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Sizes the icon is available in, e.g. `['48x48', 'any']`.
|
|
101
|
+
*/
|
|
102
|
+
sizes?: string[];
|
|
103
|
+
}
|
|
87
104
|
/**
|
|
88
105
|
* Main MCP Tool definition generated from OpenAPI.
|
|
89
106
|
*
|
|
@@ -111,6 +128,21 @@ export interface McpOpenAPITool<TMeta extends ToolMetadata = ToolMetadata> {
|
|
|
111
128
|
* precedence).
|
|
112
129
|
*/
|
|
113
130
|
annotations?: ToolAnnotations;
|
|
131
|
+
/**
|
|
132
|
+
* MCP `_meta` (spec 2025-06-18): namespaced, client-visible metadata.
|
|
133
|
+
* Contains the `dev.agentfront.openapi/operation` entry when
|
|
134
|
+
* `GenerateOptions.emitMeta` is set, plus any `meta` object supplied via
|
|
135
|
+
* the `x-mcp` / `x-frontmcp` extensions (emitted even when the flag is
|
|
136
|
+
* off). Extension keys under `dev.agentfront.openapi/` are ignored, and
|
|
137
|
+
* pollution-gadget keys are stripped recursively.
|
|
138
|
+
*/
|
|
139
|
+
_meta?: Record<string, unknown>;
|
|
140
|
+
/**
|
|
141
|
+
* Tool icons (MCP spec 2025-11-25). From `x-frontmcp.icons` /
|
|
142
|
+
* `x-mcp.icons`, or the document's `info['x-logo']` when
|
|
143
|
+
* `GenerateOptions.inheritDocumentIcons` is set.
|
|
144
|
+
*/
|
|
145
|
+
icons?: ToolIcon[];
|
|
114
146
|
/**
|
|
115
147
|
* Combined input schema including all parameters
|
|
116
148
|
* (path, query, header, cookie, body)
|
|
@@ -297,6 +329,21 @@ export interface ToolMetadata {
|
|
|
297
329
|
* present only when there is something to know.
|
|
298
330
|
*/
|
|
299
331
|
responseHints?: ResponseHints;
|
|
332
|
+
/**
|
|
333
|
+
* TypeScript rendering of the tool's call contract — present when
|
|
334
|
+
* `GenerateOptions.emitTypeSignatures` is set. Computed on the FINAL
|
|
335
|
+
* schemas (after formats, depth truncation, trimming, and client-target
|
|
336
|
+
* transforms). The return type is the UNWRAPPED response type.
|
|
337
|
+
*/
|
|
338
|
+
typescript?: import('./type-signature').ToolTypeScriptInfo;
|
|
339
|
+
/**
|
|
340
|
+
* Arazzo workflow IR — present only on tools produced by `fromArazzo()`.
|
|
341
|
+
* When set, `path`/`method` are non-HTTP placeholders
|
|
342
|
+
* (`arazzo:<workflowId>` / `'post'`); executors must drive requests from
|
|
343
|
+
* `workflow.steps[*].operation.mapper`, never from this tool's (empty)
|
|
344
|
+
* top-level mapper.
|
|
345
|
+
*/
|
|
346
|
+
workflow?: import('./arazzo-types').WorkflowIR;
|
|
300
347
|
}
|
|
301
348
|
/**
|
|
302
349
|
* Detected response-shaping signals. Clients cap tool results hard (Claude
|
|
@@ -351,6 +398,14 @@ export interface FrontMcpExtensionData {
|
|
|
351
398
|
input: Record<string, unknown>;
|
|
352
399
|
output?: unknown;
|
|
353
400
|
}>;
|
|
401
|
+
/**
|
|
402
|
+
* MCP `_meta` entries to emit on the tool.
|
|
403
|
+
*/
|
|
404
|
+
meta?: Record<string, unknown>;
|
|
405
|
+
/**
|
|
406
|
+
* Tool icons to emit on the tool.
|
|
407
|
+
*/
|
|
408
|
+
icons?: ToolIcon[];
|
|
354
409
|
}
|
|
355
410
|
/**
|
|
356
411
|
* Security requirement definition
|
|
@@ -691,6 +746,35 @@ export interface GenerateOptions {
|
|
|
691
746
|
* When used without `resolveFormats`, only custom resolvers are applied.
|
|
692
747
|
*/
|
|
693
748
|
formatResolvers?: Record<string, FormatResolver>;
|
|
749
|
+
/**
|
|
750
|
+
* Emit a TypeScript rendering of each tool's call contract as
|
|
751
|
+
* `metadata.typescript = { signature, declaration }`. The signature is a
|
|
752
|
+
* one-line arrow type with inline anonymous types; the declaration is a
|
|
753
|
+
* self-contained block with named `<ToolName>Input` / `<ToolName>Output`
|
|
754
|
+
* types and JSDoc from schema descriptions. Computed on the FINAL schemas
|
|
755
|
+
* (after format resolution, depth truncation, trimming, and client-target
|
|
756
|
+
* transforms). The return type is the unwrapped OpenAPI response type —
|
|
757
|
+
* consumers that wrap results must wrap the type themselves.
|
|
758
|
+
* @default false
|
|
759
|
+
*/
|
|
760
|
+
emitTypeSignatures?: boolean;
|
|
761
|
+
/**
|
|
762
|
+
* Emit `_meta['dev.agentfront.openapi/operation']` on every tool with the
|
|
763
|
+
* source operation's coordinates: `{ path, method, operationId?, tags?,
|
|
764
|
+
* deprecated?, specTitle?, specVersion? }` (reverse-DNS key per MCP `_meta`
|
|
765
|
+
* conventions). Extension-supplied `meta` (`x-mcp` / `x-frontmcp`) merges
|
|
766
|
+
* on top and is emitted even when this flag is off.
|
|
767
|
+
* @default false
|
|
768
|
+
*/
|
|
769
|
+
emitMeta?: boolean;
|
|
770
|
+
/**
|
|
771
|
+
* When an operation has no extension-supplied icons, fall back to the
|
|
772
|
+
* document's `info['x-logo']` (Redoc convention) as a single icon applied
|
|
773
|
+
* to every tool. Off by default so one logo doesn't silently inflate all
|
|
774
|
+
* tool definitions.
|
|
775
|
+
* @default false
|
|
776
|
+
*/
|
|
777
|
+
inheritDocumentIcons?: boolean;
|
|
694
778
|
}
|
|
695
779
|
/**
|
|
696
780
|
* A function that enriches a JSON Schema based on its format field.
|
|
@@ -702,21 +786,24 @@ export type FormatResolver = (schema: JsonSchema) => JsonSchema;
|
|
|
702
786
|
*/
|
|
703
787
|
export interface NamingStrategy {
|
|
704
788
|
/**
|
|
705
|
-
* Resolver function for parameter name conflicts
|
|
789
|
+
* Resolver function for parameter name conflicts.
|
|
706
790
|
* @param paramName - Original parameter name
|
|
707
791
|
* @param location - Parameter location
|
|
708
792
|
* @param index - Index of conflicting parameter (0-based)
|
|
709
793
|
* @returns New parameter name
|
|
794
|
+
* @default a location-prefix resolver (`headerX_Trace`-style)
|
|
710
795
|
*/
|
|
711
|
-
conflictResolver
|
|
796
|
+
conflictResolver?: (paramName: string, location: ParameterLocation, index: number) => string;
|
|
712
797
|
/**
|
|
713
798
|
* Function to generate tool names
|
|
714
799
|
* @param path - OpenAPI path
|
|
715
800
|
* @param method - HTTP method
|
|
716
|
-
* @param operationId - Operation ID if available
|
|
801
|
+
* @param operationId - Operation ID if available (an `x-mcp` family name
|
|
802
|
+
* override arrives through this argument in place of the operationId)
|
|
803
|
+
* @param operation - The full operation object (for tag-aware strategies)
|
|
717
804
|
* @returns Tool name
|
|
718
805
|
*/
|
|
719
|
-
toolNameGenerator?: (path: string, method: HTTPMethod, operationId?: string) => string;
|
|
806
|
+
toolNameGenerator?: (path: string, method: HTTPMethod, operationId?: string, operation?: OperationObject) => string;
|
|
720
807
|
}
|
|
721
808
|
/**
|
|
722
809
|
* Validation result
|
package/validator.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ export declare class Validator {
|
|
|
14
14
|
/**
|
|
15
15
|
* Validate paths
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a local `#/components/parameters/<name>` reference (JSON Pointer
|
|
19
|
+
* tokens decoded). Returns undefined for external or dangling references.
|
|
20
|
+
*/
|
|
21
|
+
private resolveParameterRef;
|
|
17
22
|
private validatePaths;
|
|
18
23
|
/**
|
|
19
24
|
* Validate an operation
|