Model Context Protocol (MCP) in Full-Stack Architecture
Hardcoding proprietary function-calling formats inside prompt handlers couples AI applications irreversibly to specific model vendors and creates unsustainable integration maintenance. This article implements Anthropic's open Model Context Protocol (MCP) TypeScript SDK v2, exposing internal enterprise tools via custom MCP servers with OAuth 2.1 security and dynamic capability discovery.
Full-Stack AI Architecture: From Streaming Foundations to Resilient Agentic Systems in Node.js & React
Model Context Protocol (MCP) in Full-Stack Architecture
Every AI SDK has its own tool-calling format. Anthropic wraps tools in tool_use blocks. OpenAI uses function_call JSON. The Vercel AI SDK abstracts this — until you need features (like streaming tool results) that the abstraction does not expose, and you are back to vendor-specific code. Switching model providers requires rewriting every tool definition and handler.
The Model Context Protocol (MCP) is Anthropic's open JSON-RPC standard that decouples tool definitions from both the model vendor and the application. Any MCP-compatible client (Claude Desktop, GitHub Copilot, custom AI apps) can discover and use your tools without modification. This article implements a production MCP server using TypeScript SDK v2, exposing four Workspace enterprise tools over Streamable HTTP with OAuth 2.1 security.
Who this is for: Engineers who have hardcoded function-calling schemas for one model provider and want to expose those same capabilities to any MCP-compatible AI client — or who want to build custom enterprise tool servers that work across model vendors.
1. MCP Architecture
1.1 The Protocol
1.2 SDK v2 Key Classes
| Class | Use Case |
|---|---|
McpServer |
Declarative tool registration (recommended for new servers) |
Server |
Low-level JSON-RPC control (for proxies/aggregators) |
StdioServerTransport |
Local tools (CLI, desktop apps) |
StreamableHTTPServerTransport |
Network-accessible tools (production) |
2. Implementing the Workspace MCP Server
3. Streamable HTTP Transport with OAuth 2.1
4. Tool Error Isolation
MCP tool errors must be returned as structured content, not thrown as exceptions. An unhandled exception in a tool handler terminates the entire JSON-RPC session.
Summary
| Concept | Rule |
|---|---|
| MCP vs proprietary tools | MCP works across any client; proprietary schemas lock to one provider's SDK |
| McpServer | Use declarative mcpServer.tool() for all custom tools; avoid raw Server unless building a proxy |
| Streamable HTTP | Required for production network-accessible MCP; StdioTransport is local-only |
| OAuth 2.1 | Validate bearer tokens in Fastify middleware before any MCP request reaches handlers |
| Error isolation | Return { isError: true } — never throw exceptions inside MCP tool handlers |
What's Next
Part 17 builds the React side of long-running agent workflows: the Human-in-the-Loop approval UI that pauses destructive agent actions pending user authorisation, backed by step-level durable execution that survives server restarts.
This article was developed with AI-assisted deep search, specification cross-referencing, and technical research synthesis.