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.1.0.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.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_webrtc-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 33915c07a15ec53b6434e19ffe1928468f9beb0978f274e82b27d704b797380c
MD5 6fedd33c56e5b818943f44ab957f1d2f
BLAKE2b-256 083e825d886ad3d3b865064755d614fd4c5d1f69140dc41879a95f0aeaca300d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: mcp_webrtc-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9177b020c7f874d6a38b541dc8d59d2d2fd06bb54be00f6f8e16cd440b0a301
MD5 97d8b9d51fe3bbcaf293f37a65ba611c
BLAKE2b-256 baa9400ce55a4f886160f287d8327fc2ed2d9446da6fd25f499f4f6675c465ef

See more details on using hashes here.

Provenance

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