Skip to main content

🐍 Python mcp-websocket-transport

PyPI Version Python Support License: MIT

Full-duplex WebSocket Transport for the Model Context Protocol (MCP) in Python. Built on AnyIO and compatible with FastAPI, Starlette, and standalone websockets.


📦 Installation

# Using uv (recommended)
uv add mcp-websocket-transport

# With pip
pip install mcp-websocket-transport

# With all extras (FastAPI, uvicorn, websockets, mcp CLI)
pip install "mcp-websocket-transport[all]"

🛠️ Quickstart

1. FastMCP Server with WebSocket (examples/fastmcp_server.py)

import asyncio
import websockets
from mcp.server.fastmcp import FastMCP
from mcp_websocket_transport import serve_websocket

mcp = FastMCP("calculator-server")

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

@mcp.tool()
def get_stock(symbol: str) -> dict:
    """Fetches mock stock price."""
    return {"symbol": symbol.upper(), "price": 225.50}

async def main():
    async def handler(websocket):
        await serve_websocket(mcp._mcp_server, websocket)

    print("🚀 MCP WebSocket Server running on ws://0.0.0.0:8765")
    async with websockets.serve(handler, "0.0.0.0", 8765):
        await asyncio.Future()

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

2. Python Client (examples/mcp_tool_client.py)

import asyncio
from mcp.client.session import ClientSession
from mcp_websocket_transport import WebSocketClientTransport

async def main():
    async with WebSocketClientTransport("ws://localhost:8765") as (read_stream, write_stream):
        async with ClientSession(read_stream, write_stream) as session:
            await session.initialize()
            
            # List available tools
            tools = await session.list_tools()
            print("Tools:", [t.name for t in tools.tools])
            
            # Call tool
            result = await session.call_tool("add", {"a": 15, "b": 27})
            print("Result:", result.content[0].text)

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

🌉 Desktop Host Bridge (mcp-ws-bridge)

To connect Claude Desktop, LM Studio, Cursor, or Antigravity to a running WebSocket server:

{
  "mcpServers": {
    "my-websocket-tools": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "path/to/mcp-websocket/python",
        "python",
        "-m",
        "mcp_websocket_transport.bridge",
        "--url",
        "ws://localhost:8767"
      ]
    }
  }
}

🧪 Testing

uv run --all-extras pytest -v

📄 License

MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_websocket_transport-1.0.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_websocket_transport-1.0.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_websocket_transport-1.0.2.tar.gz.

File metadata

  • Download URL: mcp_websocket_transport-1.0.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mcp_websocket_transport-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1d8b6e3bed614ebeaceedb5266b0998dec0ab371a565cd33481214c3d90287f5
MD5 c5b6e2a92d460a7fcc966008ad655a44
BLAKE2b-256 446838b37ea54420d811f10a75308370c357eccb0e16754b39150d46b535ef62

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_websocket_transport-1.0.2.tar.gz:

Publisher: publish.yml on serguei9090/mcp-websocket-transport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_websocket_transport-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_websocket_transport-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c25587c8a40bbf2aa69314787770a881b8b2782d9f8d0897463d2ad9fd9336e
MD5 fdbd34293bb6d2b45603a16741e6dca5
BLAKE2b-256 9daf081b6c84bd8301ed9abad384902ef1b074f7a88009dbfa4464cb250ee182

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_websocket_transport-1.0.2-py3-none-any.whl:

Publisher: publish.yml on serguei9090/mcp-websocket-transport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page