webrtc-mcp-server

webrtc-mcp-server

Peer-to-peer WebRTC communication for AI agents, connecting autonomous coding agents over low-latency WebRTC DataChannels with room-based signaling, video stream bridging, and multi-agent coordination — all exposed as MCP tools.

Category
访问服务器

README

WebRTC MCP Server

Peer-to-peer WebRTC communication for AI agents. Connects autonomous coding agents over low-latency WebRTC DataChannels with room-based signaling, video stream bridging, and multi-agent coordination — all exposed as MCP tools.

npm npm downloads TypeScript Protocol License: MIT


TL;DR

npm install && npm run build

# As MCP server (stdio)
node dist/index.js

# As WebSocket signaling server (for external peers)
WEBRTC_SIGNALING_MODE=ws WEBRTC_WS_PORT=8765 node dist/index.js
Feature Detail
Protocol MCP v2025-03-26 (over stdio), WebSocket signaling
Tools 16 MCP tools — peers, rooms, streams, signaling, health
Concurrency Worker Thread pool (default 8, max 16)
Latency 0.82ms avg signaling RTT (measured)
Sources RTSP, HLS, RTMP, WebRTC (auto-detect)
Tests 14/14 passing

What It Does

Multi-Agent Communication

Connect AI agents (Claude Code, OpenCode, Cursor, and any MCP client) over WebRTC DataChannels. Each agent becomes a peer that can:

  • Join named rooms for group communication
  • Send structured messages (JSON) with ACK
  • Broadcast to all peers in a room
  • Relay SDP/ICE for WebRTC handshake

Video Streams

Bridge RTSP/HLS/RTMP video streams to WebRTC for real-time frame access:

  • webrtc_connect_stream(url) → creates RTCPeerConnection + offer SDP
  • webrtc_frame_get(stream_id) → returns latest frame as base64 JPEG
  • webrtc_stream_status(stream_id) → health, FPS, throughput metrics
  • FFmpeg-backed decoding with ring-buffer frame cache

Room-Based Signaling

