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.6.tar.gz (6.2 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.6-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_webrtc-0.0.6.tar.gz
  • Upload date:
  • Size: 6.2 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.6.tar.gz
Algorithm Hash digest
SHA256 c0369c5e23e862a1314211b8f8115a49f8d8265dccfc2a0e260795b566b74716
MD5 e6f850b37909b4945f93017cdf81eccc
BLAKE2b-256 0f57c0de57099a3fb9206255fe760974e55429c0a6d41fc6e3c38d06689c00b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_webrtc-0.0.6.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.6-py3-none-any.whl.

File metadata

  • Download URL: mcp_webrtc-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 3.6 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a112321cc41b7ef845b00f66fbdf05546c56bc57a8d585c40eb3766728e58cee
MD5 acf05d1c1b95310d2686acf91251ce74
BLAKE2b-256 635e95c38c089b0946179a93135e7666319d2350bba626061faca402ba8b611e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_webrtc-0.0.6-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