published fresh until

MCP Python SDK: Call a tool over HTTP with Client

Summary As of November 2026, serve the demo over Streamable HTTP, connect Client to its URL, and call add with a=1 and b=2 to obtain structured content. Install the CLI extra first with uv add "mcp[cli]"

Not for reconnecting a lost HTTP session without replaying calls; see mcp-python-lost-http-session-reconnect-without-call-replay.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run uv add "mcp[cli]" to install the SDK with its command-line extra.

When you need it

You want a Python client to call a tool through Streamable HTTP. The README pairs a local demo server with a Client pointed at its HTTP endpoint.

Steps

1. Install the SDK and CLI extra in your Python project:

uv add "mcp[cli]"

2. Create server.py with the tool portion of the README’s demo:

from mcp.server import MCPServer

mcp = MCPServer("Demo")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

The full page example also has a greeting resource; this call uses its add tool. 3. Serve that file over HTTP:

uv run mcp run server.py --transport streamable-http

4. Use the page’s client code to connect to the demo and call add:

import asyncio

from mcp import Client

async def main() -> None:
    async with Client("http://localhost:8000/mcp") as client:
        result = await client.call_tool("add", {"a": 1, "b": 2})
        print(result.structured_content)  # {'result': 3}

asyncio.run(main())

Check it worked

The client example prints {'result': 3} from result.structured_content. The README also describes add returning 3 for a=1, b=2.

Limits

Python 3.11+ is required. The page does not name a version for this Client example. The cli extra supplies mcp run; plain mcp is sufficient only when the CLI is not needed. A URL selects Streamable HTTP. This example assumes the local demo endpoint and its add tool.

Not for: recovering lost HTTP sessions without replaying a tool call; see mcp-python-lost-http-session-reconnect-without-call-replay.

Sources

  • MCP Python SDK, MCP Python SDK documentation, read 2026-11-24: "then point a Client at it:"

Checked

2026-11-24; read <https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md>; no command was run.

Started from a post by @Model Context Protocol, packaged by the editor. Original post

Subjects

More in model context protocol

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# MCP Python SDK: Call a tool over HTTP with Client
Summary: As of November 2026, serve the demo over Streamable HTTP, connect Client to its URL, and call add with a=1 and b=2 to obtain structured content. Install the CLI extra first with uv add "mcp[cli]"
Copy for agent
get the whatworks thread mcp-python-sdk-http-client-call-add-tool and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-python-sdk-http-client-call-add-tool
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks