Barefoot AI HubTHE BAREFOOT FREELANCER
Start learning
⬢ AI Agents · Lesson 6 of 7

11MCP: Connecting Agents to Everything

The Model Context Protocol is the open standard for plugging tools and data into AI apps. Connect existing MCP servers, then build your own in about 20 lines of Python.

⏱ 22 min📶 Advanced🧪 3-question check

What you'll learn

  • Explain MCP hosts, clients and servers
  • Connect a ready-made MCP server to an AI app
  • Build a simple custom MCP server
  • Apply MCP security best practices

The problem MCP solves

Before MCP, every AI app needed custom code for every integration: one connector for Google Drive in app A, a different one in app B. The Model Context Protocol is an open standard — think of it as a USB-C port for AI. Build or install a connector once as an MCP server, and any MCP-compatible app can use it: Claude, Claude Code, Hermes Agent, n8n, VS Code, Cursor and many more.

MCP HOSTAI applicationClaude · Hermes · n8n · IDE
clientclientclient
SERVERFilesystemread/write a folder
SERVERGoogle Drive / Notionyour documents
SERVERYour custom serverCRM, invoices, bookings

What an MCP server can offer

CapabilityWhat it isExample
ToolsActions the model can callcreate_invoice, search_orders
ResourcesData the app can read into contextA file, a database record, a price list
PromptsReusable prompt templates“Weekly sales report” template

Servers run either locally (the app launches them as a process — “stdio” transport) or remotely over HTTP, which is how hosted connectors for services like Notion or Asana work.

Connect a ready-made server

The official filesystem server lets an AI app read and write files — but only inside folders you allow. Most desktop hosts accept a config like this (the file location differs per app; check its docs):

mcp configjson
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/you/ClientProjects"
      ]
    }
  }
}

With Claude Code, the same thing is one command:

terminalbash
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ~/ClientProjects

Restart the app and ask: “List the files in my ClientProjects folder and summarize the newest proposal.”

Build your own MCP server (Python)

Expose your own business data as tools any agent can use. This server gives agents read access to invoices.

  1. Install the SDK

    terminalbash
    pip install "mcp[cli]"
  2. Write the server

    invoice_server.pypython
    from mcp.server.fastmcp import FastMCP
    import csv
    
    mcp = FastMCP("invoices")
    
    def _load():
        with open("invoices.csv", newline="") as f:
            return list(csv.DictReader(f))
    
    @mcp.tool()
    def get_invoice(invoice_id: str) -> dict:
        """Get one invoice by its ID: client, amount in PHP, due date and status."""
        for row in _load():
            if row["id"] == invoice_id:
                return row
        return {"error": f"Invoice {invoice_id} not found"}
    
    @mcp.tool()
    def unpaid_total() -> str:
        """Total amount (PHP) of all unpaid invoices."""
        total = sum(float(r["amount_php"]) for r in _load() if r["status"] == "unpaid")
        return f"PHP {total:,.2f}"
    
    if __name__ == "__main__":
        mcp.run()          # stdio transport — the host app launches this process
  3. Test it with the MCP Inspector

    terminalbash
    mcp dev invoice_server.py

    A browser inspector opens where you can call each tool manually.

  4. Register it in your AI app

    mcp configjson
    {
      "mcpServers": {
        "invoices": {
          "command": "python",
          "args": ["/full/path/to/invoice_server.py"]
        }
      }
    }

Security: MCP servers are code you run

Key takeaways

  • MCP is an open standard: build a connector once, use it in any compatible AI app.
  • Servers provide tools (actions), resources (data) and prompts (templates).
  • Local servers run as processes; remote servers run over HTTP.
  • A custom server is ~20 lines with FastMCP — and deserves the same caution as any installed software.

Knowledge check

0 / 3

Q1In MCP, what is the “host”?

Q2Which MCP capability lets a model perform an action?

Q3Safest way to give an agent file access?

Finished this lesson?Your progress is saved in this browser.