Ravindra BagaleCourses & study guides Track your progress

What Is MCP (Model Context Protocol)? Connect AI to Your Tools

Generative AI course · Chapter 44 · Estimated reading time: 12 minutes

An AI chat app on its own knows only what is in the chat. It cannot see your files, your calendar or your company's database. For years, every app had to build its own special connector for every tool, which was slow and messy. MCP, the Model Context Protocol, fixes this with one common standard: a tool offers an MCP server, and any AI app that speaks MCP can connect to it, a bit like how one USB-C port works with many devices. In this chapter you will learn what MCP is in plain words, build and test a tiny file-reader MCP server in Python with real output, see how a calendar connection works, look at a real read-only example from India, and finish with a safe-permissions checklist you can use before connecting anything.

What you will learn in this chapter

  • What MCP is, and who uses it (checked 19 October 2026)
  • Hosts, clients and servers, in plain words
  • Tools, resources and prompts: what a server can offer
  • Build 1: a file-reader MCP server in Python (real output)
  • Build 2: connecting a calendar through MCP
  • A real read-only example: Zerodha's Kite MCP
  • Build 3: a safe-permissions checklist

1. Suppose a shop owner asks AI about her own stock

Suppose Anjali runs a stationery shop. Her stock list is in a text file on her laptop, and her meetings are in her calendar. She asks her AI app: "What should I reorder, and when is my next supplier meeting?"

Without a connection, the app says: "I don't have access to your files or calendar. Please paste them." With an MCP server for her notes folder and one for her calendar, the app can call read_note("stock.txt") and a calendar lookup, and answer from her real data, after asking her permission to use each tool.

2. MCP in plain words

  • MCP is an open standard for connecting AI apps to tools and data. Anthropic released it in November 2024.
  • In December 2025 it became a founding project of the Agentic AI Foundation under the Linux Foundation, co-founded by Anthropic, Block and OpenAI.
  • It is supported by many AI apps and coding tools, including Claude, ChatGPT, Gemini, Microsoft Copilot, VS Code and Cursor.
  • Messages between app and server use a simple standard format called JSON-RPC 2.0. You do not need to write it by hand; libraries do it.

The 3 roles:

  1. Host: the AI app you use (a chat app, an editor).
  2. Client: the part inside the host that talks to one server.
  3. Server: a small program that offers abilities from one tool: a folder, a calendar, a database.

What a server can offer:

  • Tools: actions the AI can call, like read_note or create_event.
  • Resources: data the AI can read, like a file or a record.
  • Prompts: ready-made instructions the server suggests, like "summarise this week's meetings".
MCP in one picture: host, client, server, tool Steps from top to bottom: 1 You ask, In an AI app, the host; 2 Client, Inside the app, one per server; 3 Server, Offers tools, resources and prompts; 4 You approve, Before the tool runs; 5 Tool result, Back to the model for the answer. 1You askIn an AI app, the host 2ClientInside the app, one per server 3ServerOffers tools, resources and prompts 4You approveBefore the tool runs 5Tool resultBack to the model for the answer

MCP in one picture: host, client, server, tool

Ravindra Bagale's Tip

The mistake: installing any MCP server you find online and giving it your whole disk or full account access, because "it's just a connector". An MCP server is a program running with your permissions. Install servers only from the tool's own company or a source you trust, give each one the smallest folder or the read-only access it needs, and keep "ask before each tool call" switched on.

3. Worked example 1: a file-reader MCP server in Python

We built a tiny server that lets an AI app list and read text files, but only inside one notes folder. It uses the official MCP Python SDK (pip install mcp; version 2 is current).

# A tiny MCP server: lets an AI app list and read text files, but ONLY inside the notes folder.
from pathlib import Path
from mcp.server import MCPServer

NOTES = Path(__file__).parent / "notes"
mcp = MCPServer("Notes reader")

@mcp.tool()
def list_notes() -> list[str]:
    """List the text files in the notes folder."""
    return sorted(p.name for p in NOTES.glob("*.txt"))

