Introduction: The Challenge of API Integration at Scale
At Coherence, we’re building the infrastructure layer that enables products to embed intelligent, agentic chat into their apps. Our goal: get a fully functional AI chat interface running in your application with access to your backend APIs in under an hour.
That’s hard. Every customer has unique APIs, models, auth schemes, and logic. Our agents need to understand and safely interact with those APIs.
That’s where MCP comes in.
What Is MCP?
Model Context Protocol (MCP) is Anthropic’s open standard for connecting AI agents to external systems. It's a consistent abstraction for tool use, letting agents call real APIs safely and with structure.
The problem? Manually writing MCP servers for each customer doesn’t scale. So we automated it.
This post breaks down how we generate production-ready MCP servers using Claude Code and Daytona sandboxes.
Why MCP?
Standardized: Same format for any tool
Secure: Runs on isolated servers
Flexible: Handles stateless and stateful operations
Ecosystem: Part of a growing agentic tooling stack
Our Architecture at 30,000 Feet
The generated MCP server is the bridge that maps the agent’s high-level intent to your actual backend. It handles auth, retries, schema translation, and tool registration.
Daytona: Secure, Ephemeral Environments
We use Daytona to create secure, disposable sandboxes for each generation task. These environments provide:
Security Isolation
Reproducibility
Resource Limits and Cleanup
Full Automation via SDK
Claude Code CLI: The Brain of Our Operation
The second key piece is Anthropic's Claude Code CLI. While many know Claude as a chat interface, Claude Code is a powerful command-line tool designed specifically for software development tasks.
Why Claude Code CLI?
Context Window Management: Handles large codebases intelligently
Tool Use: Native support for file operations, code analysis, and more
Deterministic Outputs: Consistent code generation patterns
Error Recovery: Sophisticated retry and correction mechanisms
Our Integration Approach
We use Claude Code in a headless mode within our Daytona environments:
The Technical Deep Dive: MCP Generation Workflow
Now let's get into the meat of how this works. Our MCP generation pipeline consists of several stages:
1. API Specification Analysis
First, we analyze the customer's API documentation. The job here is to extract info about the endpoints available, the parameters supported, and the data returned. This can be a structured spec, such as an OpenAPI document, or can be other inputs, such as plain-text descriptions or code snippets from the server. The Claude code agent with the LLM is able to work with a wide range of data, but the old truth about "garbage-in, garbage-out" always applies!
2. Prompt Engineering for MCP Generation
This is where the magic happens. We've developed a sophisticated prompting framework that guides Claude Code to generate optimal MCP servers. Without revealing our secret sauce, here's the high-level approach:
3. Iterative Generation and Validation
Claude Code doesn't just generate code - it iterates and improves:
4. Testing and Verification
Every generated MCP server goes through rigorous testing:
Real-World Example: E-commerce API Integration
Let's walk through a concrete example. Imagine we're integrating with an e-commerce platform's API:
Input: OpenAPI Specification
Generated MCP Server (Simplified)
In the example below, the Coherence SDK handles all the hard parts of passing authentication information in real time to the Coherence backend, the LangGraph agent, the MCP servers, and then your backend. You don't need to manage these security-critical transfers, and your users can chat with the same permissions and login they already have. It "just works!"
Performance and Scale Considerations
Generating MCP servers at scale requires careful optimization:
1. Caching and Reuse
2. Parallel Generation
3. Resource Management
Daytona workspaces are auto-scaled
Generation timeout limits prevent runaway processes
Automatic cleanup of failed generations and resource archiving for cost management
Lessons Learned and Best Practices
After generating our first batches of MCP servers, here's what we've learned:
1. Prompt Engineering is Everything
The quality of generated code is directly proportional to prompt quality. We maintain a library of prompt components that we compose for different scenarios.
2. Validation is Non-Negotiable
Every generated server must pass:
Static type checking
Security scanning
Functional tests
Performance benchmarks
3. Human-in-the-Loop for Edge Cases
While automation handles 90% of cases, complex APIs benefit from human review. We've built tooling to make this review process efficient. We've also built UI to allow Coherence users to view and edit their MCP code directly and deploy new versions whenever they want to.
4. Version Control and Rollback
Generated servers are version-controlled with clear rollback procedures. This is critical when APIs change. In the Coherence UI, you can see a lot of previous versions, their timestamps, status, and other info. You can generate new versions and roll back at any time.
The Future: Where We're Heading
1. Self-Improving Generation
We're building systems where generated MCP servers learn from usage patterns and self-optimize.
2. Multi-Modal MCP
Beyond REST APIs - integrating with databases, message queues, and even UI automation.
3. Open Source Contributions
We're working with Anthropic to contribute improvements back to the MCP ecosystem.
Conclusion: The Power of Composable AI Infrastructure
The combination of Daytona's secure environments and Claude Code's generation capabilities has allowed us to solve what seemed like an intractable problem: making any API instantly accessible to AI agents.
This approach - using AI to build AI infrastructure - represents a new paradigm in software development. We're not just writing code; we're building systems that write code, with all the quality and security guarantees of human-written software.
If you're building in the AI space, I encourage you to think about similar multiplicative approaches. What manual processes in your workflow could be automated with the right combination of tools?
Try It Yourself
Interested in adding intelligent chat to your application? Check out Coherence - we handle all the complexity described above, so you can focus on building great products.
Want to experiment with MCP? Start with Anthropic's MCP documentation and try building a simple server manually first.
Building agentic computing or development environments? Daytona is revolutionizing how we think about containerized infrastructure.
Have questions or want to discuss MCP generation?
Find me on Twitter or HN. If you're solving similar problems, I'd love to hear your approach!
