Schema Editor
Adding MCP to a Tool Is Not an AI Feature. It Is an API Design Problem.
TLDR
Integrating Model Context Protocol (MCP) servers into web applications is often marketed as adding "AI features." In reality, protocol setup takes five lines of boilerplate code. The actual engineering work lies in API design: crafting a clean, stable, machine-readable serialization format that represents application domain state for LLM reasoning. Treating MCP integration as API design yields production-grade stability.| MCP Aspect | Protocol Wiring (SDK / Transport) | Payload Contract Design |
|---|---|---|
| Engineering Effort | 5 lines of boilerplate setup | Full domain schema design |
| Primary Focus | Transporting JSON RPC messages | Structuring domain state for LLM reasoning |
| Failure Mode | Network connection errors | Hallucinations due to noisy data formats |
Problem statement: the convenience trap of native serialization
The default pattern for MCP integration in many tools is: receive a tool request, dump the application's internal or native serialization format (SVG, HTML, raw database records), and let the LLM parse it.
While this pattern is quick to implement, it mistakes transport execution for API design.
Just as REST APIs avoid returning raw HTML markup for programmatic clients to parse, MCP tool integrations should avoid returning raw visual markup for AI consumers to parse.
Technical failure mode: the high cost of unstructured MCP dumps
- Token Waste: Raw SVG or HTML dumps consume thousands of unnecessary tokens detailing CSS styles, DOM IDs, and path curves.
- Brittle Integrations: Refactoring frontend rendering components alters the output markup, breaking AI tool calls that previously worked.
- Prompt Workarounds: Developers waste time crafting complex system prompts to force LLMs to ignore rendering noise.
The fix & architecture: intentional API payload design
Design the AI-facing domain representation before writing MCP server code:
- Entity Identification: What domain entities does the AI need to inspect? (Components, conductors, nets.)
- Relevance Filtering: What attributes matter for reasoning? (Component types, values, connected ports. Omit CSS classes, screen pixels, and UI chrome handles.)
- Action Contracts: What state mutations can the AI request? (Add component, wire pins, rename net.)
// Clean API Design: Structured Domain State Payload
const payload = {
schema: 'ginexys-diagram-v2',
components: editor.getComponents().map(c => ({
id: c.id,
type: c.symbolType,
label: c.label,
properties: c.properties
})),
connections: editor.getWires().map(w => ({
from: { id: w.startComponent, port: w.startPort },
to: { id: w.endComponent, port: w.endPort }
}))
};
Rule of thumb: Approach MCP integrations with the same rigor as public REST or GraphQL API design. Design structured domain schemas optimized for AI consumers rather than exposing raw internal rendering state.
Read this post in the full Engineering Journal →