@mcp.tool()
def read_note(name: str) -> str:
    """Read one text file from the notes folder."""
    path = (NOTES / name).resolve()
    if path.parent != NOTES.resolve():          # block ../ tricks: stay inside the folder
        raise ValueError("Only files inside the notes folder can be read.")
    return path.read_text(encoding="utf-8")

if __name__ == "__main__":
    mcp.run()          # stdio: the AI app starts this program and talks to it

The docstrings (the lines in triple quotes) matter: they become the tool descriptions the AI reads to decide which tool to use.

To test it without any AI app, we wrote a small client that acts like the host:

# Act as the AI app: connect to the server, see its tools, and call them.
import anyio
from mcp import Client
from notes_server import mcp

async def main():
    async with Client(mcp) as client:
        tools = await client.list_tools()
        for t in tools.tools:
            print(f"Tool: {t.name} - {t.description}")
        r = await client.call_tool("list_notes", {})
        print("list_notes ->", r.structured_content)
        r = await client.call_tool("read_note", {"name": "stock.txt"})
        print("read_note(stock.txt) ->", r.content[0].text.strip())
        r = await client.call_tool("read_note", {"name": "../secret.txt"})
        print("read_note(../secret.txt) -> error:", r.is_error, "|", r.content[0].text)

anyio.run(main)

Real output (19 October 2026, mcp 2.3.0; the notes and secret.txt are dummy files):

Tool: list_notes - List the text files in the notes folder.
Tool: read_note - Read one text file from the notes folder.
list_notes -> {'result': ['meeting.txt', 'stock.txt']}
read_note(stock.txt) -> Stock to reorder: notebooks (40), pen packs (25), geometry boxes (10).
read_note(../secret.txt) -> error: True | Error executing tool read_note

Read the output:

  1. The client discovered 2 tools and their descriptions; nobody told it in advance.
  2. list_notes and read_note returned real file content.
  3. The attempt to step outside the folder with ../ was refused. Limits like this belong in the server, not just in the prompt.

