mcpField
M
MCP SSE Client Python

MCP SSE Client Python

Local
github.com/zanetworkerDeveloper Tools25Updated 5w ago

About MCP SSE Client Python

MCP SSE Client Python is a Python toolkit for interacting with remote MCP endpoints over Streamable HTTP or SSE. It is aimed at developers who write scripts or want an interactive test interface, and it can use several LLM providers to choose tools from natural language.

Key features

  1. 01Streamable HTTP and SSE transports
  2. 02Async context manager for connections
  3. 03Custom authentication headers
  4. 04LLM-based tool selection
  5. 05Streamlit interactive playground

Use cases

  1. 01Listing and calling tools on a remote MCP server from scripts
  2. 02Testing MCP tool calls driven by natural language

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MCP Playground

A Python toolkit for interacting with remote Model Context Protocol (MCP) endpoints. Supports Streamable HTTP (default) and SSE transports, with LLM-powered tool selection across multiple providers.

Quick Start

git clone https://github.com/zanetworker/mcp-playground.git
cd mcp-playground
pip install -e ".[all]"

Usage

Context Manager (recommended)
import asyncio
from mcp_playground import MCPClient

async def main():
    async with MCPClient("http://localhost:8000/mcp") as client:
        tools = await client.list_tools()
        print(f"Found {len(tools)} tools")

        result = await client.call_tool("add", arguments={"a": 10, "b": 5})
        print(f"Result: {result.content}")

asyncio.run(main())
SSE Transport (legacy servers)
async with MCPClient("http://localhost:8000/sse", transport="sse") as client:
    tools = await client.list_tools()
Custom Auth / Headers
import httpx

http = httpx.AsyncClient(headers={"Authorization": "Bearer token"})
async with MCPClient("http://localhost:8000/mcp", http_client=http) as client:
    tools = await client.list_tools()
One-Shot Usage

For simple scripts that don't need a persistent connection:

client = MCPClient("http://localhost:8000/mcp")
tools = await client.list_tools()  # auto-connects and disconnects

LLM-Powered Tool Selection

Let an LLM choose and execute the right MCP tool based on natural language:

import os
from mcp_playground import MCPClient
from mcp_playground.llm_bridge import OpenAIBridge

async with MCPClient("http://localhost:8000/mcp") as client:
    bridge = OpenAIBridge(client, api_key=os.environ["OPENAI_API_KEY"])
    result = await bridge.process_query("Add 10 and 5")

    if result["tool_call"]:
        print(f"Tool: {result['tool_call']['name']}")
        print(f"Result: {result['tool_result'].content}")
Supported LLM Providers
ProviderBridge ClassDefault Model
OpenAIOpenAIBridgegpt-4o
AnthropicAnthropicBridgeclaude-sonnet-4-20250514
OllamaOllamaBridgellama3.3
OpenRouterOpenRouterBridgeany model ID

Interactive Playground (Streamlit)

cd mcp-streamlit-app
pip install -r requirements.txt
streamlit run app.py

Features:

  • Transport selector (Streamable HTTP / SSE)
  • Multi-provider LLM support (OpenAI, Anthropic, Ollama, OpenRouter)
  • Chat modes: Auto, Chat-only, Tools-only
  • Tool discovery and invocation
  • Real-time connection status

API Reference

MCPClient
client = MCPClient(
    endpoint="http://localhost:8000/mcp",
    transport="streamable-http",  # or "sse"
    timeout=30.0,
    http_client=None,  # optional httpx.AsyncClient
)

Methods:

MethodDescription
list_tools()List available tools from the MCP endpoint
call_tool(name, arguments={})Invoke a tool with parameters
invoke_tool(name, kwargs)Backward-compatible alias for call_tool()
check_connection()Check if the endpoint is reachable
get_endpoint_info()Get endpoint metadata
connect() / disconnect()Manual session lifecycle
ToolInvocationResult
result = await client.call_tool("add", arguments={"a": 1, "b": 2})
result.content             # Text content as string
result.error_code          # 0 for success, 1 for error
result.structured_content  # Structured output (dict), if available
result.raw_content         # Raw content blocks from the SDK
Error Handling
from mcp_playground import MCPClient, MCPConnectionError, MCPTimeoutError

try:
    async with MCPClient("http://localhost:8000/mcp") as client:
        tools = await client.list_tools()
except MCPConnectionError as e:
    print(f"Connection failed: {e}")
except MCPTimeoutError as e:
    print(f"Timed out: {e}")

Requirements

  • Python >= 3.10
  • mcp >= 1.26.0
  • httpx >= 0.28.0
  • pydantic >= 2.0.0

Optional (for LLM integration):

  • openai >= 2.28.0
  • anthropic >= 0.84.0
  • ollama >= 0.6.0

Development

pip install -e ".[dev]"
pytest                # run tests
black .               # format code
ruff check .          # lint

License

MIT

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.