{"_id":"@aigentools/mcpgen-core","name":"@aigentools/mcpgen-core","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@aigentools/mcpgen-core","version":"0.1.1","private":false,"type":"module","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"bun build src/index.ts --outdir dist --target node --format esm --sourcemap --external @scalar/openapi-parser --external yaml && tsc -p tsconfig.json --emitDeclarationOnly","dev":"bun run src/index.ts","typecheck":"tsc -p tsconfig.json --noEmit","lint":"biome lint .","format":"biome format --write .","test":"bun test"},"dependencies":{"@scalar/openapi-parser":"^0.10.0","ts-morph":"^26.0.0","yaml":"^2.5.0","zod":"^4.0.17"},"_id":"@aigentools/mcpgen-core@0.1.1","gitHead":"9315a4cd83c2215c83c4adb4597bb7ebf4a859f7","description":"Advanced generator library for creating MCP servers from OpenAPI specifications using AST manipulation.","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-4rpwu2kvNZerXqbBjGA7c7XOU4ewUOol9jVmMWPLUC9YTsMkOWUtxQ/Zy0Gk6Mkn+Lgc/NufO2ZcwzE+MDLZFw==","shasum":"a2808ecef50968b91499920091b868027f23b865","tarball":"https://registry.npmjs.org/@aigentools/mcpgen-core/-/mcpgen-core-0.1.1.tgz","fileCount":17,"unpackedSize":30359449,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDwEJi3mN2YW7O3JYtwfA5LCZx5pm7cOQnYGOX1UG4gxAiAEXXzdDKnZ1WWqNFDejkeZFazxaKNvyDMY2xQY4+UfaQ=="}]},"_npmUser":{"name":"beshkenadze","email":"beshkenadze@gmail.com"},"directories":{},"maintainers":[{"name":"beshkenadze","email":"beshkenadze@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mcpgen-core_0.1.1_1755091424253_0.8076135377629206"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-13T13:23:44.151Z","0.1.1":"2025-08-13T13:23:44.539Z","modified":"2025-08-13T13:23:44.886Z"},"maintainers":[{"name":"beshkenadze","email":"beshkenadze@gmail.com"}],"description":"Advanced generator library for creating MCP servers from OpenAPI specifications using AST manipulation.","readme":"# @aigentools/mcpgen-core\n\nAdvanced generator library for creating MCP servers from OpenAPI specifications using AST manipulation.\n\n## Features\n- **AST-based Code Generation**: Uses `ts-morph` for precise TypeScript code generation\n- **OpenAPI Parsing**: Built on `@scalar/openapi-parser` with validation and dereferencing\n- **Type-Safe**: Full TypeScript support with Zod schema validation\n- **Multiple Runtimes**: Support for Bun/Node (stdio) and Hono (HTTP/SSE/WebSocket) runtimes\n- **CamelCase Naming**: Converts OpenAPI operations to camelCase method names\n- **Biome Formatting**: Automatic code formatting with Biome v2 integration\n- **Comprehensive Mapping**: Maps OpenAPI paths, parameters, request bodies, and responses to MCP tools\n\n## Core API\n\n### OpenAPIMcpGenerator Class\nThe main generator class that converts OpenAPI specifications to MCP servers.\n\n```ts\nimport { OpenAPIMcpGenerator, type GeneratorOptions } from '@aigentools/mcpgen-core';\n\n// Standard runtime (Bun/Node with stdio transport)\nconst generator = new OpenAPIMcpGenerator();\nawait generator.generateFromOpenAPI(\n  './petstore.yaml',    // OpenAPI file path (JSON or YAML)\n  './server.ts',        // Output file path\n  'petstore-mcp',       // Server name\n  'bun'                 // Runtime: 'bun', 'node', or 'hono'\n);\n\n// Hono runtime (Web server with HTTP/SSE/WebSocket transports)\nconst honoGenerator = new OpenAPIMcpGenerator({\n  debug: true,           // Enable debug logging\n  skipFormatting: false  // Enable Biome formatting\n});\nawait honoGenerator.generateFromOpenAPI(\n  './petstore.yaml',\n  './output/src/server.ts',\n  'petstore-web-mcp',\n  'hono'                 // Generates Hono web server with multiple transports\n);\n\n// Custom options\nconst customGenerator = new OpenAPIMcpGenerator({\n  debug: true,           // Enable debug logging\n  indentSize: 2,         // Use 2-space indentation\n  quoteStyle: 'double',  // Use double quotes\n  trailingCommas: false, // Disable trailing commas\n  skipFormatting: true   // Skip Biome formatting\n});\n```\n\n### Type Exports\nAll TypeScript interfaces are available for import:\n\n```ts\nimport type {\n  // Core OpenAPI types\n  OpenAPISchema,\n  OpenAPIParameter,\n  OpenAPIOperation,\n  OpenAPIDocument,\n  \n  // Generator configuration\n  GeneratorOptions,\n  Runtime,               // 'bun' | 'node' | 'hono'\n  \n  // Additional types\n  OpenAPIRequestBody,\n  OpenAPIResponse,\n  OpenAPIPath,\n  OpenAPIInfo,\n  OpenAPIComponents\n} from '@aigentools/mcpgen-core';\n```\n\n### Generator Options\nConfigure the generator behavior with `GeneratorOptions`:\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `debug` | `boolean` | `false` | Enable debug logging |\n| `skipFormatting` | `boolean` | `false` | Skip Biome formatting step |\n| `indentSize` | `2 \\| 4 \\| 8` | `4` | Number of spaces for indentation |\n| `quoteStyle` | `'single' \\| 'double'` | `'single'` | Quote style for strings |\n| `trailingCommas` | `boolean` | `true` | Use trailing commas |\n\n## Generated Server Features\n\nThe generated MCP server includes:\n\n### Common Features (All Runtimes)\n- **Individual MCP Tools**: Each OpenAPI operation becomes an MCP tool\n- **Zod Validation**: Input parameters validated with Zod schemas\n- **Type Safety**: Full TypeScript support with proper interfaces\n- **Path Parameters**: Automatic URL building with path parameter substitution\n- **Query Parameters**: Support for query string parameters\n- **Request Bodies**: JSON request body handling\n- **Error Handling**: Comprehensive HTTP error handling\n- **Environment Variables**: Configurable base URL via `API_BASE_URL`\n\n### Standard Runtime (Bun/Node) Features\n- **Stdio Transport**: Direct stdin/stdout communication\n- **Single File Output**: Complete server in one `index.ts` file\n- **Claude Desktop Ready**: Works immediately with Claude Desktop configuration\n\n### Hono Runtime Features\n- **HTTP Transport**: RESTful MCP endpoint at `/mcp`\n- **SSE Transport**: Server-Sent Events at `/mcp/sse` for streaming\n- **WebSocket Stdio**: Experimental stdio transport via WebSocket at `/mcp/stdio`\n- **Web Server**: Full Hono application with middleware\n- **Health Checks**: Built-in `/health` endpoint for monitoring\n- **Docker Support**: Includes Dockerfile for containerized deployment\n- **Development Mode**: Hot reload with `bun run dev`\n\n## Example Output\n\n### Standard Runtime (Bun/Node)\nGiven a simple OpenAPI spec, the generator creates:\n\n```ts\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\n\nconst server = new McpServer({\n  name: 'petstore-mcp',\n  version: '1.0.0'\n});\n\nserver.registerTool(\n  'getPetById',\n  {\n    title: 'Find pet by ID',\n    description: 'Returns a single pet',\n    inputSchema: {\n      petId: z.string().describe('Path parameter: petId')\n    }\n  },\n  async (params) => {\n    // HTTP request implementation with error handling\n  }\n);\n\n// Stdio transport setup\nconst transport = new StdioServerTransport();\nserver.connect(transport);\n```\n\n### Hono Runtime\nFor Hono runtime, the generator creates a complete web server:\n\n```ts\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StreamableHTTPTransport } from '@hono/mcp';\nimport { Hono } from 'hono';\nimport { stream } from 'hono/streaming';\n\nconst mcpServer = new McpServer({\n  name: 'petstore-mcp',\n  version: '1.0.0'\n});\n\n// Tool registration (same as standard runtime)\nmcpServer.registerTool('getPetById', { /* ... */ }, async (params) => {\n  // HTTP request implementation\n});\n\nconst app = new Hono();\n\n// HTTP transport endpoint\napp.post('/mcp', async (c) => {\n  const transport = new StreamableHTTPTransport();\n  await mcpServer.connect(transport);\n  return transport.handleRequest(c);\n});\n\n// SSE transport endpoint  \napp.get('/mcp/sse', async (c) => {\n  const transport = new StreamableHTTPTransport();\n  await mcpServer.connect(transport);\n  return stream(c, async (stream) => {\n    // Server-Sent Events implementation\n  });\n});\n\nexport default app;\n```\n\n## Development\n\n- **Build**: `bun run build` - Creates dist/ with JS and TypeScript declarations\n- **Typecheck**: `bun run typecheck` - Validates TypeScript without emitting\n- **Test**: `bun run test` - Runs test suite\n- **Lint**: `bun run lint` - Code quality checks with Biome\n\n## Package Structure\n\n```\nsrc/\n├── index.ts      # Main exports (class + types)\n├── generator.ts  # OpenAPIMcpGenerator implementation\n└── types.ts      # TypeScript interfaces and types\n```\n\n## Technical Details\n\n- **AST Generation**: Uses `ts-morph` for precise TypeScript code generation\n- **OpenAPI Parsing**: Built on `@scalar/openapi-parser` with validation and dereferencing\n- **Type Safety**: Comprehensive TypeScript interfaces separated into `types.ts`\n- **Configurable**: Flexible generator options for different coding styles\n- **Formatting**: Optional Biome integration for consistent code style\n- **Modular Design**: Clean separation between generator logic and type definitions\n","readmeFilename":"README.md","_rev":"1-4157076aebc11db741264b7d069c9c1c"}