Skip to content
Artificial Intelligence2026-10-25·8 min read

Model Context Protocol (MCP): Connecting AI Agents to Tools

How Anthropic Model Context Protocol (MCP) standardizes JSON-RPC tool calling between LLMs, local databases, and enterprise APIs.

Model Context Protocol (MCP): Connecting AI Agents to Tools

TL;DR

MCP is an open JSON-RPC 2.0 protocol over stdio or Streamable HTTP that lets a single tool server work across Claude, Cursor, VS Code, and custom agent runtimes without rewriting adapters.

Model Context Protocol (MCP) is an open JSON-RPC 2.0 protocol that standardizes how AI clients and IDEs discover and call external tools, read data sources, and load prompt templates.

Before MCP, connecting Claude, Cursor, ChatGPT, and an internal CLI agent to the same PostgreSQL database, Git repository, and issue tracker meant writing and maintaining separate tool schemas and glue code for every single client. When an AI vendor changed its tool-calling payload format, integrations broke silently.

MCP decouples the AI host from the tool server so you write an integration once and run it across any compatible client.


1. What Model Context Protocol (MCP) Actually Solves

At the wire level, MCP specifies capability negotiation, typed JSON Schema inputs, and two primary transports:

  • stdio transport: Ideal for local developer tools, Git inspection, and filesystem helpers launched as child processes by an IDE or desktop host.
  • Streamable HTTP transport: Built for remote, multi-user enterprise servers authenticated with OAuth tokens behind TLS.

Instead of hardcoding custom OpenAI or Anthropic tool wrappers inside every repo, an MCP server exposes its tools through a standard handshake so any compliant host discovers them automatically at startup.


2. The M x N Integration Nightmare vs The M + N Standard

To understand why tech leads and CTOs love MCP, look at the mathematics of software integration:

┌────────────────────────────────────────────────────────────────────────┐
│ 1. THE PROPRIETARY FUNCTION-CALLING NIGHTMARE: (M x N Integrations)   │
└────────────────────────────────────────────────────────────────────────┘

     AI CLIENTS (M)                                 DATA SOURCES (N)
    ┌──────────────┐                              ┌──────────────────┐
    │ Claude Code  │───┬──────────────┬──────────►│ PostgreSQL DB    │
    └──────────────┘   │              │           └──────────────────┘
    ┌──────────────┐   │   Custom     │   Custom  ┌──────────────────┐
    │ Cursor IDE   │───┼── Function ──┼── Calling │ GitHub Repos     │
    └──────────────┘   │   Wrappers   │   Glue    └──────────────────┘
    ┌──────────────┐   │              │           ┌──────────────────┐
    │ Custom Agent │───┴──────────────┴──────────►│ Terminal / Bash  │
    └──────────────┘                              └──────────────────┘
    * Result: 3 AI Clients x 3 Data Sources = 9 separate custom adapters!
      If you add 5 new AI models and 10 new internal tools, you must write 50 new wrappers!

┌────────────────────────────────────────────────────────────────────────┐
│ 2. THE MODEL CONTEXT PROTOCOL (MCP) STANDARD: (M + N Integrations)     │
└────────────────────────────────────────────────────────────────────────┘

     AI CLIENTS (M)              MCP PROTOCOL BUS            MCP SERVERS (N)
    ┌──────────────┐          ┌────────────────────┐      ┌──────────────────┐
    │ Claude Code  │─────────►│                    │─────►│ PostgreSQL Server│
    ├──────────────┤          │  STANDARD JSON-RPC │      ├──────────────────┤
    │ Cursor IDE   │─────────►│  UNIVERSAL PLUG    │─────►│ GitHub Server    │
    ├──────────────┤          │  (Tools, Prompts,  │      ├──────────────────┤
    │ Any Agent    │─────────►│   Resources)       │─────►│ Local Filesystem │
    └──────────────┘          └────────────────────┘      └──────────────────┘
    * Result: Each AI client supports MCP once. Each data tool builds an MCP server once.
      Adding a new tool takes 1 integration, not 50!

Proprietary Function Calling Chaos vs The Universal MCP Standard Figure 1: The proprietary function-calling approach (left) creates a tangled mess of brittle custom adapters and vendor lock-in. Model Context Protocol (right) establishes a unified, clean standard bus bar where any agent docks with any tool instantly.


3. The 3 Core Primitives of MCP

MCP standardizes how an AI assistant interacts with the outside world by breaking all interactions down into three clean primitives:

                        ┌───────────────────────────────┐
                        │     THE 3 MCP PRIMITIVES      │
                        └───────────────┬───────────────┘
                                        │
        ┌───────────────────────────────┼───────────────────────────────┐
        ▼                               ▼                               ▼
┌───────────────┐               ┌───────────────┐               ┌───────────────┐
│ 1. RESOURCES  │               │  2. PROMPTS   │               │   3. TOOLS    │
│  (Read-Only)  │               │  (Workflows)  │               │ (Executable)  │
│               │               │               │               │               │
│ • File data   │               │ • Pre-built   │               │ • SQL queries │
│ • DB schemas  │               │   templates   │               │ • Git commits │
│ • Log streams │               │ • Multi-step  │               │ • API actions │
│ • API docs    │               │   tasks       │               │ • Deployments │
└───────────────┘               └───────────────┘               └───────────────┘

1. Resources (Read-Only Context)

Resources are like GET endpoints or open book pages. They represent data that the server makes available to the AI for background reading without executing code.

  • Examples: The current contents of package.json, a database schema definition, or a live application error log.
  • Resources have clean URIs like postgres://main-db/schema or file:///src/index.ts.

2. Prompts (Pre-Engineered Workflows)

