Client Overview

Interact programmatically with any MCP‑compatible server: local, remote, or in‑memory - using the fully‑async Client class shipped with Hyperia Protocol.

Introduced in v2.0 · design‑overhauled in v2.2 for richer streaming and multi‑server support.


1 Architecture

flowchart LR
    subgraph App
        direction TB
        A[Your Python Code] -->|await| C(Client)
    end
    C --> T[Transport]
    T -->|wire| S(Server)
  • Client – constructs MCP requests (tools/call, resources/read…), tracks sessions, aggregates notifications.

  • Transport – actual pipe (STDIO process, HTTP/2 stream, in‑mem RPC,…).

Separation of concerns means you can swap transports without touching business logic.


2 Transport Inference Cheatsheet

Input to Client( …)

Detected Transport

Typical Use‑Case

Hyperia() instance

InMemoryTransport

Unit tests, plugins

Path *.py

PythonStdioTransport

Spawn Python script

Path *.js

NodeStdioTransport

Node servers

http(s):// URL

StreamableHttpTransport

Cloud functions, micro‑services

MCPConfig dict/file

CompositeTransport

Multi‑server routing

Pre‑built Transport

As‑is

Full control (headers, env)

Tip – instantiate transports directly when you need custom TLS certs, auth headers, or env vars.


3 Connecting to Many Servers (Composite Clients)

A single MCPConfig can declare multiple backends which the client auto‑mounts with name prefixes:

  • Tools → weather_get_forecast, billing_create_invoice

  • Resources → weather://weather/icons/snow, resource://billing/plans/list

No additional routing code required—client picks server from the prefix.


4 Lifecycle ⇢ async with

  • __aenter__ – establishes transport, negotiates roots, sets heart‑beats.

  • __aexit__ – gracefully closes session, kills child proc if STDIO.

You can reuse the same client object; reconnects automatically between context blocks.


5 High‑Level "Happy‑Path" API

Tools

Add timeout= or progress_handler= per call.

Resources

Prompts

Ping / Health‑Check


6 Raw Protocol Access

Every helper has an *_mcp twin that returns exact spec objects—future proof for breaking changes:


7 Progress, Logs, Roots & Sampling

Attach handlers globally or per‑call:

Handlers available:

  • RootsHandler / RootsList – reacts to dynamic root updates.

  • LogHandler – real‑time ctx.info() / ctx.error() streaming.

  • ProgressHandler – percentage updates.

  • SamplingHandler – (roadmap) client‑side LLM callbacks.


8 Timeout Strategy

  • GlobalClient(timeout=5)

  • Per‑request — overrides via timeout= param.

  • HTTP chooses the lower value; SSE honours per‑call value first.


9 Error Taxonomy

Exception
Trigger

ClientError

Server threw ToolError / ResourceError

ConnectionError

Transport connection failed

TimeoutError

Hard timeout hit

Inspect raw result for partial data:


10 Quick‑Ref Code Snippet

Last updated