InspirationAutoMCP: Automating MCP Server Generation with AI
The Inspiration π‘ Creating MCP servers manually is tediousβwriting boilerplate code, defining tool schemas, handling authentication. We asked: what if we could automate this?
AutoMCP bridges API documentation and AI agent integration. Developers upload OpenAPI/Swagger docs and get a production-ready MCP server in minutes, not hours.
What We Learned π Prompt Engineering: Structured, context-rich prompts with clear examples produce better code. We learned to break complex tasks into focused prompts (types β tools β server).
Schema Resolution: OpenAPI's $ref references create complex dependency graphs. We implemented recursive resolution with cycle detection to handle nested schemas.
Error Resilience: External APIs fail. We added retry logic, model validation, and auto-detection to gracefully handle Gemini API issues.
Type Safety: Generating TypeScript that compiles requires careful schema-to-type conversion and handling optional vs required parameters.
How We Built It ποΈ Architecture Upload β Parser β Transformer β Gemini AI β Generator β ZIP Package
- Parsing Layer (src/parsers/)
OpenAPI 3.x parser (JSON/YAML) Extracts endpoints, parameters, schemas, auth schemes Recursive $ref resolution with cycle detection
- Transformation Layer (src/transformers/)
Normalizes data for AI consumption Reduces token usage while preserving context Creates endpoint summaries
- Gemini Integration (src/gemini/)
Multi-stage code generation: Types β Tool Definitions β Implementations β Server Retry logic with exponential backoff Model validation and auto-detection Extracts code from markdown responses
- Package Generator (src/generators/)
Assembles complete npm package Generates package.json, tsconfig.json, config files Creates ZIP archive for distribution
- REST API (src/api/)
Express.js endpoints: upload, generate, download, status Local file storage with UUID sessions File upload handling with multer Tech Stack TypeScript + Express.js Google Gemini AI for code generation js-yaml for OpenAPI parsing @modelcontextprotocol/sdk for MCP protocol Challenges We Faced π§
Model Availability: gemini-3.0-pro didn't exist, gemini-1.5-pro wasn't available. Solution: Implemented model validation with fallback to gemini-pro.
URL Construction: Generated code used new URL() which failed with relative paths. Solution: Switched to string concatenation with trailing slash handling.
Schema References: Complex $ref graphs with potential cycles. Solution: Recursive resolution with visited set for cycle detection.
Token Limits: Large APIs exceeded limits. Solution: Multi-stage generation (types separately, tools individually).
Type Safety: Ensuring generated TypeScript compiles. Solution: Explicit schema-to-type conversion with proper annotations.
Impact π Time Savings: Hours β minutes for MCP server creation Zero Boilerplate: Eliminates repetitive code writing Protocol Compliance: Ensures MCP standards automatically Production-Ready: Generated code includes error handling, types, docs Future Enhancements π Postman collection support Web UI dashboard Batch generation Cloud storage integration CI/CD templates Technical Highlights π¬ Performance: Parallel tool generation, schema caching, lazy loading
Security: Path validation, file size limits, UUID sessions, input sanitization
Code Quality: TypeScript strict mode, comprehensive error handling, detailed logging
Log in or sign up for Devpost to join the conversation.