@christopher_dondici/mcp-gen 2.1.2

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +217 -0
  2. package/LICENSE +21 -0
  3. package/README.md +439 -0
  4. package/README.pt-BR.md +320 -0
  5. package/RELEASE_NOTES.md +98 -0
  6. package/SECURITY.md +75 -0
  7. package/SECURITY.pt-BR.md +77 -0
  8. package/dist/cli/index.d.ts +3 -0
  9. package/dist/cli/index.d.ts.map +1 -0
  10. package/dist/cli/index.js +685 -0
  11. package/dist/cli/index.js.map +1 -0
  12. package/dist/core/generator.d.ts +4 -0
  13. package/dist/core/generator.d.ts.map +1 -0
  14. package/dist/core/generator.js +275 -0
  15. package/dist/core/generator.js.map +1 -0
  16. package/dist/core/incremental.d.ts +25 -0
  17. package/dist/core/incremental.d.ts.map +1 -0
  18. package/dist/core/incremental.js +91 -0
  19. package/dist/core/incremental.js.map +1 -0
  20. package/dist/core/parser.d.ts +3 -0
  21. package/dist/core/parser.d.ts.map +1 -0
  22. package/dist/core/parser.js +372 -0
  23. package/dist/core/parser.js.map +1 -0
  24. package/dist/core/registry.d.ts +13 -0
  25. package/dist/core/registry.d.ts.map +1 -0
  26. package/dist/core/registry.js +107 -0
  27. package/dist/core/registry.js.map +1 -0
  28. package/dist/core/security-lint.d.ts +53 -0
  29. package/dist/core/security-lint.d.ts.map +1 -0
  30. package/dist/core/security-lint.js +470 -0
  31. package/dist/core/security-lint.js.map +1 -0
  32. package/dist/core/security.d.ts +41 -0
  33. package/dist/core/security.d.ts.map +1 -0
  34. package/dist/core/security.js +150 -0
  35. package/dist/core/security.js.map +1 -0
  36. package/dist/core/templating.d.ts +5 -0
  37. package/dist/core/templating.d.ts.map +1 -0
  38. package/dist/core/templating.js +211 -0
  39. package/dist/core/templating.js.map +1 -0
  40. package/dist/core/types.d.ts +104 -0
  41. package/dist/core/types.d.ts.map +1 -0
  42. package/dist/core/types.js +3 -0
  43. package/dist/core/types.js.map +1 -0
  44. package/dist/index.d.ts +7 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +20 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/templates/go/Dockerfile.hbs +16 -0
  49. package/dist/templates/go/README.md.hbs +77 -0
  50. package/dist/templates/go/ci.yml.hbs +28 -0
  51. package/dist/templates/go/client.go.hbs +86 -0
  52. package/dist/templates/go/go.mod.hbs +5 -0
  53. package/dist/templates/go/models.go.hbs +28 -0
  54. package/dist/templates/go/server.go.hbs +220 -0
  55. package/dist/templates/python/Dockerfile.hbs +12 -0
  56. package/dist/templates/python/README.md.hbs +115 -0
  57. package/dist/templates/python/ci.yml.hbs +24 -0
  58. package/dist/templates/python/models.py.hbs +20 -0
  59. package/dist/templates/python/requirements.txt.hbs +3 -0
  60. package/dist/templates/python/server.py.hbs +195 -0
  61. package/dist/templates/typescript/Dockerfile.hbs +18 -0
  62. package/dist/templates/typescript/README.md.hbs +91 -0
  63. package/dist/templates/typescript/ci.yml.hbs +28 -0
  64. package/dist/templates/typescript/client.hbs +49 -0
  65. package/dist/templates/typescript/models.hbs +23 -0
  66. package/dist/templates/typescript/package.json.hbs +26 -0
  67. package/dist/templates/typescript/server.hbs +337 -0
  68. package/dist/templates/typescript/tsconfig.json.hbs +17 -0
  69. package/examples/petstore.json +130 -0
  70. package/examples/petstore.yaml +131 -0
  71. package/examples/week3.json +47 -0
  72. package/package.json +64 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,217 @@
