Tools: define one

A tool is a function the model can ask to run. MCP has official SDKs for TypeScript, Python, Go, Java, C# and more; these slides use the Python SDK.

  1. 1 Install

    # with uv (recommended)uv add "mcp[cli]" # or with pippip install "mcp[cli]"

    mcp is the official SDK.

    [cli] adds the mcp command used in step 3.

  2. 2 Define a tool

    server.pypython
    from mcp.server import MCPServerfrom mcp.types import ToolAnnotations mcp = MCPServer(    "calculator",    instructions="Use these tools for exact arithmetic.",) @mcp.tool(    title="Add numbers",    annotations=ToolAnnotations(read_only_hint=True),)def add(a: int, b: int) -> int:    """Add two numbers."""    return a + b if __name__ == "__main__":    mcp.run()  # stdio by default
  3. 3 Run and test

    mcp dev server.py

    Opens the MCP Inspector, where you can try add with your own numbers and see the result.

  • Function nameModel sees it

    The tool name: add.

  • DocstringModel sees it

    The description the model reads.

  • Type hintsModel sees it

    The input schema: a and b are integers.

  • titleHost only

    A friendly name for app UIs.

  • annotationsHost only

    Hints for the host, e.g. safe to run without asking.

  • instructionsHost decides

    Server-wide guidance, sent once in the initialize result.

6 / 28