You can skip this one

Nothing in this course needs code, and this lesson is optional. Read it if you want to see what a server is once the packaging comes off. You do not have to run anything, and every line is explained.

The example is harmless on purpose. It has one tool, the tool counts the words in a sentence, and it touches no files, accounts or money.

What was used

The MCP project publishes official software kits, called SDKs, in ten languages. This example uses the Python SDK, which installs under the name mcp.

The code below was run on December 3, 2026 with Python 3.11.14 and version 2.3.0 of the SDK, the newest on the Python package index that day. The SDK's documentation describes version 2 as "the current stable release line."

One small disagreement between official pages: the installation guide says the SDK needs Python 3.11 or later, while the package listing says 3.10 or later. Use 3.11 or later and both are satisfied.

The server

This is the whole server, saved in a file called server.py.

from mcp.server import MCPServer
from mcp.types import ToolAnnotations

mcp = MCPServer("Word Counter")


@mcp.tool(
    title="Count words",
    annotations=ToolAnnotations(read_only_hint=True, open_world_hint=False),
)
def count_words(text: str) -> int:
    """Count the words in a piece of text."""
    return len(text.split())


if __name__ == "__main__":
    mcp.run()

Reading it from the top:

  • The two import lines fetch the parts of the SDK the file needs.
  • MCPServer("Word Counter") creates a server and gives it a name.
  • @mcp.tool(...) marks the function below it as a tool. The title is the name a person sees.
  • read_only_hint=True is the server telling your assistant that this tool changes nothing. open_world_hint=False says it does not reach out to the wider internet.
  • def count_words(text: str) -> int says the tool takes one piece of text and gives back a whole number.
  • The sentence in triple quotes is the tool description from lesson 03, the text the model reads to decide when the tool is useful.
  • return len(text.split()) is the work itself: split the text at the spaces and count the pieces.
  • mcp.run() starts the server. With nothing in the brackets it runs as a local server, the kind your assistant starts in the background.

The SDK's documentation makes a point about those two hints that is worth repeating: "They are hints, not security." The server describes itself, and nothing checks the claim. The MCP specification says the same from the other side: clients must treat such labels "to be untrusted unless they come from trusted servers."

The client

A server does nothing until a client talks to it. In daily use the client lives inside your assistant. Here a second small file, client.py, plays that part.

import sys

import anyio

from mcp import Client, StdioServerParameters

server = StdioServerParameters(command=sys.executable, args=["server.py"])


async def main() -> None:
    async with Client(server) as client:
        print("Server:", client.server_info.name)
        print("Protocol version:", client.protocol_version)

        listing = await client.list_tools()
        for tool in listing.tools:
            print("Tool:", tool.name)
            print("Title:", tool.title)
            print("Description:", tool.description)
            print("Read-only hint:", tool.annotations.read_only_hint)

        result = await client.call_tool(
            "count_words", {"text": "The quarterly report is due on Friday"}
        )
        print("Result:", result.structured_content)
        print("Is error:", result.is_error)


if __name__ == "__main__":
    anyio.run(main)

The parts that matter:

  • StdioServerParameters(...) is the instruction for starting the server: run Python on server.py.
  • async with Client(server) as client starts the server and connects to it. When that block ends, the server is shut down.
  • client.list_tools() asks the server what it offers. This is the step your assistant performs when you connect a server.
  • client.call_tool(...) runs one tool with one input. This is the step behind every approval prompt you have seen.
  • The print lines put the answers on screen.

Running it

Three commands set it up and run it on a Mac or Linux computer. The first makes a private folder for the SDK, the second installs it, and the third runs the client. The first names Python 3.11 because that is the version used here.

python3.11 -m venv venv
venv/bin/pip install mcp
venv/bin/python client.py

This is the output, copied as it appeared:

Server: Word Counter
Protocol version: 2026-07-28
Tool: count_words
Title: Count words
Description: Count the words in a piece of text.
Read-only hint: True
Result: {'result': 7}
Is error: False

What the output shows

The first two lines are the connection. The client learned the server's name, and the two sides settled on version 2026-07-28 without being told to. That is the version agreement from lesson 04.

The next four lines are the listing. Everything your assistant knows about a tool before using it is here: a name, a title, a description and the hints. All of it was written by the server's author.

The last two lines are the call. The sentence has seven words, the tool said seven, and no error was reported.

What the example leaves out

A server you would connect at work has more around it. This one has no sign-in, because it runs on the same computer and reaches nothing. It asks no permission, because this bare client has no approval prompt. It also has no person and no model in it. In your assistant, a model decides when to call the tool, and you decide whether to let it.

Those missing parts are the subject of the rest of this course. The call in the middle is the same.

What you can now do

That is the end of the course. Across the six modules, you should now be able to do the following.

  • Explain what MCP is, name the host, client and server, and tell a local server from a remote one.
  • Connect a ready-made server, give it a real task, read what it did, and respond when it fails.
  • Choose servers worth having, use several on one job, and ask in a way that uses tools well.
  • Check what a server can see and do before you install it.
  • Help a team decide who approves which servers, and keep a record of what agents did.
  • Describe how a payment travels through MCP, find the limits on it, and read a small server's code.

The full lesson list is on the course page.

Sources

Last verified: December 3, 2026.

Was this lesson useful?

Private. It goes to me and is not shown on the site.
← Previous
The Limits on What an Agent Can Spend