1
+ # Changelog
2
+
3
+ Todas as mudanças notáveis do projeto serão documentadas neste arquivo.
4
+
5
+ ## [2.1.2] - Prepared for release (2026-09-17)
6
+
7
+ ### Packaging & Distribution
8
+
9
+ - `@christopher_dondici/mcp-gen` 2.1.2 prepared for release; not yet published to npm
10
+ - Scoped npm name after rejection of `mcp-gen` for similarity to `mcpgen`; version, `mcp-gen` binary and repository unchanged
11
+ - Public scoped publication configured; CI and release install and validate the scoped tarball before publication
12
+ - Build, packaging, CI, and dependency fixes only; no new runtime features
13
+ - Portable template copy (`fs.cpSync`) replacing Windows-only `xcopy`
14
+ - Versioned `package-lock.json` enabling `npm ci`
15
+ - Package `files` allowlist + `prepack` build so tarballs are complete
16
+ - Release workflow gates `npm publish` on `HAS_NPM_TOKEN` env instead of `secrets` in `if`
17
+ - New CI workflow: typecheck, tests, build, `npm pack` and tarball install smoke test on push/PR
18
+ - Dependency updates: fast-uri 3.1.8, hono 4.13.8, js-yaml 4.3.2, qs 6.16.0
19
+ - Package and lockfile versions aligned to 2.1.2; repository URL normalized to the official `git+https` format
20
+ - English/Portuguese READMEs and `RELEASE_NOTES.md` aligned with 2.1.2 preparation, source quick start, and conditional npm installation; 2.1.1 history preserved
21
+
22
+ ---
23
+
24
+ ## [2.1.1] - 2026-08-07
25
+
26
+ ### 🛡️ MCP Security & Lint Layer (New)
27
+
28
+ - **Security scanning** (`mcp-gen security <path>`): Scans generated MCP projects for:
29
+ - Raw credential detection (API keys, tokens, secrets, JWTs, AWS keys, etc.)
30
+ - `authContext` contract validation (scoped metadata vs raw credentials)
31
+ - Tool policy enforcement (TTL, spend limits, revocation, audit logging)
32
+ - **Lint checks**: Naming conventions, empty descriptions, TODO/FIXME in generated code, incremental marker balance, schema completeness
33
+ - **JSON output** (`--json`) for CI/CD integration
34
+ - **Fail-on-warn** (`--fail-on-warn`) for strict pipelines
35
+ - **Interactive mode** support in CLI
36
+ - **Library API exports**: `scanProject`, `formatReport`, `SecurityRule`, `SecurityReport`
37
+ - **11 new tests** covering credential scanning, authContext validation, incremental markers, project scanning, report formatting
38
+
39
+ ### 🔧 Generated Template Improvements
40
+
41
+ - **TypeScript**: Enhanced `RAW_CREDENTIAL_KEYS` + `TOOL_POLICIES` with per-tool policies, `requireSecurity` helper
42
+ - **Python**: Complete authContext validation with `require_security`, raw credential blocking
43
+ - **Go**: Full security layer with `RAW_CREDENTIAL_KEYS` map, `TOOL_POLICIES` struct, `hasRawCredentialKey`, `requireSecurity`
44
+
45
+ ---
46
+
47
+ ## [2.1.0] - 2026-08-07
48
+
49
+ ### 🚀 Major Features
50
+
51
+ - **Go target (new language)**: Generate MCP servers using `mark3labs/mcp-go` with full parity — `main.go`, `models.go`, `client.go`, `go.mod`, `README.md`, `Dockerfile`, GitHub Actions CI.
52
+ - **HTTP mode (`--http`)**: Generated handlers call the **real API** over HTTP (`fetch` / `httpx` / `net/http`) instead of returning example stubs. Controlled by `--http` flag or `--env-file` for credential injection.
53
+ - **Library API (programmatic usage)**: Export `generate`, `validateSpec`, `parseOpenAPI`, `extractHandlers`, `injectHandlers`, `listKnownSpecs`, `fetchSpecToCwd` + all types from `src/index.ts`.
54
+ - **Rich `validate` command**: Detailed warnings for tool-name collisions, missing examples, unsupported schemas, duplicate operations, etc.
55
+ - **Parser v3**: Full `$ref` resolution in parameters & requestBody; header/cookie params included; real enum union types (TypeScript `type X = "a" | "b"`, Python `Literal`, Go `type X = string` + `var` constants); unique tool names with collision suffixes; reserved-word sanitization (`new`, `delete`, `class`, etc. → `new_`).
56
+ - **Safe description escaping**: Central `escapeText` helper prevents template injection/breakage from arbitrary OpenAPI descriptions.
57
+ - **CLI version sync**: Single source of truth in `package.json`; CLI reads version at runtime.
58
+ - **Interactive HTTP prompts**: When `--http` is used without `--env-file`, prompts ask for BASE_URL and TOKEN.
59
+
60
+ ### 🐛 Fixes
61
+
62
+ - Tool-name collisions resolved with unique `_<hash>` suffixes
63
+ - Reserved words in tool names sanitized
64
+ - `$ref` in parameters/requestBody no longer silently skipped
65
+ - Header/cookie parameters now included in tool signatures
66
+ - Enums emitted as real union types (not loose `string`)
67
+ - Descriptions with special chars (quotes, newlines) no longer break templates
68
+ - Go `mcp.PropertyOption` API corrected (`mcp.Description`, `mcp.Required`)
69
+ - Python `_call_api` made `async` (was sync with `async with`)
70
+
71
+ ### 📚 Documentation
72
+
73
+ - README updated with Go target, `--http` mode, library API, authContext contract, programmatic usage
74
+ - CHANGELOG v2.1.0 entry
75
+
76
+ ### ⚠️ Known Limitations
77
+
78
+ - OpenAPI v2 (Swagger) not supported — v3.x only
79
+ - `oneOf`/`anyOf`/`discriminator` generate union types but no runtime validation
80
+ - Streaming/resources/prompts not yet implemented
81
+
82
+ ---
83
+
84
+ ## [2.0.0] - 2026-05-11
85
+
86
+ ### 🎉 Major Release 2.0
87
+
88
+ Este é o release v2.0.0 de `mcp-gen` — uma versão completa e estável compilada de 7 semanas de desenvolvimento, pronta para produção.
89
+
90
+ ### ✨ Features
91
+
92
+ - **OpenAPI v3 Parser**: Suporte completo a OpenAPI v3.0.0, v3.0.1, v3.0.2, v3.0.3, v3.1.0
93
+ - `oneOf`, `anyOf`, `discriminator` support
94
+ - Schema validation com `@apidevtools/swagger-parser`
95
+ - JSON e YAML inputs
96
+
97
+ - **Code Generation**
98
+ - TypeScript: ESM com tipos completos
99
+ - Python: FastMCP com Pydantic v2
100
+ - Incremental generation com marcadores `@@mcp-gen:start/end`
101
+ - Preservação de código customizado entre regenerações
102
+
103
+ - **CLI & Tools**
104
+ - 4 comandos principais: `generate`, `validate`, `init`, `watch`
105
+ - CLI interativa com `inquirer`
106
+ - Registry pré-configurado com 10+ APIs públicas
107
+ - Support para plugins customizados
108
+ - Watch mode com polling de URLs
109
+
110
+ - **API Registry**
111
+ - Stripe Payment API
112
+ - GitHub REST API
113
+ - Slack Web API
114
+ - OpenAI API
115
+ - Petstore (exemplo)
116
+ - Twilio Communications API
117
+ - Shopify Admin API
118
+ - Kubernetes API
119
+ - DigitalOcean API
120
+ - Azure Resource Manager API
121
+
122
+ - **Deployment Ready**
123
+ - Dockerfile gerado automaticamente
124
+ - GitHub Actions CI/CD template
125
+ - package.json / requirements.txt configurados
126
+ - tsconfig.json / Python environment ready
127
+
128
+ ### 🐛 Fixes
129
+
130
+ - Remoção de dependências desnecessárias
131
+ - Melhor tratamento de erros no parser
132
+ - Validação mais robusta de specs inválidas
133
+ - Tratamento correto de parâmetros opcionais
134
+
135
+ ### 📚 Documentation
136
+
137
+ - README completo com quick start
138
+ - Documentação em Português (README.pt-BR.md)
139
+ - CLI help com exemplos
140
+ - Guia de plugins
141
+ - Roadmap transparente
142
+
143
+ ### ⚠️ Known Limitations
144
+
145
+ - OpenAPI v2 (Swagger) não suportado — apenas v3.x
146
+ - `oneOf` / `anyOf` com múltiplos níveis pode ter edge cases
147
+ - Copy templates no Windows requer `xcopy` (já configurado)
148
+ - Performance: Specs muito grandes (>50MB) podem ser lentas
149
+
150
+ ### 🔧 Technical Details
151
+
152
+ - Node.js 20+ requerido
153
+ - Handlebars v4.7+ para templating
154
+ - MCP SDK v1.0.0+
155
+ - Testes com Jest
156
+ - TypeScript 5.4+
157
+
158
+ ### 📦 Versioning
159
+
160
+ A partir de `v1.0.0-rc.1`:
161
+ - Versão RC: `v1.0.0-rc.N`
162
+ - Versão final: `v1.0.0`
163
+ - npm tag: `@rc` para release candidates, `@latest` para stable
164
+
165
+ Publicado em npm como:
166
+ ```bash
167
+ npm install mcp-gen@rc # v1.0.0-rc.1
168
+ npm install mcp-gen@latest # Quando v1.0.0 for lançado
169
+ ```
170
+
171
+ ### 🙏 Thanks
172
+
173
+ - Comunidade MCP por feedback
174
+ - Anthropic pelos docs e SDK
175
+ - OpenAPI initiative pela spec
176
+ - Contribuidores early testers
177
+
178
+ ### 📖 For RC Testing
179
+
180
+ Se você está testando a RC, por favor:
181
+
182
+ 1. **Report Issues**: Use [GitHub Issues](https://github.com/ChristopherDond/MCP-Generator/issues)
183
+ 2. **Share Feedback**: [Discussions](https://github.com/ChristopherDond/MCP-Generator/discussions)
184
+ 3. **Try Examples**: Rode `mcp-gen init --from stripe --generate -o ./stripe-mcp`
185
+ 4. **Test Registry**: Experimente diferentes APIs
186
+
187
+ ### 🚀 Next Steps (RC → v1.0.0)
188
+
189
+ Planejado para RC.2 e beyond:
190
+
191
+ - [ ] Plugin system com melhor documentação
192
+ - [ ] Suporte a OpenAPI v3.1 discriminator melhorado
193
+ - [ ] Mais templates (Go, Rust, outros?)
194
+ - [ ] Performance improvements
195
+ - [ ] Integração com ferramentas populares
196
+ - [ ] Type inference melhorado para complex schemas
197
+
198
+ ---
199
+
200
+ ## [0.1.0] - 2026-04-01
201
+
202
+ ### Initial Development
203
+
204
+ Project initialization com conceito básico.
205
+
206
+ ---
207
+
208
+ ## Versioning
209
+
210
+ Seguimos [Semantic Versioning](https://semver.org/):
211
+ - **MAJOR.MINOR.PATCH** para releases estáveis
212
+ - **MAJOR.MINOR.PATCH-rc.N** para release candidates
213
+ - **MAJOR.MINOR.PATCH-alpha.N** para alpha versions
214
+
215
+ ## How to Contribute
216
+
217
+ Veja [CONTRIBUTING.md](./CONTRIBUTING.md) (quando criado) ou abra uma discussion em GitHub Issues.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christopher Dondici
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,439 @@
1
+ # MCP-Generator
2
+
3
+ > **Also available in:** [Português (Versão em Português)](README.pt-BR.md)
4
+
5
+ Generate MCP servers from OpenAPI specs.
6
+
7
+ > **Status**: `@christopher_dondici/mcp-gen` 2.1.2 is prepared for release and has not been published to npm. This release includes build, packaging, CI, and dependency fixes, with no new runtime features. Use the source quick start below. See [release notes](RELEASE_NOTES.md) (PT-BR).
8
+
9
+ `mcp-gen` turns an OpenAPI v3 spec into an MCP server in **TypeScript**, **Python**, or **Go**. It maps each route to a tool, generates typed models (including enums, oneOf/anyOf), and keeps custom code when you regenerate.
10
+
11
+ ## Quick start
12
+
13
+ With Git, Node.js 20+ and npm 9+ installed, run:
14
+
15
+ ```bash
16
+ git clone https://github.com/ChristopherDond/MCP-Generator.git
17
+ cd MCP-Generator
18
+ npm ci
19
+ npm run build
20
+ node dist/cli/index.js --version
21
+ ```
22
+
23
+ Generate a server from a local spec:
24
+
25
+ ```bash
26
+ node dist/cli/index.js generate -i examples/petstore.yaml -l typescript -o ./my-server
27
+ ```
28
+
29
+ Validate a spec without generating files:
30
+
31
+ ```bash
32
+ node dist/cli/index.js validate -i examples/petstore.yaml
33
+ ```
34
+
35
+ Run these commands from the repository root on `main`. The build and packaging fixes are part of 2.1.2. Generation writes a scaffold; it does not install dependencies, build, or start the generated server.
36
+
37
+ Run the interactive CLI if you prefer prompts:
38
+
39
+ ```bash
40
+ npm run dev
41
+ ```
42
+
43
+ ## What it does
44
+
45
+ ```mermaid
46
+ sequenceDiagram
47
+ participant User
48
+ participant CLI
49
+ participant Parser
50
+ participant Generator
51
+ participant Output
52
+
53
+ User->>CLI: mcp-gen generate --input api.yaml --lang go
54
+ CLI->>Parser: validate and parse OpenAPI v3 (JSON or YAML)
55
+ Parser->>Generator: internal AST (tools, models, examples)
56
+ Generator->>Output: render Handlebars templates
57
+ Output-->>User: TypeScript, Python, or Go MCP server project
58
+ ```
59
+
60
+ Each route becomes an MCP tool with:
61
+
62
+ - typed input from parameters (path, query, header, cookie, body) and request bodies
63
+ - example responses from the spec
64
+ - enum / oneOf / anyOf / discriminator schema support
65
+ - real HTTP client mode (`--http`) that calls the actual API
66
+ - scaffolded authContext checks for scoped metadata and credential-like argument keys; review before deployment
67
+ - optional incremental code preservation
68
+
69
+ ## Requirements
70
+
71
+ - Node.js 20+
72
+ - npm 9+ (the source quick start uses the repository lockfile)
73
+ - Git to clone the repository
74
+ - (Optional) Python 3.8+ for Python projects
75
+ - (Optional) Go 1.22+ for Go projects
76
+
77
+ ## Local installation and command shorthand
78
+
79
+ Use the source build in [Quick start](#quick-start) while npm publication remains unverified. Once version 2.1.2 is published and its availability on npm is confirmed, you can install it with `npm install -g @christopher_dondici/mcp-gen@2.1.2`.
80
+ Throughout this README, `mcp-gen` is shorthand for `node dist/cli/index.js` from the repository root. For example, `mcp-gen validate -i examples/petstore.yaml` means `node dist/cli/index.js validate -i examples/petstore.yaml`.
81
+
82
+ Optionally, run `npm link` from the repository root after building to make the `mcp-gen` command point to your local checkout. This changes npm's global links; it does not download a published `@christopher_dondici/mcp-gen` package. The npm package name changed because `mcp-gen` was rejected for similarity to `mcpgen`; the command remains `mcp-gen`.
83
+
84
+ To install a locally produced tarball without publishing:
85
+
86
+ ```bash
87
+ npm install ./christopher_dondici-mcp-gen-2.1.2.tgz
88
+ ./node_modules/.bin/mcp-gen --version
89
+ ./node_modules/.bin/mcp-gen validate -i node_modules/@christopher_dondici/mcp-gen/examples/petstore.yaml
90
+ ```
91
+
92
+ ## CLI
93
+
94
+ ### Commands
95
+
96
+ - `mcp-gen generate` or `mcp-gen g` creates a server from a spec.
97
+ - `mcp-gen validate` or `mcp-gen v` checks a spec with detailed warnings (name collisions, missing examples, unsupported schemas).
98
+ - `mcp-gen init` downloads a known public spec and can generate a project.
99
+ - `mcp-gen watch` watches a file or URL and regenerates on changes.
100
+
101
+ ### Generate
102
+
103
+ ```bash
104
+ mcp-gen generate -i ./api/openapi.yaml -l typescript -o ./my-server
105
+ mcp-gen generate -i ./api/openapi.yaml -l python -o ./my-server
106
+ mcp-gen generate -i ./api/openapi.yaml -l go -o ./my-server
107
+ ```
108
+
109
+ **Useful flags:**
110
+
111
+ - `--force`, `-f` overwrites existing files.
112
+ - `--incremental` keeps code between `@@mcp-gen:start` and `@@mcp-gen:end`.
113
+ - `--http` generates handlers that **call the real API** over HTTP instead of returning example stubs.
114
+ - `--env-file <path>` embeds TOKEN/BASE_URL from a .env-style file into the generated client.
115
+ - `--name <name>` sets the server name.
116
+ - `--server-version <version>` sets the server version.
117
+ - `--plugin <path>` loads a plugin module or folder (can be repeated).
118
+
119
+ ### Validate (v2.1+)
120
+
121
+ ```bash
122
+ mcp-gen validate -i ./api/openapi.yaml
123
+ ```
124
+
125
+ Outputs a rich report:
126
+
127
+ ```
128
+ Spec is valid
129
+ Tools: 12 Models: 8 Base URL: https://api.example.com
130
+
131
+ 2 warning(s):
132
+ ⚠ Tool name collision resolved: "get_users" appears 2x (unique suffixes added)
133
+ ⚠ 3 tool(s) have no example response: get_users_id, delete_user, patch_user
134
+ ```
135
+
136
+ ### Security and lint (v2.1.1)
137
+
138
+ ```bash
139
+ node dist/cli/index.js security -p ./my-server
140
+ node dist/cli/index.js security -p ./my-server --fail-on-warn
141
+ ```
142
+
143
+ Scans generated files for credential-like patterns, authorization-related identifiers, naming, descriptions, and incremental markers. `--json` prints a JSON report, but the CLI also prints a header; stdout is not a pure JSON document. Errors cause exit code 1; `--fail-on-warn` also fails on warnings. This is static analysis, not a security guarantee.
144
+
145
+ ### Init
146
+
147
+ `init` uses the built-in registry:
148
+
149
+ ```bash
150
+ mcp-gen init --from list
151
+ mcp-gen init --from stripe
152
+ mcp-gen init --from stripe --generate -o ./stripe-mcp
153
+ ```
154
+
155
+ Available registry keys:
156
+
157
+ | Key | Description |
158
+ |-----|-------------|
159
+ | `stripe` | Stripe Payment API |
160
+ | `github` | GitHub REST API |
161
+ | `slack` | Slack Web API |
162
+ | `openai` | OpenAI API |
163
+ | `petstore` | Swagger Petstore example |
164
+ | `twilio` | Twilio Communications API |
165
+ | `shopify` | Shopify Admin API |
166
+ | `kubernetes` | Kubernetes API |
167
+ | `digitalocean` | DigitalOcean API |
168
+ | `azure` | Azure Resource Manager API |
169
+
170
+ ### Watch
171
+
172
+ ```bash
173
+ mcp-gen watch -i ./api/openapi.yaml -o ./my-server
174
+ mcp-gen watch -i https://example.com/spec.json --interval 60000
175
+ ```
176
+
177
+ For URL inputs, `--interval <ms>` controls the polling interval. `--once` runs generation once and exits after the first change.
178
+
179
+ ## Plugins
180
+
181
+ Plugins can override templates and register extra Handlebars helpers.
182
+
183
+ Basic structure:
184
+
185
+ - `templates/typescript/...`, `templates/python/...`, or `templates/go/...` for `.hbs` template overrides
186
+ - `index.js` that exports `registerHandlebars(handlebars)` for custom helpers
187
+
188
+ Example:
189
+
190
+ ```bash
191
+ mcp-gen generate -i ./api/openapi.yaml --plugin ./my-plugin
192
+ mcp-gen watch -i ./api/openapi.yaml --plugin ./my-plugin
193
+ ```
194
+
195
+ Plugin templates override core templates when they use the same path under `templates/<lang>/`.
196
+
197
+ ## Generated project structure
198
+
199
+ **TypeScript:**
200
+
201
+ ```
202
+ my-server/
203
+ ├── src/
204
+ │ ├── server.ts # MCP server — tool definitions + handlers
205
+ │ ├── models.ts # TypeScript interfaces from OpenAPI schemas (enums, unions)
206
+ │ └── client.ts # HTTP client (used in --http mode)
207
+ ├── .github/
208
+ │ └── workflows/
209
+ │ └── ci.yml
210
+ ├── Dockerfile
211
+ ├── package.json
212
+ ├── tsconfig.json
213
+ └── README.md
214
+ ```
215
+
216
+ **Python:**
217
+
218
+ ```
219
+ my-server/
220
+ ├── server.py # FastMCP server — tool definitions + handlers
221
+ ├── models.py # Pydantic models from OpenAPI schemas (enums, unions)
222
+ ├── requirements.txt
223
+ ├── .github/
224
+ │ └── workflows/
225
+ │ └── ci.yml
226
+ ├── Dockerfile
227
+ └── README.md
228
+ ```
229
+
230
+ **Go (new in v2.1):**
231
+
232
+ ```
233
+ my-server/
234
+ ├── main.go # MCP server using mark3labs/mcp-go
235
+ ├── models.go # Go types from OpenAPI schemas (enums, unions)
236
+ ├── client.go # HTTP client (used in --http mode)
237
+ ├── go.mod
238
+ ├── .github/
239
+ │ └── workflows/
240
+ │ └── ci.yml
241
+ ├── Dockerfile
242
+ └── README.md
243
+ ```
244
+
245
+ ---
246
+
247
+ ## Connect to Claude Desktop
248
+
249
+ **TypeScript:**
250
+
251
+ ```json
252
+ {
253
+ "mcpServers": {
254
+ "my-server": {
255
+ "command": "node",
256
+ "args": ["/absolute/path/to/my-server/dist/server.js"]
257
+ }
258
+ }
259
+ }
260
+ ```
261
+
262
+ **Python:**
263
+
264
+ ```json
265
+ {
266
+ "mcpServers": {
267
+ "my-server": {
268
+ "command": "python",
269
+ "args": ["/absolute/path/to/my-server/server.py"]
270
+ }
271
+ }
272
+ }
273
+ ```
274
+
275
+ **Go:**
276
+
277
+ ```json
278
+ {
279
+ "mcpServers": {
280
+ "my-server": {
281
+ "command": "go",
282
+ "args": ["run", "/absolute/path/to/my-server/main.go"]
283
+ }
284
+ }
285
+ }
286
+ ```
287
+
288
+ Restart Claude Desktop. Your API tools appear automatically.
289
+
290
+ ---
291
+
292
+ ## Security & `authContext` Contract
293
+
294
+ The generated tools expect **scoped authorization metadata** (not raw credentials):
295
+
296
+ ```json
297
+ {
298
+ "tokenId": "tok_abc123",
299
+ "principal": "user:42",
300
+ "expiresAt": "2026-05-11T14:00:00Z",
301
+ "allowedTools": ["get_orders"],
302
+ "endpointAllowlist": ["GET /orders"],
303
+ "spendLimitUsd": 5,
304
+ "spendUsedUsd": 1.2,
305
+ "revoked": false,
306
+ "requestId": "req_01J..."
307
+ }
308
+ ```
309
+
310
+ The scaffold blocks arguments like `token`, `authorization`, `api_key`, `client_secret`, `password`, `secret` by default.
311
+
312
+ **Quick example (env var):**
313
+
314
+ ```bash
315
+ # Linux / macOS
316
+ export TOKEN=your_api_key_here
317
+
318
+ # Windows (PowerShell)
319
+ $env:TOKEN='your_api_key_here'
320
+ ```
321
+
322
+ For advanced integrations and management, consider Cohesivity.ai as a backend for auth, storage, and revocation policies.
323
+
324
+ ---
325
+
326
+ ## Implement handlers
327
+
328
+ Generated files return spec examples by default. Replace stubs with real logic.
329
+
330
+ **TypeScript** (`src/server.ts`):
331
+
332
+ ```typescript
333
+ case "get_users_id": {
334
+ // @@mcp-gen:start:get_users_id
335
+ const user = await db.users.findById(args.id);
336
+ return { content: [{ type: "text", text: JSON.stringify(user) }] };
337
+ // @@mcp-gen:end:get_users_id
338
+ }
339
+ ```
340
+
341
+ **Python** (`server.py`):
342
+
343
+ ```python
344
+ @mcp.tool()
345
+ async def get_users_id(id: float, auth_context: dict | None = None) -> Any:
346
+ # @@mcp-gen:start:get_users_id
347
+ user = await db.users.find_by_id(id)
348
+ return user
349
+ # @@mcp-gen:end:get_users_id
350
+ ```
351
+
352
+ **Go** (`main.go`):
353
+
354
+ ```go
355
+ s.AddTool(get_users_idTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
356
+ // @@mcp-gen:start:get_users_id
357
+ return jsonSerialize(jsonExample(`{"id": 1, "name": "Alice"}`))
358
+ // @@mcp-gen:end:get_users_id
359
+ })
360
+ ```
361
+
362
+ Code between `@@mcp-gen:start` and `@@mcp-gen:end` markers is preserved when you re-run `generate --incremental`.
363
+
364
+ ---
365
+
366
+ ## Programmatic API (Library Mode)
367
+
368
+ With the local tarball installed, import the scoped package as shown below. From the repository root after building, use `"./dist/index.js"` instead; neither approach requires npm publication.
369
+
370
+ ```typescript
371
+ import { generate, validateSpec, parseOpenAPI } from "@christopher_dondici/mcp-gen";
372
+
373
+ const result = await generate({
374
+ input: "./api/openapi.yaml",
375
+ lang: "typescript",
376
+ out: "./my-server",
377
+ force: true,
378
+ incremental: false,
379
+ http: false,
380
+ });
381
+
382
+ const validation = await validateSpec("./api/openapi.yaml");
383
+ console.log(validation.tools, validation.models, validation.warnings);
384
+ ```
385
+
386
+ ---
387
+
388
+ ## Development
389
+
390
+ ```bash
391
+ npm test
392
+ npx tsc --noEmit
393
+
394
+ # TypeScript example
395
+ node dist/cli/index.js generate --input examples/petstore.json --out /tmp/ts-test --force
396
+
397
+ # Python example
398
+ node dist/cli/index.js generate --input examples/petstore.yaml --lang python --out /tmp/py-test --force
399
+
400
+ # Go example
401
+ node dist/cli/index.js generate --input examples/petstore.json --lang go --out /tmp/go-test --force
402
+
403
+ # HTTP mode (real API calls)
404
+ node dist/cli/index.js generate --input examples/petstore.json --lang typescript --out /tmp/ts-http --force --http
405
+
406
+ # Incremental example
407
+ node dist/cli/index.js generate --input examples/petstore.json --out /tmp/ts-test --incremental
408
+ ```
409
+
410
+ ---
411
+
412
+ ## Roadmap
413
+
414
+ | Stage | Status | Scope |
415
+ |-------|--------|-------|
416
+ | Existing features | Implemented | CLI, OpenAPI v3 parser, TypeScript/Python generation, incremental generation, interactive mode, spec registry, plugins |
417
+ | v2.1.0 | Tagged | Go target, HTTP mode, enums, header/cookie params, library API, rich validate |
418
+ | v2.1.1 | Tagged | Static security/lint scanning and Go server template checks; TypeScript/Python templates unchanged from v2.1.0 |
419
+ | v2.1.2 | Prepared for release | Portable template copy, lockfile, package allowlist, prepack build, corrected release workflow, CI tarball smoke test, dependency updates |
420
+ | Distribution | Unverified | npm publication of 2.1.2 must be confirmed before registry installation; pip publication is not established. Python is a generation target, not a pip installation path for this CLI |
421
+ | Future | Planned | Streaming/resources/prompts, OpenAPI v2, more registries |
422
+
423
+ ---
424
+
425
+ ## Known limitations
426
+
427
+ - OpenAPI v2 (Swagger) is not supported — v3.x only
428
+ - `oneOf` / `anyOf` / `discriminator` schemas generate union types but no runtime validation
429
+ - Security/lint scanning uses static text patterns and can produce false positives or miss issues. A passing report does not guarantee security or verify runtime authorization, revocation, spending, or audit logging
430
+ - Generated authorization checks are scaffolding, not a complete security backend; review and test them before deployment
431
+ - Streaming/resources/prompts are not implemented
432
+
433
+ The `copy-templates` fix included in 2.1.2 uses Node.js `fs.cpSync` on Windows, Linux, and macOS; it no longer requires `cp` or `xcopy`. CI currently runs on Ubuntu only.
434
+
435
+ ---
436
+
437
+ ## License
438
+
439
+ MIT © 2026 - Christopher D.