@vinkius-core/mcp-fusion-openapi-gen 1.0.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 +211 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +176 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/ConfigLoader.d.ts +29 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +81 -0
- package/dist/config/ConfigLoader.js.map +1 -0
- package/dist/config/GeneratorConfig.d.ts +110 -0
- package/dist/config/GeneratorConfig.d.ts.map +1 -0
- package/dist/config/GeneratorConfig.js +80 -0
- package/dist/config/GeneratorConfig.js.map +1 -0
- package/dist/emitter/CodeEmitter.d.ts +41 -0
- package/dist/emitter/CodeEmitter.d.ts.map +1 -0
- package/dist/emitter/CodeEmitter.js +491 -0
- package/dist/emitter/CodeEmitter.js.map +1 -0
- package/dist/emitter/TemplateHelpers.d.ts +66 -0
- package/dist/emitter/TemplateHelpers.d.ts.map +1 -0
- package/dist/emitter/TemplateHelpers.js +115 -0
- package/dist/emitter/TemplateHelpers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/mapper/EndpointMapper.d.ts +28 -0
- package/dist/mapper/EndpointMapper.d.ts.map +1 -0
- package/dist/mapper/EndpointMapper.js +100 -0
- package/dist/mapper/EndpointMapper.js.map +1 -0
- package/dist/parser/OpenApiParser.d.ts +11 -0
- package/dist/parser/OpenApiParser.d.ts.map +1 -0
- package/dist/parser/OpenApiParser.js +173 -0
- package/dist/parser/OpenApiParser.js.map +1 -0
- package/dist/parser/RefResolver.d.ts +21 -0
- package/dist/parser/RefResolver.d.ts.map +1 -0
- package/dist/parser/RefResolver.js +90 -0
- package/dist/parser/RefResolver.js.map +1 -0
- package/dist/parser/types.d.ts +85 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +11 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/runtime/HttpHandlerFactory.d.ts +31 -0
- package/dist/runtime/HttpHandlerFactory.d.ts.map +1 -0
- package/dist/runtime/HttpHandlerFactory.js +90 -0
- package/dist/runtime/HttpHandlerFactory.js.map +1 -0
- package/dist/runtime/loadOpenAPI.d.ts +37 -0
- package/dist/runtime/loadOpenAPI.d.ts.map +1 -0
- package/dist/runtime/loadOpenAPI.js +50 -0
- package/dist/runtime/loadOpenAPI.js.map +1 -0
- package/dist/schema/ZodCompiler.d.ts +46 -0
- package/dist/schema/ZodCompiler.d.ts.map +1 -0
- package/dist/schema/ZodCompiler.js +216 -0
- package/dist/schema/ZodCompiler.js.map +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# @vinkius-core/mcp-fusion-openapi-gen
|
|
2
|
+
|
|
3
|
+
> OpenAPI 3.x → **MCP Fusion** Server Generator
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vinkius-core/mcp-fusion-openapi-gen)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](../../LICENSE)
|
|
8
|
+
|
|
9
|
+
Parse any OpenAPI 3.x spec and generate a **complete, ready-to-run MCP Server** powered by **MCP Fusion** — with Presenters, Tools, ToolRegistry, and server bootstrap. All features configurable via YAML.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What It Generates
|
|
14
|
+
|
|
15
|
+
Given an OpenAPI spec (YAML/JSON), the generator produces:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
output/
|
|
19
|
+
├── models/ # M — Zod schemas (data boundary)
|
|
20
|
+
│ ├── pet.schema.ts
|
|
21
|
+
│ └── store.schema.ts
|
|
22
|
+
├── views/ # V — createPresenter() (perception layer)
|
|
23
|
+
│ ├── pet.presenter.ts
|
|
24
|
+
│ └── store.presenter.ts
|
|
25
|
+
├── agents/ # A — Agent layer — defineTool()
|
|
26
|
+
│ ├── pet.tool.ts
|
|
27
|
+
│ └── store.tool.ts
|
|
28
|
+
├── server.ts # MCP Server bootstrap
|
|
29
|
+
└── index.ts # ToolRegistry + registerAll barrel
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Every file follows the **[MVA Convention](/mva-convention)** — the standard directory structure for **MCP Fusion** projects.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @vinkius-core/mcp-fusion-openapi-gen
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### 1. Generate from OpenAPI spec
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx openapi-gen --input ./petstore.yaml --output ./generated
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Run the generated server
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
API_BASE_URL=https://api.example.com npx tsx ./generated/server.ts
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
That's it — you have a fully functional MCP Server.
|
|
55
|
+
|
|
56
|
+
## Configuration
|
|
57
|
+
|
|
58
|
+
Create an `openapi-gen.yaml` file in your project root for full control:
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
# openapi-gen.yaml
|
|
62
|
+
input: ./specs/petstore.yaml
|
|
63
|
+
output: ./generated
|
|
64
|
+
|
|
65
|
+
features:
|
|
66
|
+
tags: true # Add tags to tools
|
|
67
|
+
annotations: true # Infer readOnly, destructive, idempotent from HTTP method
|
|
68
|
+
presenters: true # Generate Presenter files with response schemas
|
|
69
|
+
descriptions: true # Include summaries/descriptions on actions
|
|
70
|
+
toonDescription: false # Enable TOON-optimized descriptions
|
|
71
|
+
serverFile: true # Generate server.ts bootstrap
|
|
72
|
+
deprecated: comment # 'include' | 'skip' | 'comment'
|
|
73
|
+
|
|
74
|
+
naming:
|
|
75
|
+
style: snake_case # 'snake_case' | 'camelCase'
|
|
76
|
+
deduplication: true # Auto-suffix duplicates (_2, _3, ...)
|
|
77
|
+
|
|
78
|
+
server:
|
|
79
|
+
name: petstore-mcp
|
|
80
|
+
version: 1.0.0
|
|
81
|
+
transport: stdio # 'stdio' | 'sse'
|
|
82
|
+
toolExposition: flat # 'flat' | 'grouped' — how the LLM sees your tools
|
|
83
|
+
actionSeparator: '_' # Flat mode delimiter: pet_get_by_id
|
|
84
|
+
|
|
85
|
+
context:
|
|
86
|
+
import: '../types.js#AppCtx' # Custom context type
|
|
87
|
+
|
|
88
|
+
# Tag filtering
|
|
89
|
+
includeTags:
|
|
90
|
+
- pet
|
|
91
|
+
- store
|
|
92
|
+
excludeTags:
|
|
93
|
+
- internal
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Auto-detected when present, or pass explicitly:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npx openapi-gen --config ./openapi-gen.yaml
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## CLI Options
|
|
103
|
+
|
|
104
|
+
| Flag | Description | Default |
|
|
105
|
+
|------|-------------|---------|
|
|
106
|
+
| `--input <path>` | Path to OpenAPI YAML/JSON spec | From config |
|
|
107
|
+
| `--output <dir>` | Output directory | `./generated` |
|
|
108
|
+
| `--config <path>` | Path to config file | Auto-detect `openapi-gen.yaml` |
|
|
109
|
+
| `--base-url <expr>` | Base URL expression for fetch calls | `ctx.baseUrl` |
|
|
110
|
+
| `--server-name <name>` | MCP Server name | `openapi-mcp-server` |
|
|
111
|
+
| `--context <import>` | Custom context type import | Default `ApiContext` |
|
|
112
|
+
|
|
113
|
+
CLI flags override config file values.
|
|
114
|
+
|
|
115
|
+
## Generated Code Features
|
|
116
|
+
|
|
117
|
+
### Annotations (from HTTP Method)
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// GET → readOnly: true
|
|
121
|
+
// DELETE → destructive: true
|
|
122
|
+
// PUT → idempotent: true
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Coerced Path/Query Parameters
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Path and query params use z.coerce for safe string-to-type conversion
|
|
129
|
+
petId: z.coerce.number().int().describe('ID of pet to return')
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Presenter Binding
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Each action with a response schema binds to a Presenter
|
|
136
|
+
get_pet_by_id: {
|
|
137
|
+
returns: PetPresenter,
|
|
138
|
+
// ...
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Tag Filtering
|
|
143
|
+
|
|
144
|
+
Only generate tools for the tags you need:
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
includeTags: [pet] # Only pet tools
|
|
148
|
+
excludeTags: [internal] # Everything except internal
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Custom Context
|
|
152
|
+
|
|
153
|
+
Inject your own typed context into all tools:
|
|
154
|
+
|
|
155
|
+
```yaml
|
|
156
|
+
context:
|
|
157
|
+
import: '../types.js#AppCtx'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Generates:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import type { AppCtx } from '../types.js';
|
|
164
|
+
const petTools = defineTool<AppCtx>('pet', { ... });
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Programmatic API
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { parseOpenAPI, mapEndpoints, emitFiles, mergeConfig } from '@vinkius-core/mcp-fusion-openapi-gen';
|
|
171
|
+
|
|
172
|
+
const spec = parseOpenAPI(yamlString);
|
|
173
|
+
const mapped = mapEndpoints(spec);
|
|
174
|
+
const config = mergeConfig({ features: { tags: true }, includeTags: ['pet'] });
|
|
175
|
+
const files = emitFiles(mapped, config);
|
|
176
|
+
|
|
177
|
+
for (const file of files) {
|
|
178
|
+
writeFileSync(`./out/${file.path}`, file.content);
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Pipeline
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
OpenAPI 3.x Spec (YAML/JSON)
|
|
186
|
+
│
|
|
187
|
+
▼
|
|
188
|
+
┌─────────────┐
|
|
189
|
+
│ OpenApiParser │ → ApiSpec IR (groups, actions, params, responses)
|
|
190
|
+
└─────────────┘
|
|
191
|
+
│
|
|
192
|
+
▼
|
|
193
|
+
┌───────────────┐
|
|
194
|
+
│ EndpointMapper │ → Named actions (snake_case), dedup, annotations
|
|
195
|
+
└───────────────┘
|
|
196
|
+
│
|
|
197
|
+
▼
|
|
198
|
+
┌────────────┐
|
|
199
|
+
│ CodeEmitter │ → TypeScript files (Presenters, Tools, Registry, Server)
|
|
200
|
+
└────────────┘
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Requirements
|
|
204
|
+
|
|
205
|
+
- Node.js ≥ 18
|
|
206
|
+
- `@vinkius-core/mcp-fusion` ^2.0.0 (peer dependency)
|
|
207
|
+
- `zod` ^3.25.1 || ^4.0.0 (peer dependency)
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI Entry Point — openapi-gen
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* openapi-gen generate -i <spec> -o <outDir> [--config <config.yaml>] [--base-url <url>]
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
11
|
+
import { resolve, join } from 'node:path';
|
|
12
|
+
import { parseOpenAPI } from './parser/OpenApiParser.js';
|
|
13
|
+
import { mapEndpoints } from './mapper/EndpointMapper.js';
|
|
14
|
+
import { emitFiles } from './emitter/CodeEmitter.js';
|
|
15
|
+
import { loadConfig, applyCliOverrides } from './config/ConfigLoader.js';
|
|
16
|
+
function parseArgs(argv) {
|
|
17
|
+
const args = argv.slice(2);
|
|
18
|
+
const command = args[0] ?? '';
|
|
19
|
+
const result = {};
|
|
20
|
+
for (let i = 1; i < args.length; i++) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
switch (arg) {
|
|
23
|
+
case '-i':
|
|
24
|
+
case '--input':
|
|
25
|
+
result['input'] = args[++i];
|
|
26
|
+
break;
|
|
27
|
+
case '-o':
|
|
28
|
+
case '--output':
|
|
29
|
+
result['output'] = args[++i];
|
|
30
|
+
break;
|
|
31
|
+
case '--base-url':
|
|
32
|
+
result['baseUrl'] = args[++i];
|
|
33
|
+
break;
|
|
34
|
+
case '--context':
|
|
35
|
+
result['context'] = args[++i];
|
|
36
|
+
break;
|
|
37
|
+
case '-c':
|
|
38
|
+
case '--config':
|
|
39
|
+
result['config'] = args[++i];
|
|
40
|
+
break;
|
|
41
|
+
case '--server-name':
|
|
42
|
+
result['serverName'] = args[++i];
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
command,
|
|
48
|
+
...(result['input'] !== undefined ? { input: result['input'] } : {}),
|
|
49
|
+
...(result['output'] !== undefined ? { output: result['output'] } : {}),
|
|
50
|
+
...(result['baseUrl'] !== undefined ? { baseUrl: result['baseUrl'] } : {}),
|
|
51
|
+
...(result['context'] !== undefined ? { context: result['context'] } : {}),
|
|
52
|
+
...(result['config'] !== undefined ? { config: result['config'] } : {}),
|
|
53
|
+
...(result['serverName'] !== undefined ? { serverName: result['serverName'] } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// ── Commands ─────────────────────────────────────────────
|
|
57
|
+
function runGenerate(rawArgs) {
|
|
58
|
+
// Load config (YAML file → defaults → CLI overrides)
|
|
59
|
+
const baseConfig = loadConfig(rawArgs.config);
|
|
60
|
+
const overrides = {
|
|
61
|
+
...(rawArgs.input !== undefined ? { input: rawArgs.input } : {}),
|
|
62
|
+
...(rawArgs.output !== undefined ? { output: rawArgs.output } : {}),
|
|
63
|
+
...(rawArgs.baseUrl !== undefined ? { baseUrl: rawArgs.baseUrl } : {}),
|
|
64
|
+
...(rawArgs.context !== undefined ? { contextImport: rawArgs.context } : {}),
|
|
65
|
+
...(rawArgs.serverName !== undefined ? { serverName: rawArgs.serverName } : {}),
|
|
66
|
+
};
|
|
67
|
+
const config = applyCliOverrides(baseConfig, overrides);
|
|
68
|
+
// Resolve input
|
|
69
|
+
const inputPath = config.input ?? rawArgs.input;
|
|
70
|
+
if (!inputPath) {
|
|
71
|
+
console.error('Error: --input (-i) is required (or set `input` in config file).');
|
|
72
|
+
console.error('Usage: openapi-gen generate -i <spec.yaml> -o <outDir>');
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const specPath = resolve(inputPath);
|
|
76
|
+
let specContent;
|
|
77
|
+
try {
|
|
78
|
+
specContent = readFileSync(specPath, 'utf-8');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
console.error(`Error: Cannot read file "${specPath}".`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
console.log(`📂 Parsing: ${specPath}`);
|
|
85
|
+
// Parse + Map
|
|
86
|
+
const spec = parseOpenAPI(specContent);
|
|
87
|
+
const mapped = mapEndpoints(spec);
|
|
88
|
+
console.log(`✅ Parsed: ${spec.title} v${spec.version}`);
|
|
89
|
+
console.log(`📋 Groups: ${mapped.groups.length}`);
|
|
90
|
+
const totalActions = mapped.groups.reduce((sum, g) => sum + g.actions.length, 0);
|
|
91
|
+
console.log(`🔧 Actions: ${totalActions}`);
|
|
92
|
+
// Show active features
|
|
93
|
+
console.log(`\n⚙️ Features:`);
|
|
94
|
+
console.log(` Tags: ${config.features.tags ? '✅' : '❌'}`);
|
|
95
|
+
console.log(` Annotations: ${config.features.annotations ? '✅' : '❌'}`);
|
|
96
|
+
console.log(` Presenters: ${config.features.presenters ? '✅' : '❌'}`);
|
|
97
|
+
console.log(` Descriptions: ${config.features.descriptions ? '✅' : '❌'}`);
|
|
98
|
+
console.log(` Server file: ${config.features.serverFile ? '✅' : '❌'}`);
|
|
99
|
+
console.log(` toonDescription: ${config.features.toonDescription ? '✅' : '❌'}`);
|
|
100
|
+
// Emit
|
|
101
|
+
const files = emitFiles(mapped, config);
|
|
102
|
+
// Write output
|
|
103
|
+
const outDir = resolve(config.output ?? './generated');
|
|
104
|
+
mkdirSync(outDir, { recursive: true });
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const filePath = join(outDir, file.path);
|
|
107
|
+
writeFileSync(filePath, file.content, 'utf-8');
|
|
108
|
+
console.log(` 📄 ${file.path}`);
|
|
109
|
+
}
|
|
110
|
+
console.log(`\n🎉 Generated ${files.length} files in ${outDir}`);
|
|
111
|
+
if (config.features.serverFile) {
|
|
112
|
+
console.log(`\n🚀 Run your MCP server:`);
|
|
113
|
+
console.log(` API_BASE_URL=https://api.example.com npx tsx ${outDir}/server.ts`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function printHelp() {
|
|
117
|
+
console.log(`
|
|
118
|
+
openapi-gen — OpenAPI → MCP Fusion Server Generator
|
|
119
|
+
|
|
120
|
+
USAGE:
|
|
121
|
+
openapi-gen generate -i <spec> -o <outDir> [options]
|
|
122
|
+
|
|
123
|
+
COMMANDS:
|
|
124
|
+
generate Parse OpenAPI spec and generate a complete MCP Server
|
|
125
|
+
|
|
126
|
+
OPTIONS:
|
|
127
|
+
-i, --input <file> OpenAPI spec file (YAML or JSON)
|
|
128
|
+
-o, --output <dir> Output directory (default: ./generated)
|
|
129
|
+
-c, --config <file> Config file (default: auto-detect openapi-gen.yaml)
|
|
130
|
+
--base-url <url> Base URL expression for fetch calls
|
|
131
|
+
--context <path#Type> Custom context type import
|
|
132
|
+
--server-name <name> MCP Server name
|
|
133
|
+
--help Show this help message
|
|
134
|
+
|
|
135
|
+
CONFIG FILE (openapi-gen.yaml):
|
|
136
|
+
input: ./petstore.yaml
|
|
137
|
+
output: ./src/generated
|
|
138
|
+
features:
|
|
139
|
+
tags: true
|
|
140
|
+
annotations: true
|
|
141
|
+
presenters: true
|
|
142
|
+
descriptions: true
|
|
143
|
+
deprecated: comment # skip | comment | include
|
|
144
|
+
toonDescription: false
|
|
145
|
+
serverFile: true
|
|
146
|
+
context:
|
|
147
|
+
import: '../types.js#AppCtx'
|
|
148
|
+
server:
|
|
149
|
+
name: my-api-server
|
|
150
|
+
version: 1.0.0
|
|
151
|
+
transport: stdio
|
|
152
|
+
includeTags: []
|
|
153
|
+
excludeTags: []
|
|
154
|
+
|
|
155
|
+
EXAMPLES:
|
|
156
|
+
openapi-gen generate -i petstore.yaml -o ./src/mcp
|
|
157
|
+
openapi-gen generate -i api.json -o ./mcp --config project.yaml
|
|
158
|
+
openapi-gen generate -i spec.yaml -o ./tools --server-name "my-tools"
|
|
159
|
+
`);
|
|
160
|
+
}
|
|
161
|
+
// ── Main ─────────────────────────────────────────────────
|
|
162
|
+
const cliArgs = parseArgs(process.argv);
|
|
163
|
+
switch (cliArgs.command) {
|
|
164
|
+
case 'generate':
|
|
165
|
+
runGenerate(cliArgs);
|
|
166
|
+
break;
|
|
167
|
+
case '--help':
|
|
168
|
+
case 'help':
|
|
169
|
+
case '':
|
|
170
|
+
printHelp();
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
console.error(`Unknown command: "${cliArgs.command}". Use --help for usage.`);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","source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AAC,2BAA2B,CAAC,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,mDAAmD,MAAM,YAAY,CAAC,CAAC;IACvF,CAAC;AACL,CAAC;AAED,SAAS,SAAS;IACd,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Cf,CAAC,CAAC;AACH,CAAC;AAED,4DAA4D;AAE5D,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAExC,QAAQ,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,KAAK,UAAU;QACX,WAAW,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM;IACV,KAAK,QAAQ,CAAC;IACd,KAAK,MAAM,CAAC;IACZ,KAAK,EAAE;QACH,SAAS,EAAE,CAAC;QACZ,MAAM;IACV;QACI,OAAO,CAAC,KAAK,CAAC,qBAAqB,OAAO,CAAC,OAAO,0BAA0B,CAAC,CAAC;QAC9E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type GeneratorConfig } from './GeneratorConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Load configuration from a YAML/JSON file.
|
|
4
|
+
*
|
|
5
|
+
* Priority:
|
|
6
|
+
* 1. Explicit `configPath` argument
|
|
7
|
+
* 2. Auto-detect `openapi-gen.yaml` in `cwd`
|
|
8
|
+
* 3. Fall back to all defaults
|
|
9
|
+
*
|
|
10
|
+
* @param configPath - Explicit path to config file (optional)
|
|
11
|
+
* @param cwd - Working directory for auto-detection (default: process.cwd())
|
|
12
|
+
* @returns Fully merged GeneratorConfig
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadConfig(configPath?: string, cwd?: string): GeneratorConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Merge a loaded config with CLI argument overrides.
|
|
17
|
+
*
|
|
18
|
+
* CLI args take precedence over file values.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyCliOverrides(config: GeneratorConfig, cli: CliOverrides): GeneratorConfig;
|
|
21
|
+
/** CLI arguments that can override config file values */
|
|
22
|
+
export interface CliOverrides {
|
|
23
|
+
readonly input?: string;
|
|
24
|
+
readonly output?: string;
|
|
25
|
+
readonly baseUrl?: string;
|
|
26
|
+
readonly contextImport?: string;
|
|
27
|
+
readonly serverName?: string;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ConfigLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigLoader.d.ts","sourceRoot":"","sources":["../../src/config/ConfigLoader.ts"],"names":[],"mappings":"AAWA,OAAO,EAAe,KAAK,eAAe,EAAsB,MAAM,sBAAsB,CAAC;AAY7F;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,eAAe,CAsB7E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,eAAe,CAe7F;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConfigLoader — YAML Configuration File Reader
|
|
3
|
+
*
|
|
4
|
+
* Loads `openapi-gen.yaml` from cwd or a specified path, validates
|
|
5
|
+
* the structure, and merges with defaults. CLI args override file values.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
10
|
+
import { resolve, join } from 'node:path';
|
|
11
|
+
import { parse as parseYaml } from 'yaml';
|
|
12
|
+
import { mergeConfig } from './GeneratorConfig.js';
|
|
13
|
+
// ── Filename Conventions ─────────────────────────────────
|
|
14
|
+
const CONFIG_FILENAMES = [
|
|
15
|
+
'openapi-gen.yaml',
|
|
16
|
+
'openapi-gen.yml',
|
|
17
|
+
'openapi-gen.json',
|
|
18
|
+
];
|
|
19
|
+
// ── Public API ───────────────────────────────────────────
|
|
20
|
+
/**
|
|
21
|
+
* Load configuration from a YAML/JSON file.
|
|
22
|
+
*
|
|
23
|
+
* Priority:
|
|
24
|
+
* 1. Explicit `configPath` argument
|
|
25
|
+
* 2. Auto-detect `openapi-gen.yaml` in `cwd`
|
|
26
|
+
* 3. Fall back to all defaults
|
|
27
|
+
*
|
|
28
|
+
* @param configPath - Explicit path to config file (optional)
|
|
29
|
+
* @param cwd - Working directory for auto-detection (default: process.cwd())
|
|
30
|
+
* @returns Fully merged GeneratorConfig
|
|
31
|
+
*/
|
|
32
|
+
export function loadConfig(configPath, cwd) {
|
|
33
|
+
const workDir = cwd ?? process.cwd();
|
|
34
|
+
// 1. Explicit path
|
|
35
|
+
if (configPath) {
|
|
36
|
+
const absPath = resolve(workDir, configPath);
|
|
37
|
+
if (!existsSync(absPath)) {
|
|
38
|
+
throw new Error(`Config file not found: "${absPath}"`);
|
|
39
|
+
}
|
|
40
|
+
return parseConfigFile(absPath);
|
|
41
|
+
}
|
|
42
|
+
// 2. Auto-detect
|
|
43
|
+
for (const filename of CONFIG_FILENAMES) {
|
|
44
|
+
const candidate = join(workDir, filename);
|
|
45
|
+
if (existsSync(candidate)) {
|
|
46
|
+
return parseConfigFile(candidate);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// 3. All defaults
|
|
50
|
+
return mergeConfig({});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Merge a loaded config with CLI argument overrides.
|
|
54
|
+
*
|
|
55
|
+
* CLI args take precedence over file values.
|
|
56
|
+
*/
|
|
57
|
+
export function applyCliOverrides(config, cli) {
|
|
58
|
+
return {
|
|
59
|
+
...config,
|
|
60
|
+
...(cli.input !== undefined ? { input: cli.input } : {}),
|
|
61
|
+
...(cli.output !== undefined ? { output: cli.output } : {}),
|
|
62
|
+
...(cli.baseUrl !== undefined ? { baseUrl: cli.baseUrl } : {}),
|
|
63
|
+
context: {
|
|
64
|
+
...config.context,
|
|
65
|
+
...(cli.contextImport !== undefined ? { import: cli.contextImport } : {}),
|
|
66
|
+
},
|
|
67
|
+
server: {
|
|
68
|
+
...config.server,
|
|
69
|
+
...(cli.serverName !== undefined ? { name: cli.serverName } : {}),
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// ── Internal ─────────────────────────────────────────────
|
|
74
|
+
function parseConfigFile(filePath) {
|
|
75
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
76
|
+
const raw = filePath.endsWith('.json')
|
|
77
|
+
? JSON.parse(content)
|
|
78
|
+
: parseYaml(content);
|
|
79
|
+
return mergeConfig(raw);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=ConfigLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigLoader.js","sourceRoot":"","sources":["../../src/config/ConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,WAAW,EAA4C,MAAM,sBAAsB,CAAC;AAE7F,4DAA4D;AAE5D,MAAM,gBAAgB,GAAG;IACrB,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;CACrB,CA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C,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,EAAE;YACL,GAAG,MAAM,CAAC,OAAO;YACjB,GAAG,CAAC,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5E;QACD,MAAM,EAAE;YACJ,GAAG,MAAM,CAAC,MAAM;YAChB,GAAG,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpE;KACJ,CAAC;AACN,CAAC;AAWD,4DAA4D;AAE5D,SAAS,eAAe,CAAC,QAAgB;IACrC,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAkB;QACtC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAkB,CAAC;IAE1C,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GeneratorConfig — Full Configuration for the OpenAPI-to-MCP Generator
|
|
3
|
+
*
|
|
4
|
+
* Controls every aspect of code generation: which MCP Fusion features
|
|
5
|
+
* are enabled, naming conventions, tag filtering, server scaffolding,
|
|
6
|
+
* and context injection.
|
|
7
|
+
*
|
|
8
|
+
* Can be loaded from a YAML file (`openapi-gen.yaml`) or passed programmatically.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Controls which MCP Fusion features appear in generated code.
|
|
14
|
+
* All fields default to `true` for maximum fidelity.
|
|
15
|
+
*/
|
|
16
|
+
export interface FeatureFlags {
|
|
17
|
+
/** Apply OpenAPI tags as MCP tool tags via `.tags()` */
|
|
18
|
+
readonly tags: boolean;
|
|
19
|
+
/** Infer `readOnly` / `destructive` / `idempotent` from HTTP methods */
|
|
20
|
+
readonly annotations: boolean;
|
|
21
|
+
/** Generate Presenter files with `createPresenter()` + Zod response schemas */
|
|
22
|
+
readonly presenters: boolean;
|
|
23
|
+
/** Chain `.describe()` on every Zod field that has an OpenAPI description */
|
|
24
|
+
readonly descriptions: boolean;
|
|
25
|
+
/** Handle deprecated operations: 'skip' = omit, 'comment' = add @deprecated JSDoc */
|
|
26
|
+
readonly deprecated: 'skip' | 'comment' | 'include';
|
|
27
|
+
/** Enable `toonDescription: true` on generated `defineTool()` calls */
|
|
28
|
+
readonly toonDescription: boolean;
|
|
29
|
+
/** Generate a complete MCP Server file (`server.ts`) with `attachToServer()` */
|
|
30
|
+
readonly serverFile: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Controls how action names are derived from operationId / path */
|
|
33
|
+
export interface NamingConfig {
|
|
34
|
+
/** Action naming style */
|
|
35
|
+
readonly style: 'snake_case' | 'camelCase';
|
|
36
|
+
/** Append _2, _3 for collision resolution */
|
|
37
|
+
readonly deduplication: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Controls the context type used in generated tools */
|
|
40
|
+
export interface ContextConfig {
|
|
41
|
+
/** Import path with type name, e.g. `'../src/types.js#MyAppContext'` */
|
|
42
|
+
readonly import?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Controls the generated MCP Server file */
|
|
45
|
+
export interface ServerConfig {
|
|
46
|
+
/** Server name shown to MCP clients */
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/** Server version */
|
|
49
|
+
readonly version: string;
|
|
50
|
+
/** Transport type for the generated server */
|
|
51
|
+
readonly transport: 'stdio' | 'sse';
|
|
52
|
+
/**
|
|
53
|
+
* Exposition strategy for projecting tools onto the MCP wire format.
|
|
54
|
+
* - `'flat'` — Each action becomes an independent MCP tool (default)
|
|
55
|
+
* - `'grouped'` — All actions in a builder merge into a single MCP tool
|
|
56
|
+
*/
|
|
57
|
+
readonly toolExposition: 'flat' | 'grouped';
|
|
58
|
+
/**
|
|
59
|
+
* Separator for flat mode action naming: `{toolName}{separator}{actionKey}`.
|
|
60
|
+
* @default '_'
|
|
61
|
+
* @example 'pet_get_by_id', 'pet.get_by_id', 'pet-get_by_id'
|
|
62
|
+
*/
|
|
63
|
+
readonly actionSeparator: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Complete generator configuration.
|
|
67
|
+
*
|
|
68
|
+
* Can be loaded from `openapi-gen.yaml` or passed to `emitFiles()`.
|
|
69
|
+
* All fields have sensible defaults — see {@link DEFAULT_CONFIG}.
|
|
70
|
+
*/
|
|
71
|
+
export interface GeneratorConfig {
|
|
72
|
+
/** Path to OpenAPI spec file (YAML or JSON) */
|
|
73
|
+
readonly input?: string;
|
|
74
|
+
/** Output directory for generated files */
|
|
75
|
+
readonly output?: string;
|
|
76
|
+
/** Base URL expression for fetch calls (default: `'ctx.baseUrl'`) */
|
|
77
|
+
readonly baseUrl?: string;
|
|
78
|
+
/** Feature toggles */
|
|
79
|
+
readonly features: FeatureFlags;
|
|
80
|
+
/** Naming conventions */
|
|
81
|
+
readonly naming: NamingConfig;
|
|
82
|
+
/** Context type injection */
|
|
83
|
+
readonly context: ContextConfig;
|
|
84
|
+
/** Server generation settings */
|
|
85
|
+
readonly server: ServerConfig;
|
|
86
|
+
/** Only generate tools for these tags (empty = all) */
|
|
87
|
+
readonly includeTags: readonly string[];
|
|
88
|
+
/** Exclude these tags from generation */
|
|
89
|
+
readonly excludeTags: readonly string[];
|
|
90
|
+
}
|
|
91
|
+
/** Default configuration — all features enabled */
|
|
92
|
+
export declare const DEFAULT_CONFIG: GeneratorConfig;
|
|
93
|
+
/**
|
|
94
|
+
* Deep-merge a partial config with defaults.
|
|
95
|
+
* Partial values override defaults at each level.
|
|
96
|
+
*/
|
|
97
|
+
export declare function mergeConfig(partial: PartialConfig): GeneratorConfig;
|
|
98
|
+
/** Partial config shape for merging */
|
|
99
|
+
export interface PartialConfig {
|
|
100
|
+
readonly input?: string;
|
|
101
|
+
readonly output?: string;
|
|
102
|
+
readonly baseUrl?: string;
|
|
103
|
+
readonly features?: Partial<FeatureFlags>;
|
|
104
|
+
readonly naming?: Partial<NamingConfig>;
|
|
105
|
+
readonly context?: Partial<ContextConfig>;
|
|
106
|
+
readonly server?: Partial<ServerConfig>;
|
|
107
|
+
readonly includeTags?: readonly string[];
|
|
108
|
+
readonly excludeTags?: readonly string[];
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=GeneratorConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeneratorConfig.d.ts","sourceRoot":"","sources":["../../src/config/GeneratorConfig.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACpD,uEAAuE;IACvE,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,gFAAgF;IAChF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAChC;AAID,oEAAoE;AACpE,MAAM,WAAW,YAAY;IACzB,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC;IAC3C,6CAA6C;IAC7C,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACnC;AAID,w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