Skip to content
BotServBotServ
MCPModel Context ProtocolAgentsToolsLocal AI

MCP Basics for AI Agents

Understand Model Context Protocol. How MCP connects agents with tools, transport, and building your first server.

S

schutzgeist

3 min read
MCP Basics for AI Agents

MCP Basics for AI Agents

What this article covers

  • What the Model Context Protocol is and why it matters.
  • How MCP connects AI agents to external tools.
  • The components that make up client, server, and transport.
  • How to build a simple MCP server.
  • Benefits, limitations, and common pitfalls.

Introduction: MCP Basics for AI Agents

AI agents need to interact with the world. They read files, call APIs, query databases, execute commands. Until now, each connection was custom-built for the project. The Model Context Protocol, or MCP, aims to change that. It’s an open standard that connects agents and tools in a standardized way.

Think of MCP as a universal socket. An agent speaks MCP, a tool provides an MCP server. This lets you combine tools and agents without reimplementing each connection from scratch. If you build agents, you benefit from a growing ecosystem of MCP servers.

Why do you need MCP?

Historically, every agent application had to write its own adapters for tools. A Discord tool, a database tool, a filesystem tool, all with different interfaces. MCP reduces this overhead. The agent speaks MCP, the server implements the tool. Benefits include:

  • Reusability: One server works for many clients.
  • Interchangeability: Servers are easy to swap out.
  • Security: Clear protocols and permissions.
  • Openness: No vendor lock-in.
  • Flexibility: New tools integrate quickly.

MCP explained simply

MCP is built on a client-server model. The client is the AI application, the server provides resources and tools. Communication happens over JSON-RPC.

Key terms:

  • Host: The application running the agent.
  • Client: The host’s connection to an MCP server.
  • Server: Provides tools, resources, and prompts.
  • Tool: A function the agent can call.
  • Resource: Data the agent can query.
  • Prompt: Predefined inputs for the model.
  • Transport: The communication channel, such as stdio or SSE.

Who is MCP for?

  • Developers connecting agents to tools.
  • Teams building and offering their own tools.
  • Architects designing modular AI systems.
  • Anyone wanting to avoid vendor lock-in.

Key concepts in MCP

  • JSON-RPC: Standard for remote procedure calls.
  • stdio: Transport via standard input and output.
  • SSE: Server-Sent Events for HTTP transport.
  • Capability: An ability a server offers.
  • Schema: Description of tools and resources.
  • StdioClientTransport: Connection via process pipes.

How an MCP system is organized

  1. Host: Starts the agent and MCP clients.
  2. Clients: Connect to MCP servers.
  3. Servers: Provide tools and resources.
  4. Model: Selects tools and executes them through clients.
  5. Transport: Handles communication.

Practical example: Simple MCP server in Python

from mcp.server import Server
from mcp.types import TextContent

server = Server('mein-server')

@server.tool()
def addiere(a: int, b: int) -> TextContent:
    return TextContent(text=str(a + b))

@server.resource('greeting://welt')
def greeting() -> TextContent:
    return TextContent(text='Hallo, Welt!')

if __name__ == '__main__':
    server.run()

The server exposes a tool and a resource. An MCP client can call both.

Practical example: Client in Python

from mcp import ClientSession, StdioServerTransport

transport = StdioServerTransport('python', ['mein_server.py'])
async with ClientSession(transport) as session:
    tools = await session.list_tools()
    ergebnis = await session.call_tool('addiere', {'a': 2, 'b': 3})
    print(ergebnis)

The client starts the server as a subprocess and calls the tool.

Security in MCP

  • Permissions: Servers should only allow what’s necessary.
  • Sandboxing: Isolate server processes.
  • Authentication: Essential for HTTP transport.
  • Auditing: Log which tools are called.
  • Human approval: Don’t execute critical operations automatically.

Common pitfalls with MCP

  • Missing tool descriptions: Models need good schemas.
  • Complex error handling: Network and process failures add complexity.
  • Underestimating security: A server with filesystem access is powerful.
  • Transport choice: Use stdio locally, SSE for remote.
  • Version compatibility: MCP is young and still evolving.
  • Difficult debugging: Async communication makes tracing harder.

Further reading and resources

FAQ: MCP

Is MCP only for Claude? No. It’s an open standard that different clients can use.

Do I need Python? No. SDKs exist for TypeScript, Python, and other languages.

Can MCP only run locally? No. HTTP/SSE enables remote servers too.

Are MCP servers secure? Only with permissions, sandboxing, and auditing. They have direct access to tools.

What’s the difference from function calling? MCP standardizes tool integration. Function calling is the model’s ability to invoke functions.

Sources and further reading

Summary: MCP Basics for AI Agents

MCP is an open standard that modularly connects AI agents with tools. Client, server, and transport form a clean architecture. Python and TypeScript SDKs make getting started straightforward. Good tool descriptions, permissions, and security matter most. Using MCP lets you build agents that extend easily with new capabilities.

Back to Blog
Share:

Related Posts