MCP Server That Calls Real HTTP APIs: Error Handling and What Actually Matters
MCP servers that only compute a + b are demos, not tools. This walkthrough shows the practical wiring for letting an AI assistant hit real endpoints, and it makes the boundary between MCP transport errors and HTTP business errors explicit, which is where a lot of confusion happens when debugging.
The second MCP practice session moves past the basic math tool and into a real HTTP integration. A developer builds a userServer with the MCP TypeScript SDK, registers a getUserInfo tool with Zod input validation, and connects it to Copilot through VS Code's stdio configuration. Copilot then asks the tool to query JSONPlaceholder's public user endpoint, and the full loop works end to end.
The interesting part is error handling. HTTP 404 gets mapped to an isError result with a human-readable message. Connection failures are caught via try/catch, and AbortSignal.timeout(5000) adds a 5-second timeout. The tests cover three cases: successful query, missing user, and network failure. A regression check confirms the normal path still works after the error handling changes.
The write-up also separates two layers clearly: an HTTP failure is not an MCP communication failure. The MCP channel stays healthy while the underlying API call fails. The author notes that MCP doesn't understand natural language, the AI model does, and that MCP and HTTP APIs complement each other rather than compete. Existing backend interfaces can be wrapped as MCP tools without rewriting business logic.
The author's step of curl-testing the HTTP endpoint before wiring it into MCP is the quiet hero of the article: it separates HTTP-layer from MCP-layer debugging, so a failure later narrows down quickly.
Treating isError as a first-class return value is what keeps an AI assistant honest. Without it, Copilot might just invent data instead of reporting a 404.
The distinction between validation and coercion in Zod matters more in MCP than in typical UI code, because the AI model may produce string values from natural language, and silent coercion can mask type bugs.
Parameter definitions double as discovery metadata for clients, which means a well-described schema isn't just for validation; it guides the model's tool selection.
MCP tools need the same engineering discipline as any backend endpoint, and the author's list of missing pieces (auth, permissions, field filtering) is a realistic checklist before anything goes to production.