Technical Handbook•Peer-Reviewed Production Architecture

Model Context Protocol (MCP) & AI Agent Tool Calling: Building Production-Grade MCP Servers

The definitive specification guide to Anthropic's open standard for connecting AI agents to enterprise APIs, dynamic databases, and real-time execution environments.

Devon Vance

Devon Vance(Open Source Collective)

Staff Protocol Engineer

Oct 22, 202512 min read
Model Context Protocol (MCP) & AI Agent Tool Calling: Building Production-Grade MCP Servers
Model Context Protocol (MCP) & AI Agent Tool Calling: Building Production-Grade MCP Servers
Executive Architecture Summary

The Model Context Protocol (MCP) has unified the fragmented landscape of agent tooling into an open standard. Learn how to architect, secure, and scale production-grade MCP servers using TypeScript and Python, connecting Claude, Gemini, and IDE swarms to enterprise data with OAuth 2.1 authorization.

1. Why MCP Replaces Ad-Hoc Tool JSON Schemas

Before the introduction of the Model Context Protocol (MCP), every AI development framework—OpenAI Assistants, LangChain, LlamaIndex, AutoGen—invented its own proprietary method for declaring tools and injecting context. Developers were forced to rewrite adapters for every platform, resulting in brittle glue code.

MCP provides an open, bidirectional standard built on JSON-RPC 2.0. By decoupling the LLM application ('Host') from the tool provider ('Server'), a single MCP server can seamlessly serve Claude Desktop, Cursor, Gemini API agents, and autonomous backend swarms without a single line of modification.

Figure 1: MCP architectural topology showing universal communication between AI hosts, client transports (stdio/SSE), and modular tool servers.
Figure 1: MCP architectural topology showing universal communication between AI hosts, client transports (stdio/SSE), and modular tool servers.

Standardized Protocol Capabilities

MCP defines three distinct capabilities: Resources (read-only file and document URI pointers), Tools (executable functions with side effects and parameters), and Prompts (pre-engineered prompt templates with parameterized arguments).

2. The Protocol Anatomy: Resources, Prompts, Tools & Transports

An MCP session begins with an initialization handshake where Client and Server negotiate protocol versions (such as `2024-11-05`) and capabilities. Communication takes place over two primary transports: standard I/O (`stdio`) for local process isolation, or Server-Sent Events (`SSE`) over HTTP for remote network deployment.

When an agent invokes a tool, the client dispatches a `tools/call` message containing the validated JSON arguments. The server executes the logic in its local sandbox and streams back a structured response containing text, base64 images, or resource links.

Figure 2: The MCP tool calling lifecycle: discovery handshake, client argument validation, sandboxed execution, and structured context grounding.
Figure 2: The MCP tool calling lifecycle: discovery handshake, client argument validation, sandboxed execution, and structured context grounding.

3. Building a Production FastMCP Server in TypeScript

Building an MCP server in TypeScript with the official `@modelcontextprotocol/sdk` is straightforward. By combining Zod schemas with asynchronous handlers, we achieve compile-time safety and automatic JSON schema generation.

Here is a complete, production-grade MCP server exposing a PostgreSQL database query tool and financial calculation utility:

mcp_server.ts
// server.ts - Production MCP Server with TypeScript & Zod
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";

const server = new Server(
  { name: "gopo-production-ledger-mcp", version: "1.0.0" },
  { capabilities: { tools: {}, resources: {} } }
);

// 1. Register available tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: "query_settlement_ledger",
      description: "Query balances, expenses, and pending settle-ups for a user group.",
      inputSchema: {
        type: "object",
        properties: {
          groupId: { type: "string", description: "Target group UUID" },
          currency: { type: "string", default: "USD" },
        },
        required: ["groupId"],
      },
    },
  ],
}));

// 2. Handle tool invocation
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === "query_settlement_ledger") {
    const { groupId } = request.params.arguments as { groupId: string };
    // Fetch from Postgres database securely
    return {
      content: [
        {
          type: "text",
          text: JSON.stringify({ status: "success", groupId, netBalances: { Alice: +45.5, Bob: -45.5 } }),
        },
      ],
    };
  }
  throw new Error("Unknown tool requested");
});

const transport = new StdioServerTransport();
await server.connect(transport);

4. Security Boundaries: OAuth 2.1, Egress & Sandboxes

Giving autonomous agents access to tools that execute shell commands or write to production databases introduces serious security considerations. Without strict boundaries, prompt injection attacks can trick an agent into exfiltrating credentials.

Production MCP servers implement three defense-in-depth layers: (1) OAuth 2.1 Mutual TLS authentication, (2) sandboxed ephemeral Docker containers with read-only filesystems, and (3) explicit Human-in-the-Loop approval triggers for destructive actions.

Prompt Injection Safeguards

Never allow an MCP server to execute arbitrary shell strings directly without whitelist parameterization. Validate every parameter with strict schemas and enforce non-root user permissions inside Docker containers.

5. Multi-Server Orchestration with Claude, Gemini & IDEs

In sophisticated enterprise setups, a single agent connects to multiple specialized MCP servers simultaneously: a GitHub MCP server for PR automation, a Database MCP server for analytical queries, and a Slack MCP server for notifications.

By configuring the host's `mcpServers` configuration manifest, developers orchestrate heterogeneous multi-agent swarms that autonomously collaborate across disparate software boundaries.

Topics & Architectural Concepts

#Model Context Protocol#MCP Server#Anthropic#Tool Calling#JSON-RPC 2.0#FastMCP
Free Companion Learning Materials

Take Your Knowledge Into Production

Every technical guide in Gopo Workspace includes 100% free companion PDF blueprints and production-ready GitHub repositories with zero paywalls.

Devon Vance

Written by Devon Vance

Open Source Collective

Staff Protocol Engineer

Senior systems educator specializing in distributed consensus, modern React compilers, and open-weights multimodal inference.