🐍 Python mcp-websocket-transport
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d8b6e3bed614ebeaceedb5266b0998dec0ab371a565cd33481214c3d90287f5
|
|
| MD5 |
c5b6e2a92d460a7fcc966008ad655a44
|
|
| BLAKE2b-256 |
446838b37ea54420d811f10a75308370c357eccb0e16754b39150d46b535ef62
|
Provenance
The following attestation bundles were made for mcp_websocket_transport-1.0.2.tar.gz:
Publisher:
publish.yml on serguei9090/mcp-websocket-transport
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_websocket_transport-1.0.2.tar.gz -
Subject digest:
1d8b6e3bed614ebeaceedb5266b0998dec0ab371a565cd33481214c3d90287f5 - Sigstore transparency entry: 2608109594
- Sigstore integration time:
-
Permalink:
serguei9090/mcp-websocket-transport@edc3fdf84f19c28b8a578bd371208f99580e8e1a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/serguei9090
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edc3fdf84f19c28b8a578bd371208f99580e8e1a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mcp_websocket_transport-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mcp_websocket_transport-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c25587c8a40bbf2aa69314787770a881b8b2782d9f8d0897463d2ad9fd9336e
|
|
| MD5 |
fdbd34293bb6d2b45603a16741e6dca5
|
|
| BLAKE2b-256 |
9daf081b6c84bd8301ed9abad384902ef1b074f7a88009dbfa4464cb250ee182
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_websocket_transport-1.0.2-py3-none-any.whl -
Subject digest:
4c25587c8a40bbf2aa69314787770a881b8b2782d9f8d0897463d2ad9fd9336e - Sigstore transparency entry: 2608109895
- Sigstore integration time:
-
Permalink:
serguei9090/mcp-websocket-transport@edc3fdf84f19c28b8a578bd371208f99580e8e1a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/serguei9090
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@edc3fdf84f19c28b8a578bd371208f99580e8e1a -
Trigger Event:
workflow_dispatch
-
Statement type: