A simple MCP (Model Context Protocol) server built with Next.js and TypeScript and mcp-handler that exposes multiple interactive tools via a standardized JSON-RPC API. This project demonstrates how to build, expose, and call micro-tools that can be connected to ChatGPT or any LLM supporting MCP.
Currently, the server includes the following tools:
- Roll Dice – Roll an N-sided die.
- Say Hello – Returns a greeting message.
- Add Numbers – Adds two numbers.
- Random Number – Generates a random number between a given min and max.
- Random Quote – Returns a motivational quote.
- Emoji Reaction – Responds with a random emoji.
- Color Palette – Generates a random color palette.
- Horoscope – Returns a fun horoscope for a zodiac sign.
git clone https://github.com/sattarrasouli/MCP-Next.js.git
# get to the directory
cd MCP-Next.jsnpm install
npm run dev
http://localhost:3000/api/mcp
http://localhost:3000
Each MCP tool can be called using JSON-RPC 2.0 format.
Use either Postman or curl to send requests.
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "tool_name",
"arguments": {}
}
}{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "roll_dice",
"arguments": { "sides": 6 }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": { "name": "roll_dice", "arguments": { "sides": 6 } }
}'{
"jsonrpc": "2.0",
"id": "2",
"method": "tools/call",
"params": {
"name": "say_hello",
"arguments": { "name": "Sattar" }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "2",
"method": "tools/call",
"params": { "name": "say_hello", "arguments": { "name": "Sattar" } }
}'{
"jsonrpc": "2.0",
"id": "3",
"method": "tools/call",
"params": {
"name": "add_numbers",
"arguments": { "a": 10, "b": 15 }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "3",
"method": "tools/call",
"params": { "name": "add_numbers", "arguments": { "a": 10, "b": 15 } }
}'{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": {
"name": "random_number",
"arguments": { "min": 5, "max": 15 }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": { "name": "random_number", "arguments": { "min": 5, "max": 15 } }
}'{
"jsonrpc": "2.0",
"id": "5",
"method": "tools/call",
"params": { "name": "random_quote", "arguments": {} }
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": { "name": "random_quote", "arguments": {} }
}'{
"jsonrpc": "2.0",
"id": "6",
"method": "tools/call",
"params": { "name": "emoji_reaction", "arguments": {} }
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": { "name": "emoji_reaction", "arguments": {} }
}'{
"jsonrpc": "2.0",
"id": "7",
"method": "tools/call",
"params": {
"name": "color_palette",
"arguments": { "count": 5 }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": { "name": "color_palette", "arguments": { "count": 5 } }
}'{
"jsonrpc": "2.0",
"id": "8",
"method": "tools/call",
"params": {
"name": "horoscope",
"arguments": { "sign": "Leo" }
}
}curl -X POST http://localhost:3000/api/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json,text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": { "name": "horoscope", "arguments": { "sign": "Leo" } }
}'{
"jsonrpc": "2.0",
"id": "1",
"result": {
"content": [{ "type": "text", "text": "🎲 You rolled a 5!" }]
}
}