Dice MCP Server

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.

Tools

ToolDescription
roll_diceRoll 1-10 six-sided dice
flip_coinFlip a coin (heads/tails)

Usage

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

Example with OpenAI

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", }], });

Building Your Own MCP Server

This val demonstrates the minimal structure for an HTTP MCP server:

  1. Handle CORS - Required for browser-based clients
  2. Implement initialize - Return server info and capabilities
  3. Implement tools/list - Return available tools with JSON schemas
  4. Implement tools/call - Execute tools and return results
  5. Handle notifications - Return 204 for notifications/initialized

MCP Protocol Basics

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": [...] } }

Tool Response Format

Tools return content as an array of typed blocks:

return jsonRpc(id, { content: [{ type: "text", text: "You rolled a 6!" }] });

Remix This

Fork this val to create your own MCP server with custom tools!