跪拜 Guibai
← All articles
MCP · TypeScript · AI

MCP in 15 Minutes: Wrap Your Backend API into a Reusable AI Tool

By 猫头_ ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

One MCP server per service replaces a growing matrix of per-client adapters, so teams and solo developers stop re-implementing the same API bindings. The captcha auto-login pattern also shows how to keep credentials out of model context, closing a security leak that most homegrown agents leave wide open.

Summary

The Model Context Protocol (MCP) cuts the cost of connecting backend services to AI clients from M×N adapters down to M+N. Instead of reimplementing function calling for every client, you write one MCP server that exposes your existing API as Tools, and Cursor, Claude Desktop, and other clients all plug in directly. The article demonstrates this with a bookmark service, reducing a full server to three TypeScript files: entry, request wrapper, and tool definitions.

The four design rules matter most: give parameter schemas concrete examples, hide API-specific formatting in code, slim down return data to save tokens, and make error messages tell the model what to do next. The stdio transport is the central detail for local tools, replacing network ports with stdin/stdout pipes, but it also introduces one sharp edge: a stray console.log breaks the JSON-RPC channel.

The advanced section solves the token-expiry problem with multimodal AI. By returning a captcha image as an MCP image payload and keeping credentials in environment variables, the model computes the arithmetic answer and logs in automatically. The article closes with a five-item deployment checklist covering protocol-safety, Windows compatibility, tool count limits, and deprecated SDK methods.

Takeaways
— Adopting MCP cuts integration work from M×N adapters (M clients, N services) to M+N.
— A minimal MCP server consists of three files: index.ts (entry), client.ts (request wrapper), and tools.ts (tool definitions).
— The stdio transport communicates over standard input/output pipes, requiring no open ports, domain names, or server deployment.
— Tool descriptions must include concrete examples, hide API formatting quirks, and slim returned data to conserve tokens.
— Error responses should set isError:true and instruct the model on the next recovery step, like fetching a captcha and logging in.
— In stdio mode, never use console.log; use console.error to avoid corrupting the JSON-RPC protocol channel.
— On Windows, set the client command to node rather than npx to avoid the spawn npx ENOENT error.
— Keep the number of tools under 10 with consistent naming, and use the new server.registerTool() API instead of the deprecated server.tool().
Conclusions

The M×N-to-M+N reduction is the core value proposition: one MCP server per service replaces a matrix of per-client adapters, and the article shows that even a personal bookmark tool benefits from this standardization.

The multimodal captcha login trick is only safe because the credentials never enter the tool parameters; the article correctly treats tool parameters as a public channel, keeping password handling entirely on the server side.

The rule to never let an agent drive a browser but instead wrap the API is a recognition that HTML/DOM is an unstable contract, while HTTP endpoints are deterministic and stable.

A single console.log breaking the stdio channel is a reminder that protocol consumers have zero tolerance for stray output; the debug discipline is a structural necessity, not a style preference.

Concepts & terms
Model Context Protocol (MCP)
A standard protocol that lets AI clients call external tools and data sources through a unified interface. Instead of writing per-client adapters, you implement one MCP server and any compatible client can use it.
Tools (MCP)
One of three capability types in MCP. Tools are functions the model can invoke at runtime, typically corresponding to read or write operations on an API. The model decides when to call them; write operations usually require user approval.
stdio transport
A communication channel for MCP servers that runs as a local child process. It uses standard input/output pipes instead of network ports, letting the client spawn the server and exchange JSON-RPC messages over stdin/stdout.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