WebSocket server (ws://host:port) for external peers:

  • join/leave/list_peers — room membership
  • signal — SDP/ICE relay between peers
  • broadcast — fan-out messages to all room members
  • ping/pong — health check

Quick Start

As a standalone server

# stdio mode (MCP transport)
WEBRTC_SIGNALING_MODE=stdio node dist/index.js

# WebSocket signaling mode (for external peers)
WEBRTC_SIGNALING_MODE=ws WEBRTC_WS_PORT=8765 node dist/index.js

# Both modes simultaneously
WEBRTC_SIGNALING_MODE=both node dist/index.js

As an MCP server (Claude Desktop / Cursor / any MCP client)

{
  "mcpServers": {
    "webrtc": {
      "command": "node",
      "args": ["/path/to/dist/index.js"],
      "env": {
        "WEBRTC_SIGNALING_MODE": "stdio"
      }
    }
  }
}

External peer via WebSocket

// Node.js client
const ws = new WebSocket('ws://127.0.0.1:8765');
ws.on('open', () => {
  ws.send(JSON.stringify({
    type: 'join',
    peerId: 'peer-a',
    room: 'my-room'
  }));
});

MCP Tools

Peer Communication (6 tools)

Tool Description
webrtc_connect Create RTCPeerConnection + DataChannel with a peer
webrtc_disconnect Close connection and release resources
webrtc_send Send structured message via DataChannel
webrtc_broadcast Broadcast to all peers in a room
webrtc_list_peers List all connected peers
webrtc_peer_status Detailed status of a specific peer

Rooms (4 tools)

Tool Description
webrtc_create_room Create a new signaling room
webrtc_join_room Join a peer to a room
webrtc_leave_room Leave a room
webrtc_signal_relay Relay SDP/ICE candidates between peers

Video Streams (5 tools)

Tool Description
webrtc_connect_stream Connect RTSP/HLS/RTMP source → WebRTC offer
webrtc_frame_get Get latest frame as base64 (cached, no re-encode)
webrtc_list_streams List all active streams with health metrics
webrtc_stream_status Detailed streaming metrics (FPS, throughput)
webrtc_disconnect_stream Close a video stream

Health (1 tool)

Tool Description
webrtc_health Overall server health (peers, rooms, workers, uptime)

Configuration

All config via environment variables or config.yaml:

Variable Default Description
WEBRTC_SIGNALING_MODE stdio stdio | ws | both
WEBRTC_MAX_WORKERS 8 Max concurrent worker threads (≤16)
WEBRTC_FRAME_CACHE_SIZE 5 Frames cached per stream (ring buffer)
WEBRTC_MAX_FRAME_BYTES 500000 Max JPEG payload (~480KB @ 1920×1080)
WEBRTC_CONNECTION_TIMEOUT 30 Connection timeout in seconds
WEBRTC_WS_PORT 8765 WebSocket signaling port
WEBRTC_WS_HOST 127.0.0.1 WebSocket bind address
WEBRTC_LOG_LEVEL warn debug | info | warn | error
WEBRTC_STUN_URL stun:stun.l.google.com:19302 STUN server
WEBRTC_ALLOWED_URLS (auto) Comma-separated URL allowlist

See config.yaml for the full default configuration with TURN, rate limiting, and ICE restart settings.


Multi-Agent Workflow

1. Agent A:   webrtc_create_room("team-sync")
2. Agent B:   {type:"join", peerId:"agent-b", room:"team-sync"}  ← WebSocket
3. Agent A:   webrtc_connect(peerId="agent-b")  → RTCPeerConnection + DataChannel

4. A → B:     webrtc_send(peerId="agent-b", data={"task":"review","file":"src/index.ts"})
5. B → A:     webrtc_send(peerId="agent-a", data={"result":"✅ no issues"})

6. Broadcast: webrtc_broadcast(data={"type":"status","msg":"deploying"})

Video Stream Workflow

1. webrtc_connect_stream(url="rtsp://camera.local:554/stream1")
   → {stream_id: "cam-123", offer_sdp: "...", ice_servers: [...]}

2. webrtc_frame_get(stream_id="cam-123")
   → {frame: "base64...", timestamp: 1753785600000, resolution: {width:1920, height:1080}}

3. vision_analyze(image="data:image/jpeg;base64,...", question="¿Hay personas?")
   → "Sí, 2 personas detectadas"

Frames are cached in a thread-safe ring buffer — repeated frame_get calls return the same buffer without re-encoding.


Architecture

┌─────────────────────────────────────────────────────────┐
│  MCP CLIENT (Claude Desktop, Cursor, any MCP host)     │
│  MCP stdio transport: node dist/index.js                │
├─────────────────────────────────────────────────────────┤
│  MCP Protocol Handler (v2025-03-26)                    │
│  → tools/list, tools/call → dispatch                     │
├─────────────────────────────────────────────────────────┤
│  WebSocket Signaling Server (ws://127.0.0.1:8765)       │
│  → join/leave/list_peers/ping/broadcast/signal          │
├─────────────────────────────────────────────────────────┤
│  Worker Thread Pool (8 concurrent, round-robin)          │
│  ├─ Worker 1: RTCPeerConnection + DataChannel            │
│  ├─ Worker 2: RTSP/FFmpeg → WebRTC bridge                │
│  └─ Worker N: isolated per peer/stream                    │
├─────────────────────────────────────────────────────────┤
│  FFmpeg Bridge                                           │
│  RTSP/HLS/RTMP → raw frames → JPEG (via sharp)            │
│  FrameCache: thread-safe ring buffer (5 frames)            │
└─────────────────────────────────────────────────────────┘

Development

npm install        # install dependencies
npm run build      # TypeScript → dist/
npm run dev        # watch mode (tsx)
npm test           # 14 tests (vitest)
npm run typecheck  # tsc --noEmit
npm run lint       # eslint

Tests

Test Files  2 passed (2)
     Tests  14 passed (14)
File Tests
test/room.test.ts 9 tests — room join/leave, peer management, broadcast
test/signaling.test.ts 5 tests — SDP/ICE routing, health checks

License

MIT — see LICENSE.


WebRTC is the industry standard for real-time P2P communication (used by Zoom, Google Meet, Discord). This server brings that capability to the MCP ecosystem for multi-agent collaboration.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选