How to Use MCP Servers for AI Agents Step by Step

Coding Liquids blog cover featuring Sagnik Bhattacharya for setting up MCP servers for AI agents.
Coding Liquids blog cover featuring Sagnik Bhattacharya for setting up MCP servers for AI agents.

AI agents need tools to do real work — search files, query databases, call APIs, read documents. MCP servers provide those tools through a standard protocol that works across different AI providers.

I teach Flutter and Excel with AI — explore my courses if you want structured learning.

This guide walks through setting up MCP servers specifically for agent workflows, where the model makes multiple tool calls in sequence to complete a task.

Follow me on Instagram@sagnikteaches

Quick answer

Create an MCP server that exposes focused tools with clear schemas. Connect it to your agent runtime. The agent discovers available tools, decides which to call, and chains results across multiple steps.

Connect on LinkedInSagnik Bhattacharya
  • You are building an AI agent that needs to interact with external systems.
  • You want a standard tool interface instead of hard-coded function calls.
  • You need the agent to discover and chain tools dynamically.

Why MCP matters for agents

Without MCP, every agent-tool connection is custom. You write specific code to call each API, format each result, and handle each error. MCP standardises this so you can swap tools, add new ones, or change the agent runtime without rewriting integrations.

Subscribe on YouTube@codingliquids

For agents specifically, MCP's tool discovery is important — the agent can see what tools are available and decide which ones to use for each step of a multi-step task.

Designing tools for agent use

Agent-facing tools need clearer descriptions than human-facing ones. The model reads the tool description to decide whether and how to use it.

Keep each tool focused on one action. A tool that 'searches and summarises' is harder for the agent to use well than separate search and summarise tools.

  • Write descriptions that explain what the tool does, what it returns, and when to use it
  • Use specific parameter names — `file_path` not `input`
  • Return structured results the agent can parse and use in the next step
  • Include error information in the response rather than throwing exceptions

Server architecture for agents

For agent workflows, you often need multiple tools that share context — a database connection, a file system root, or an API session. Structure your MCP server so tools can share this state without exposing it to the agent.

Consider grouping related tools into a single server (e.g., all database tools together) rather than running one server per tool.

Connecting the server to an agent runtime

Most agent frameworks (LangChain, CrewAI, Claude's agent SDK, AutoGen) support MCP or can be adapted to use it. The connection typically involves starting the MCP server and passing its transport to the agent client.

For local development, use the stdio transport. For production, use SSE or HTTP so the server can run on a separate machine or container.

Testing agent-tool interactions

Test each tool independently first, then test the agent's ability to choose and chain tools correctly. The most common failures are: the agent picks the wrong tool, sends incorrect parameters, or misinterprets the result.

Log every tool call during development. Reviewing the sequence of calls is the fastest way to debug agent behaviour.

Worked example: file research agent

You build an MCP server with tools for listing files, reading file contents, and searching text within files. An agent connected to this server can handle requests like 'Find all Python files that import requests and summarise what HTTP calls they make' by chaining list, search, and read operations.

Common mistakes

  • Building tools that are too broad or vague for the agent to use reliably.
  • Skipping tool descriptions — the agent literally reads them to decide what to call.
  • Not logging tool calls during development, making it impossible to debug agent decisions.

When to use something else

If you want to connect MCP to ChatGPT specifically, see MCP with ChatGPT. For hosting MCP servers for multiple apps, see remote MCP servers.

Frequently asked questions

What does MCP give an agent?

A standard way to discover and call tools. Instead of bespoke code per integration, the agent reads tool schemas, decides which to call, and chains results across steps.

Why use MCP instead of hand-wiring each tool?

Without it, every agent-tool link is custom code for calling, formatting, and error handling. MCP standardises that, so you can swap tools, add new ones, or change the agent runtime without rewriting integrations.

How should I describe tools for an agent?

More explicitly than for humans. The model picks tools from their descriptions, so state what the tool does, when to use it, and exactly what each parameter means; vague descriptions cause wrong calls.

How do tools share state like a DB connection or session?

Structure the server so tools share context internally without exposing it to the agent. The agent sees clean tool calls while the server manages the connection, root path, or session behind them.

How many tools should one agent have?

Few, focused ones. Too many overlapping tools make the model's choice harder and more error-prone. One clear job per tool beats a single Swiss-army tool.

How do I stop an agent looping or misusing tools?

Set step limits, validate parameters before executing, return structured results, and make errors explicit so the model can recover instead of guessing.

Related guides on this site

These guides cover specific MCP setups and agent patterns you can build on.