The Layers
| Layer | Question it answers | Examples |
|---|---|---|
| Model API | How do I send a prompt and get tokens? | Vendor chat and messages APIs |
| Tool and data protocol | How does a model-powered app discover and call tools, read resources, use prompt templates? | Model Context Protocol (MCP) |
| Agent-to-agent protocol | How do independent agents discover each other\'s capabilities and delegate tasks? | Agent2Agent (A2A) and similar efforts |
| Identity and authorisation | Who is the agent acting for, and what may it do? | OAuth 2.x flows, workload identity |
| Observability | What did the agent do, and why? | OpenTelemetry traces, logs of tool calls |
MCP is the most widely adopted of these; many coding agents, desktop assistants and IDEs support it as clients, and many vendors publish servers. Agent-to-agent standards are newer and still evolving, so verify the current specification and governance before you build on one.
What MCP Standardises
An MCP server exposes capabilities; an MCP client inside the host application connects to servers on behalf of a model. The core capability types are:
- Tools: functions the model can call, described by a name, a description and a JSON Schema for inputs. This is the part most people use.
- Resources: data the client can read, such as files, records or documents, identified by URIs.
- Prompts: reusable prompt templates a user can invoke.
Messages use JSON-RPC 2.0. The two common transports are stdio (the client launches the server as a local subprocess; simplest for local tools) and an HTTP-based transport for remote servers, which is where authentication matters. The protocol is versioned and has changed since release, so pin your SDK version and read the changelog when upgrading.
Build a Working MCP Server
This server exposes one tool: a loan EMI calculator. We ran it with version 2.3 of the official Python SDK (pip install "mcp>=2"). Note that in 1.x versions of the SDK the class was FastMCP imported from mcp.server.fastmcp; in 2.x it is MCPServer from mcp.server.mcpserver. SDK APIs move, so check the documentation for your installed version.
# mcp_server.py
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("emi-calculator")
@mcp.tool()
def monthly_emi(principal: float, annual_rate_percent: float, years: int) -> dict:
"""Monthly EMI for a fixed-rate loan. Rate is a percentage (8.5 means 8.5%)."""
r = annual_rate_percent / 12 / 100
n = years * 12
emi = principal / n if r == 0 else principal * r * (1 + r) ** n / ((1 + r) ** n - 1)
return {"emi": round(emi, 2), "total_paid": round(emi * n, 2), "total_interest": round(emi * n - principal, 2)}
if __name__ == "__main__":
mcp.run() # stdio transport by defaultThe function\'s type hints become the tool\'s input schema, and its docstring becomes the description the model reads to decide when to call it. Writing a precise docstring is the single most effective improvement you can make to tool quality.
Test It with a Client
# mcp_client.py
import asyncio, sys
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
params = StdioServerParameters(command=sys.executable, args=["mcp_server.py"])
async with stdio_client(params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
print([t.name for t in tools.tools])
result = await session.call_tool("monthly_emi", {"principal": 5000000, "annual_rate_percent": 8.5, "years": 20})
print(result.content[0].text)
asyncio.run(main())['monthly_emi']
{
"emi": 43391.16,
"total_paid": 10413878.8,
"total_interest": 5413878.8
}That output is from our run. You can cross-check the arithmetic with the Loan EMI Calculator. To use the server from a desktop agent or IDE, register the command (python mcp_server.py) in that application\'s MCP configuration; each host has its own configuration file format, so follow its documentation.
Designing Good Tools
- Few, well-named tools beat many overlapping ones. Models choose better from a short list.
- Describe when to use each tool, not just what it does, and document units and formats (the percent example above).
- Return structured, compact results. Large payloads burn context and money; paginate or summarise.
- Make errors informative, so the model can correct its call ("principal must be positive").
- Prefer idempotent operations and separate read tools from write tools, so you can grant read-only access.
- Validate inputs on the server. The model\'s arguments are untrusted input.
Security: The Part That Matters
An MCP server gives a model hands. Treat it like any externally reachable API, and add the risks specific to agents:
- Least privilege. Give each server only the access its tools need, using a dedicated, scoped credential. A read-only database tool should connect with a read-only user.
- Authenticate remote servers. For HTTP transports use the authorisation mechanism defined in the MCP specification (built on OAuth) and short-lived tokens. Never expose an unauthenticated remote server.
- Prompt injection. Content returned by a tool (a web page, an email, a ticket) can contain instructions aimed at the model. Do not let a tool that reads untrusted text sit in the same agent as a tool that can send data out or modify systems without a human confirmation step.
- Trust and supply chain. Third-party servers run code and describe themselves to your model. Review them as you would any dependency: pin versions, read the source, and run them in a sandbox.
- Human confirmation for actions with side effects (sending money, deleting data, emailing customers).
- Log every tool call with arguments (redacted where needed), caller identity and result status.
Where A2A and Similar Protocols Fit
MCP connects one agent to tools. Agent-to-agent protocols address a different problem: independent agents, possibly built by different vendors, discovering each other\'s capabilities (typically through a published description of skills and endpoints) and delegating tasks, sometimes long-running ones. If you operate several specialised agents inside one organisation, a simple internal API often works. Consider a standard protocol when agents cross organisational boundaries or vendors. The space is moving quickly, so check the current state of A2A and any competing or merging efforts before committing.
A Practical Adoption Path
- Pick one internal capability people already ask about in chat (look up an order, query a metric, check a deployment).
- Wrap it as a read-only MCP tool with a precise description.
- Connect it to the coding agent or assistant your team uses and watch real calls for a week.
- Fix descriptions where the model chose wrongly, add logging, and only then add write tools with confirmation.
Frequently Asked Questions
What is the Model Context Protocol?
MCP is an open protocol that lets model-powered applications discover and call tools, read resources and use prompt templates exposed by servers, using JSON-RPC 2.0 over stdio or HTTP-based transports, so one integration works across many agents.
What is the difference between MCP and A2A?
MCP connects an agent to tools and data. Agent-to-agent protocols such as A2A address independent agents discovering each other's capabilities and delegating tasks. They operate at different layers and can be used together.
How do tool descriptions affect agent behaviour?
The model chooses tools by reading their names and descriptions, so precise descriptions that state when to use the tool and what units and formats it expects directly improve how often it is called correctly.
Is it safe to install third-party MCP servers?
Treat them like any dependency that runs code and influences your model. Pin versions, review the source, run them sandboxed with least-privilege credentials, and require human confirmation for actions with side effects.
What is prompt injection in the context of MCP?
It is when content returned by a tool, such as a web page or email, contains instructions that manipulate the model. Avoid combining tools that read untrusted text with tools that can exfiltrate data or change systems without confirmation.