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.

Metadata

Release files for mcp-websocket-transport 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-websocket-transport 1.0.2
File Size Uploaded Provenance Actions
mcp_websocket_transport-1.0.2.tar.gz 10.6 kB With provenance Details for mcp_websocket_transport-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-websocket-transport 1.0.2
File Interpreter ABI Platform Actions
mcp_websocket_transport-1.0.2-py3-none-any.whl Python 3 none any Details for mcp_websocket_transport-1.0.2-py3-none-any.whl

Total release size: 19.0 kB

Release files / mcp_websocket_transport-1.0.2.tar.gz

Download URL mcp_websocket_transport-1.0.2.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1d8b6e3bed614ebeaceedb5266b0998dec0ab371a565cd33481214c3d90287f5
BLAKE2b-256 checksum
How to use checksums
446838b37ea54420d811f10a75308370c357eccb0e16754b39150d46b535ef62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / mcp_websocket_transport-1.0.2-py3-none-any.whl

Download URL mcp_websocket_transport-1.0.2-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c25587c8a40bbf2aa69314787770a881b8b2782d9f8d0897463d2ad9fd9336e
BLAKE2b-256 checksum
How to use checksums
9daf081b6c84bd8301ed9abad384902ef1b074f7a88009dbfa4464cb250ee182
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Security for mcp-websocket-transport 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mcp_websocket_transport-1.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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