# Model Context Protocol (MCP) Explained

> A standard way to connect AI assistants to tools and data — servers, clients, tools, resources and prompts.

- Source: https://akshaythakare.com/notes/ai-tools/model-context-protocol
- Topic: AI Tools
- Level: intermediate
- Reading time: 3 min
- Tags: ai-tools, mcp, agents, integration
- Updated: 2026-10-11

## The integration problem

Every assistant needs access to databases, file systems, ticketing tools and APIs. Without a standard, each pairing of assistant and tool needs custom glue code.

**MCP** defines one protocol: tools are exposed by **MCP servers**, and any **MCP client** (an AI app or agent) can discover and call them.

**MCP request path:** User (asks a question) → MCP client (AI application) → MCP server (exposes tools) → Tool (query / API call) → Result (back to the model)

## What a server can expose

| Primitive | What it is | Example |
| --- | --- | --- |
| Tools | Functions the model may call | `run_readonly_sql(query)` |
| Resources | Data the client can read into context | A table schema, a file |
| Prompts | Reusable prompt templates | "Explain this query plan" |

## How a tool call flows

  
### Discover
On connect, the client asks the server which tools it offers, with names, descriptions and JSON schemas.
  
### Decide
The model sees the tool list and chooses to call one with arguments.
  
### Execute
The client sends the call to the server, which runs it with its own credentials and permissions.
  
### Return
The result goes back to the model, which continues the task or answers.

```python
# a tiny MCP server exposing one read-only tool (Python SDK)
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("warehouse")

@mcp.tool()
def row_count(table: str) -> int:
    """Return the number of rows in an allow-listed analytics table."""
    if table not in {"fact_sales", "dim_customer"}:
        raise ValueError("table not allowed")
    return query_scalar(f"SELECT COUNT(*) FROM {table}")

if __name__ == "__main__":
    mcp.run()
```

> **Warning: Servers run with real permissions**
>
> Give each MCP server the narrowest credentials possible, validate every argument, and require human approval for anything that writes or deletes.
