diff --git a/package.json b/package.json index ab67acc..68edd75 100644 --- a/package.json +++ b/package.json @@ -1,67 +1,67 @@ { - "name": "openapi-mcp-generator", - "version": "3.1.3", - "description": "Generates MCP server code from OpenAPI specifications", - "license": "MIT", - "author": "Harsha", - "type": "module", - "engines": { - "node": ">=20.0.0" - }, - "bin": { - "openapi-mcp-generator": "./bin/openapi-mcp-generator.js" - }, - "main": "dist/index.js", - "files": [ - "dist", - "bin", - "README.md", - "LICENSE" - ], - "types": "./dist/index.d.ts", - "scripts": { - "start": "node dist/index.js", - "clean": "rimraf dist", - "typecheck": "tsc --noEmit", - "build": "tsc && chmod 755 dist/index.js && chmod 755 bin/openapi-mcp-generator.js", - "version:patch": "npm version patch", - "version:minor": "npm version minor", - "version:major": "npm version major" - }, - "keywords": [ - "openapi", - "mcp", - "model-context-protocol", - "generator", - "llm", - "ai", - "api" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/harsha-iiiv/openapi-mcp-generator.git" - }, - "bugs": { - "url": "https://github.com/harsha-iiiv/openapi-mcp-generator/issues" - }, - "homepage": "https://github.com/harsha-iiiv/openapi-mcp-generator#readme", - "dependencies": { - "@apidevtools/swagger-parser": "^10.1.1", - "commander": "^13.1.0", - "openapi-types": "^12.1.3" - }, - "devDependencies": { - "@types/node": "^22.15.2", - "@typescript-eslint/eslint-plugin": "^8.31.0", - "@typescript-eslint/parser": "^8.31.0", - "eslint": "^9.25.1", - "prettier": "^3.5.3", - "rimraf": "^6.0.1", - "typescript": "^5.8.3" - }, - "peerDependencies": { - "@modelcontextprotocol/sdk": "^1.10.0", - "json-schema-to-zod": "^2.6.1", - "zod": "^3.24.3" - } + "name": "openapi-mcp-generator", + "version": "3.1.4", + "description": "Generates MCP server code from OpenAPI specifications", + "license": "MIT", + "author": "Harsha", + "type": "module", + "engines": { + "node": ">=20.0.0" + }, + "bin": { + "openapi-mcp-generator": "./bin/openapi-mcp-generator.js" + }, + "main": "dist/index.js", + "files": [ + "dist", + "bin", + "README.md", + "LICENSE" + ], + "types": "./dist/index.d.ts", + "scripts": { + "start": "node dist/index.js", + "clean": "rimraf dist", + "typecheck": "tsc --noEmit", + "build": "tsc && chmod 755 dist/index.js && chmod 755 bin/openapi-mcp-generator.js", + "version:patch": "npm version patch", + "version:minor": "npm version minor", + "version:major": "npm version major" + }, + "keywords": [ + "openapi", + "mcp", + "model-context-protocol", + "generator", + "llm", + "ai", + "api" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/harsha-iiiv/openapi-mcp-generator.git" + }, + "bugs": { + "url": "https://github.com/harsha-iiiv/openapi-mcp-generator/issues" + }, + "homepage": "https://github.com/harsha-iiiv/openapi-mcp-generator#readme", + "dependencies": { + "@apidevtools/swagger-parser": "^10.1.1", + "commander": "^13.1.0", + "openapi-types": "^12.1.3" + }, + "devDependencies": { + "@types/node": "^22.15.2", + "@typescript-eslint/eslint-plugin": "^8.31.0", + "@typescript-eslint/parser": "^8.31.0", + "eslint": "^9.25.1", + "prettier": "^3.5.3", + "rimraf": "^6.0.1", + "typescript": "^5.8.3" + }, + "peerDependencies": { + "@modelcontextprotocol/sdk": "^1.10.0", + "json-schema-to-zod": "^2.6.1", + "zod": "^3.24.3" + } } diff --git a/src/index.ts b/src/index.ts index f222bf5..a528160 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ import { // Import types import { CliOptions, TransportType } from './types/index.js'; +import pkg from '../package.json' with { type: 'json' }; // Export programmatic API export { getToolsFromOpenApi, McpToolDefinition, GetToolsOptions } from './api.js'; @@ -72,13 +73,12 @@ program (val) => parseInt(val, 10) ) .option('--force', 'Overwrite existing files without prompting') - .version('3.1.2') // Match package.json version - .action(options => { - runGenerator(options) - .catch((error) => { - console.error('Unhandled error:', error); - process.exit(1); - }); + .version(pkg.version) // Match package.json version + .action((options) => { + runGenerator(options).catch((error) => { + console.error('Unhandled error:', error); + process.exit(1); + }); }); // Export the program object for use in bin stub @@ -283,4 +283,4 @@ async function runGenerator(options: CliOptions & { force?: boolean }) { } // Export the run function for programmatic usage -export { runGenerator as generateMcpServer }; \ No newline at end of file +export { runGenerator as generateMcpServer }; diff --git a/src/parser/extract-tools.ts b/src/parser/extract-tools.ts index 3b3e597..f50232e 100644 --- a/src/parser/extract-tools.ts +++ b/src/parser/extract-tools.ts @@ -31,10 +31,7 @@ export function extractToolsFromApi(api: OpenAPIV3.Document): McpToolDefinition[ if (!baseName) continue; // Sanitize the name to be MCP-compatible (only a-z, 0-9, _, -) - baseName = baseName - .replace(/\./g, '_') - .replace(/[^a-z0-9_-]/gi, '_') - .toLowerCase(); + baseName = baseName.replace(/\./g, '_').replace(/[^a-z0-9_-]/gi, '_'); let finalToolName = baseName; let counter = 1; @@ -174,7 +171,9 @@ export function mapOpenApiSchemaToJsonSchema( // Detect cycles if (seen.has(schema)) { - console.warn(`Cycle detected in schema${schema.title ? ` "${schema.title}"` : ''}, returning generic object to break recursion.`); + console.warn( + `Cycle detected in schema${schema.title ? ` "${schema.title}"` : ''}, returning generic object to break recursion.` + ); return { type: 'object' }; } seen.add(schema); @@ -212,7 +211,10 @@ export function mapOpenApiSchemaToJsonSchema( for (const [key, propSchema] of Object.entries(jsonSchema.properties)) { if (typeof propSchema === 'object' && propSchema !== null) { - mappedProps[key] = mapOpenApiSchemaToJsonSchema(propSchema as OpenAPIV3.SchemaObject, seen); + mappedProps[key] = mapOpenApiSchemaToJsonSchema( + propSchema as OpenAPIV3.SchemaObject, + seen + ); } else if (typeof propSchema === 'boolean') { mappedProps[key] = propSchema; }