Skip to main content

WebRTC Transport for Model Context Protocol

Project description

WebRTC Transport for Model Context Protocol

The Model Context Protocol (MCP) is an open standard for connecting AI applications to external systems, such as tools and data sources. It defines several transport mechanisms for client-server communication, including STDIO (over standard input/output) and Streamable HTTP (for web-based streaming).

However, there are scenarios—such as in browser environments or firewalled networks—where neither STDIO nor Streamable HTTP can effectively connect an MCP client to an MCP server. In these cases, WebRTC provides a peer-to-peer alternative, leveraging real-time communication capabilities, provided a signaling connection (e.g., via WebSockets or another channel) is established between the parties.

This repository implements a WebRTC-based transport layer compatible with the MCP specification, enabling seamless integration in constrained networking setups.

Installation

pip install mcp-webrtc

Usage

Server

    from mcp_webrtc import webrtc_server_transport
    from aiortc.contrib.signaling import TcpSocketSignaling
    from mcp.server.lowlevel import Server
    from mcp.types import Tool

    app = Server("mcp-greeter")

    @app.list_tools()
    async def list_tools() -> list[Tool]:
        return [
            Tool(
                name="greet",
                description="Greets the caller",
                inputSchema={
                    "type": "object",
                    "required": [],
                    "properties": {},
                },
            )
        ]

    async with webrtc_server_transport(TcpSocketSignaling("localhost", 8000)) as (read, write):
        await app.run(
            read, write, app.create_initialization_options()
        )

Client

    from mcp import ClientSession
    from mcp_webrtc import webrtc_client_transport
    from aiortc.contrib.signaling import TcpSocketSignaling

    async with (
        webrtc_client_transport(TcpSocketSignaling("localhost", 8000)) as (
            read,
            write,
        ),
        ClientSession(read, write) as session,
    ):
        await session.initialize()
        result = await session.list_tools()
        print(result.tools)

Project details


Download files

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

Source Distribution

mcp_webrtc-0.0.7.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

mcp_webrtc-0.0.7-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file mcp_webrtc-0.0.7.tar.gz.

File metadata

  • Download URL: mcp_webrtc-0.0.7.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_webrtc-0.0.7.tar.gz
Algorithm Hash digest
SHA256 5c4fb64b247ff21c43aee6c21e4b22bafd3e4d8e14d35c9b5fdd4bcff4ea7b0b
MD5 883d7029878b370d8e6a21cd0ead229c
BLAKE2b-256 8489f991959a466ce5eaba11f4c54cd4c268a093e27e043f1abbf64e82507442

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_webrtc-0.0.7.tar.gz:

Publisher: release.yml on pilartomas/mcp-webrtc

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_webrtc-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: mcp_webrtc-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_webrtc-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3f0dda87f9453f9873444828f0c8484e8dc88bf134d052d74c96a4a4deb58e
MD5 ddbce21270eec89efa8971ecfc4e5579
BLAKE2b-256 26676fba63fa1c6f3a94731e58d8df2f40465de287c97b76313dafd1d0fd3f9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_webrtc-0.0.7-py3-none-any.whl:

Publisher: release.yml on pilartomas/mcp-webrtc

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page