Prompts are reusable prompt templates packaged directly inside the server.

  • Example: A Git MCP server might provide a built-in prompt called generate_release_notes(from_tag, to_tag). The user doesn't have to write prompt engineering instructions; the MCP server supplies the expert instructions directly to the AI model.

3. Tools (Executable Actions)

Tools are functions that the AI can explicitly choose to invoke with arguments to alter the state of the world.

  • Examples: execute_sql_query(query), create_pull_request(branch, title), or send_slack_alert(channel, message).
  • Tools require explicit parameters and return structured results back into the conversation context.

4. How MCP Works Under the Hood: The Architecture

How do an AI model, a desktop application, and your database actually talk to each other?

MCP uses a lightweight, language-agnostic JSON-RPC 2.0 protocol. It divides responsibility across three layers:

┌────────────────────────────────────────────────────────────────────────┐
│                   MCP HOST, CLIENT, AND SERVER TOPOLOGY                │
└────────────────────────────────────────────────────────────────────────┘

 ┌─────────────────────────────────────────────────────────────┐
 │ 1. HOST APPLICATION (e.g., Claude Desktop, Cursor, CLI)     │
 │    Manages user interface, loads LLM, orchestrates context. │
 └──────────────────────────────┬──────────────────────────────┘
                                │
                                ▼
 ┌─────────────────────────────────────────────────────────────┐
 │ 2. MCP CLIENT (Integrated into Host)                        │
 │    Negotiates protocol capabilities, verifies permissions.  │
 └──────────────────────────────┬──────────────────────────────┘
                                │ Transport: stdio (Local) or SSE/HTTP (Remote)
                                ▼
 ┌─────────────────────────────────────────────────────────────┐
 │ 3. MCP SERVER (e.g., PostgreSQL MCP, Git MCP, Linear MCP)   │
 │    Exposes specific resources, tools, and prompts.          │
 └──────────────────────────────┬──────────────────────────────┘
                                │
                                ▼
 ┌─────────────────────────────────────────────────────────────┐
 │ 4. TARGET DATA SOURCE (Database, OS Files, Cloud REST API)  │
 └─────────────────────────────────────────────────────────────┘

Transport Modes:

  1. Standard Input/Output (stdio): Perfect for local tools on your machine. The host application spawns the MCP server as a local child process and exchanges messages over standard input and output streams. It requires zero open ports and zero network latency.
  2. Server-Sent Events (SSE) / HTTP: Perfect for remote enterprise services. The MCP server runs in the cloud (or inside a Kubernetes cluster) and communicates with the client over secure, authenticated HTTPS channels.

5. Building a Real MCP Server in 20 Lines of Code

One reason developers are building thousands of community MCP servers is because the official SDKs (TypeScript and Python) are clean and intuitive.

Here is a minimal TypeScript MCP server exposing a real mathematical tool to an AI agent:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

// 1. Initialize the MCP Server
const server = new McpServer({
  name: "Production-Metrics-Server",
  version: "1.0.0"
});

// 2. Register a Tool with Zod validation
server.tool(
  "calculate_churn_rate",
  "Calculates monthly customer churn rate percentage from raw counts",
  {
    lostCustomers: z.number().describe("Number of customers lost this month"),
    startCustomers: z.number().describe("Customer count at the start of the month")
  },
  async ({ lostCustomers, startCustomers }) => {
    if (startCustomers <= 0) {
      throw new Error("startCustomers must be greater than zero.");
    }
    const rate = ((lostCustomers / startCustomers) * 100).toFixed(2);
    return {
      content: [{ type: "text", text: `Monthly Churn Rate: ${rate}%` }]
    };
  }
);

// 3. Connect via local stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);

The moment this server starts, any MCP-compatible AI client (such as Claude Desktop or Cursor) automatically detects the tool, reads its input schema, and can invoke it with 100% type safety.


6. Security and Sandboxing: The Real Superpower

Connecting powerful AI agents to local terminals and production databases sounds risky. What prevents an AI agent from running DROP DATABASE production;?

MCP was engineered with strict security boundaries from day one:

  1. Human-in-the-Loop Confirmation: By default, MCP hosts require explicit user confirmation before executing potentially destructive tools.
  2. Capability Negotiation: When client and server connect, they declare exactly which capabilities they support. A read-only server cannot be forced to run commands.
  3. Local Process Isolation: With stdio transport, the MCP server runs inside the local user's security permissions, meaning it cannot access resources outside what the host operating system permits.

Key Takeaways

  1. Open Standard: MCP replaces per-vendor tool wrappers with a single JSON-RPC 2.0 protocol.
  2. From M x N to M + N: Write a server once for PostgreSQL, Slack, or internal APIs and reuse it across every compatible client.
  3. Three Core Primitives: Resources (read-only context), Prompts (reusable templates), and Tools (callable actions).
  4. Scoped Security: Hosts negotiate permissions explicitly and can require human approval before mutating state.

Common MCP Troubleshooting Questions

Why does my stdio MCP server fail to connect or throw JSON parse errors?

Any console.log() or print statement writing to stdout corrupts the JSON-RPC stream over stdio. Always send diagnostic logs to stderr (console.error()), never stdout.

When should I use stdio vs Streamable HTTP transport?

Use stdio for local developer utilities that inspect local files, git diffs, or local Docker containers. Use Streamable HTTP when multiple team members share a hosted server with centralized auth and audit logging.

How do I stop an MCP agent from running destructive SQL queries?

Expose read-only tools backed by a read-only database role, validate every query server-side, and keep write operations behind separate tools that require explicit user confirmation in the client host.


References & Further Reading

Sabtain Ali

Written by Sabtain Ali

Full-Stack Developer

I build backends and full-stack web apps with React, Node.js, Laravel, and MySQL - including the CommutersLink carpooling backend in Pakistan and web tools for WHO and WOAH.