diceMcp
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.
A minimal MCP (Model Context Protocol) server that provides dice rolling and coin flipping tools. Great as a starting point for building your own MCP servers.
| Tool | Description |
|---|---|
roll_dice | Roll 1-10 six-sided dice |
flip_coin | Flip a coin (heads/tails) |
This MCP server works with any MCP-compatible client:
- OpenAI Responses API - Add as an MCP tool
- Claude Desktop - Add to your MCP config
- MCP Chat - Add via the settings UI
const response = await openai.responses.create({
model: "gpt-4o-mini",
input: "Roll 3 dice for me",
tools: [{
type: "mcp",
server_label: "dice",
server_url: "https://your-val-url.web.val.run",
require_approval: "never",
}],
});
This val demonstrates the minimal structure for an HTTP MCP server:
- Handle CORS - Required for browser-based clients
- Implement
initialize- Return server info and capabilities - Implement
tools/list- Return available tools with JSON schemas - Implement
tools/call- Execute tools and return results - Handle notifications - Return 204 for
notifications/initialized
MCP uses JSON-RPC 2.0 over HTTP POST:
// Request { "jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {} } // Response { "jsonrpc": "2.0", "id": 1, "result": { "tools": [...] } }
Tools return content as an array of typed blocks:
return jsonRpc(id, {
content: [{ type: "text", text: "You rolled a 6!" }]
});
Fork this val to create your own MCP server with custom tools!