Skip to content

Building AI Tools with MCP

·4 min read·Ahmet Kaan Celenk
MCPAIPythonClaude

What Is MCP?#

The Model Context Protocol (MCP) is an open standard that gives AI assistants the ability to interact with the outside world. Developed by Anthropic, the protocol lets AI models reach real-time data and use external tools.

The biggest limitation of traditional AI models is their training data cutoff. MCP solves this by giving models access to live data.

NOTE

MCP is the technology that turns AI assistants from mere chatbots into genuine digital assistants. It is developed by Anthropic as open source.

How Does It Work?#

The MCP architecture has three core components:

ComponentDescription
HostThe AI model (e.g. Claude Desktop)
ClientThe MCP client (runs inside the host)
ServerThe server exposing the tools (the part you build)

MCP Architecture Diagram#

Loading diagram...

Communication Flow#

Loading diagram...

Transport Layer#

MCP supports two transport methods:

  • stdio: standard input/output, for local tools
  • SSE (Server-Sent Events): HTTP-based communication, for remote servers

TIP

We recommend using the stdio transport while developing. It is simpler and easier to debug. You can move to SSE when going to production.

Building an MCP Tool with Python#

Let's build a simple exchange rate tool. First, install the dependencies:

pip install mcp httpx

Then create the MCP server:

server.py
from mcp.server.fastmcp import FastMCP
import httpx
 
mcp = FastMCP("exchange-rate")
 
@mcp.tool()
async def get_exchange_rate(base: str, target: str) -> str:
    """Query the live exchange rate."""
    async with httpx.AsyncClient() as client:
        response = await client.get(
            f"https://api.exchangerate.host/latest",
            params={"base": base, "symbols": target}
        )
        data = response.json()
        rate = data["rates"][target]
        return f"1 {base} = {rate} {target}"
 
if __name__ == "__main__":
    mcp.run(transport="stdio")
💡

The @mcp.tool() decorator automatically uses the function's docstring as the tool description. That description plays a critical role in how the AI model decides when to reach for the tool.

Claude Desktop Integration#

To add your tool to Claude Desktop, add this configuration to claude_desktop_config.json:

claude_desktop_config.json
{
  "mcpServers": {
    "exchange-rate": {
      "command": "python",
      "args": ["path/to/server.py"]
    }
  }
}

WARNING

Remember to give the absolute path to the server file in args. With a relative path, Claude Desktop may not find the tool.

Performance Comparison#

The difference between MCP and a direct API call can be expressed with a simple formula:

Total response time: Ttotal=Tmodel+Tmcp+TapiT_{total} = T_{model} + T_{mcp} + T_{api}

Where the average values are:

Ttotal200ms+50ms+TapiT_{total} \approx 200\text{ms} + 50\text{ms} + T_{api}

MCP overhead averages around 50ms50\text{ms} — low enough that it does not degrade the user experience.

Where to Use It#

Examples of tools you can build with MCP:

  • Finance: live market data, exchange rates, crypto prices
  • Weather: location-based forecasts
  • Databases: running SQL queries directly
  • IoT: reading sensor data and controlling devices
  • Business processes: CRM, ERP and project management tools — these can be integrated into both web and mobile platforms

IMPORTANT

MCP servers must be designed carefully from a security standpoint. Store external API keys as environment variables — never write them into source code.

Conclusion#

MCP is a transformative protocol that turns AI assistants from passive chatbots into active digital tools. With Python you can build a tool quickly and integrate it into AI models like Claude.

While you are building MCP tools, you may also want to explore another powerful extension system in Claude: Skills, covered in our Claude Skills guide, is a complementary feature that gives Claude persistent instructions and workflows.

ℹ️

The source code for the MCP exchange rate tool used in this article is available on our GitHub page.

References#

Share:

Related Posts