hello-mcp
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v17View latest version
Hello MCP is a remix of OpenAI's hello-realtime demo that adds Model Context Protocol (MCP) support for server-side tool execution.
This demo showcases:
- WebRTC-based voice conversations with OpenAI's Realtime API
- MCP (Model Context Protocol) for secure server-side tool execution
- A demo
getFavoriteFood
tool to demonstrate MCP functionality - Toggle between standard and MCP-enabled modes
If you remix the app, you'll just need to pop in your own OPENAI_API_KEY
(from
platform.openai.com).
MCP enables server-side tool execution, keeping your business logic and API keys secure on the server rather than exposing them to the client.
Try asking questions like:
- "What's Thomas's favorite food?"
- "What does Brian like to eat?"
- "Tell me about Yana's favorite food"
The tool knows about: Thomas, Brian, Emil, Yana, Alex, Max, Justin, and Sam.
-
Standard WebRTC Flow:
- Browser connects to frontend
- Creates WebRTC offer
/rtc
endpoint handles SDP negotiation with OpenAI- Observer established to monitor session
-
MCP-Enhanced Flow (when enabled):
- Same WebRTC setup as above
- OpenAI discovers tools via MCP protocol (
/mcp
) - Tools execute server-side when invoked
- Results returned through MCP protocol
- Client triggers response generation after tool completion
GET /
- serves the WebRTC-based app with MCP togglePOST /rtc
- creates a new WebRTC-based Realtime API session (with optional?mcp=true
)POST /sip
- handles an incoming Realtime API SIP callPOST /observer
- internal endpoint to establish a Realtime API websocket for session controlPOST /mcp
- MCP protocol endpoint for tool discovery and executionGET /mcp/tools
- Debug endpoint to list available tools
├── frontend/
│ └── index.html # HTML/JS application for WebRTC with MCP support
├── main.tsx # Main entrypoint for the val.town app
└── routes/
|── mcp.ts # MCP protocol handler with getFavoriteFood tool
|── observer.ts # Server-side session control for SIP & WebRTC
|── rtc.ts # WebRTC session setup with MCP configuration
|── sip.ts # SIP webhook handling and session setup
└── utils.ts # Realtime API session configuration with MCP support
- Start the app - Click "Start" and allow microphone access
- Check MCP is enabled - Ensure "Use MCP Tools" checkbox is checked
- Ask about favorite foods - Try "What's Thomas's favorite food?"
- Watch the logs - You'll see MCP events including tool discovery and execution
- Try without MCP - Uncheck the box and restart to see the difference
The MCP implementation follows the JSON-RPC 2.0 specification:
{ "method": "initialize", "params": { "protocolVersion": "2025-06-18" } }
{ "method": "tools/list", "result": { "tools": [...] } }
{ "method": "tools/call", "params": { "name": "getFavoriteFood", "arguments": { "name": "Thomas" } } }