Connect it to an AI app. Most desktop AI apps that support local MCP servers use a settings file like this (the exact place is in each app's help page):

{
  "mcpServers": {
    "notes": {
      "command": "python",
      "args": ["/full/path/to/notes_server.py"]
    }
  }
}

Expected output (yours will be similar, not the same): after restarting the app, it lists "notes" with 2 tools. Ask "What do I need to reorder?" and the app asks permission to run read_note, then answers: "Reorder 40 notebooks, 25 pen packs and 10 geometry boxes (from stock.txt)."

4. Worked example 2: connecting a calendar

You rarely need to build a calendar server yourself. Many AI apps now offer ready-made connectors for calendars and email, and calendar providers and third parties publish MCP servers. The steps are similar everywhere:

  1. In your AI app's settings, open Connectors (or Integrations / MCP servers).
  2. Choose the calendar connector, or add a remote MCP server address given by a provider you trust.
  3. Sign in through the provider's own page. Read the permission screen: view only or view and edit?
  4. Pick view only unless you truly need the AI to create events.
  5. Test with one question.

Prompt:

Using my calendar, list my meetings for next Monday with times, and tell me
if I have a free hour between 2 pm and 6 pm. Do not create or change any events.

Expected output (yours will be similar, not the same): "Next Monday: 10:00 to 11:00 Team meeting; 15:00 to 15:30 Supplier call. You are free from 16:00 to 17:00." If you later allow editing, the app should show the event details and ask before creating it.

5. A real read-only example: Zerodha's Kite MCP

Zerodha, the Indian stockbroker, offers Kite MCP, a hosted MCP server at https://mcp.kite.trade/mcp (checked 19 October 2026). It is a good model of safe design:

  • The hosted version is read-only: an AI app can look at your holdings, positions and market data, but cannot place orders.
  • You log in through Kite's own login page with two-factor authentication; your password never goes to the AI.
  • You can revoke the access whenever you want.
  • Apps that only support local servers can connect through a small bridge: npx mcp-remote https://mcp.kite.trade/mcp.

Prompt (after connecting):

Using Kite, show my holdings as a table with quantity, average price and current value.
Then explain in simple words which 2 holdings are the largest share of my portfolio.
Do not suggest buying or selling.

Expected output (yours will be similar, not the same): a table of your holdings and a short plain explanation. This is not investment advice, and the AI can misread numbers; check anything important in Kite itself.

6. Worked example 3: a safe-permissions checklist

Use this before connecting any MCP server:

MCP SAFE-PERMISSIONS CHECKLIST
[ ] Source: made by the tool's own company or a source I trust?
[ ] Purpose: I can say in one line what I need it for.
[ ] Scope: only one folder / one calendar / one project, not everything.
[ ] Read-only: chosen read-only access unless editing is really needed.
[ ] Approval: "ask before each tool call" is ON for anything that writes, sends or deletes.
[ ] Secrets: no passwords or API keys typed into chats; logins happen on the provider's page.
[ ] Data: I know which data leaves my computer, and I am allowed to share it.
[ ] Untrusted content: tools that read web pages or emails cannot also send or delete without asking.
[ ] Review: I check the app's tool log for the first few uses.
[ ] Exit: I know how to disconnect and revoke access.

Expected output (yours will be similar, not the same): for Anjali's two connections, every box is ticked: the notes server is limited to one folder and read-only by design, and the calendar is connected as view only. If a box cannot be ticked, do not connect yet.

7. Beginner mistakes and quick fixes

Mistake What happens Quick fix
Installing unknown servers A program runs with your access Official or trusted sources only
Giving a whole disk or full account One mistake reaches everything One folder, one calendar, read-only
Turning off tool approval AI acts without asking Keep "ask before each call" on for writes
Limits only in the prompt A trick can talk past them Put limits in the server code, like the ../ check
Vague tool descriptions The AI picks the wrong tool Clear docstrings: what it does, what it needs
Mixing web reading and sending Hidden page text can trigger a send Approval before any send or delete

8. Try at home

Try at home

Task 1: run the file-reader server

  1. Install the SDK: pip install mcp.
  2. Create a notes folder with 2 text files and save the server and client.
  3. Run the client and check that ../ is refused.

Task 2: add a tool

  1. Add a tool count_words(name) that returns the word count of one note.
  2. Write a clear docstring for it.
  3. Run the client and check that the new tool appears.

Task 3: audit one connection

  1. Open the connectors or MCP settings in an AI app you use.
  2. Go through the checklist for one connection.
  3. Switch anything you do not need to read-only, or disconnect it.

Recap

In short

  1. MCP is an open standard that connects AI apps to tools and data, like one common port for many devices.
  2. Hosts are AI apps, clients live inside them, and servers offer tools, resources and prompts.
  3. A tiny Python server with 2 tools took about 20 lines, and it refused to read outside its folder.
  4. Ready-made connectors exist for calendars and many apps; choose view-only access first.
  5. Zerodha's hosted Kite MCP shows safe design: read-only, provider login, revocable.
  6. Use the checklist before connecting anything, and keep tool approval on.

You can now explain agents, build one in n8n, use browser agents safely, and connect AI to your tools through MCP with sensible limits. Start small, read-only, and with approval switched on.

Previous chapter: AI Browser Agents: Let AI Do Web Tasks Safely

Next chapter: Build Your First AI Agent in Python: Tools, Memory, Guardrails


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. Anjali, her shop, the notes and the calendar entries on this page are made up for learning. MCP and Kite MCP details were checked on modelcontextprotocol.io, the Linux Foundation announcement and Zerodha's Kite MCP pages on 19 October 2026. The Python output was produced on 19 October 2026 with mcp 2.3.0. AI output changes every time, so your output will be similar, not the same.