Flip-a-Coin MCP
A simple MCP server that provides a fair coin flip tool, returning heads or tails.
README
Flip-a-Coin MCP
A small, open-source-friendly Model Context Protocol (MCP) server that gives compatible AI clients one tool: flip_coin.
The tool performs a fair virtual coin flip and returns either heads or tails. It can be tested locally with MCP Inspector or connected to ChatGPT as a developer-mode app.
What it provides
- A Streamable HTTP MCP endpoint at
/mcp - A health endpoint at
/ - A single zero-argument tool named
flip_coin - Human-readable text and structured JSON output
- Configurable port through the
PORTenvironment variable
Example tool response:
{
"content": [
{
"type": "text",
"text": "The coin landed on heads."
}
],
"structuredContent": {
"result": "heads"
}
}
Requirements
Before starting, install:
- Node.js 18 or newer
- npm, which is included with Node.js
- Optional: ngrok for connecting a local server to ChatGPT
Install
Clone or download this repository, then open a terminal in the project directory.
npm install
Start the server
npm start
The default MCP endpoint is:
http://localhost:8787/mcp
You should see:
Flip-a-Coin MCP listening at http://localhost:8787/mcp
To use a different port:
PORT=3000 npm start
Keep this terminal open while testing or using the server.
Verify the health endpoint
Open http://localhost:8787 in a browser or run:
curl http://localhost:8787/
Expected response:
Flip-a-Coin MCP server is running.
Test with MCP Inspector
Keep the server running and open a second terminal in the project directory:
npm run inspect
In MCP Inspector:
- Connect to
http://localhost:8787/mcpusing Streamable HTTP. - Open Tools.
- Select
flip_coin. - Click Run Tool.
- Confirm the result is
headsortails.
Connect it to ChatGPT
ChatGPT must be able to reach the MCP server over HTTPS. localhost and 127.0.0.1 are only available on your computer and cannot be entered as the ChatGPT MCP URL.
1. Start the MCP server
In the first terminal:
npm start
2. Create a public HTTPS tunnel
In a second terminal:
ngrok http 8787
ngrok will display a forwarding URL resembling:
https://example-subdomain.ngrok-free.app
The MCP URL is that forwarding URL followed by /mcp:
https://example-subdomain.ngrok-free.app/mcp
http://127.0.0.1:4040is ngrok's local inspection dashboard. It is not the URL to enter in ChatGPT.
You can verify the tunnel by opening the forwarding URL without /mcp in a browser. It should display the server health message.
3. Enable ChatGPT developer mode
- Open ChatGPT.
- Open Settings → Security and login.
- Turn on Developer mode.
If the option is unavailable in a managed workspace, ask the workspace administrator to enable developer mode.
4. Create the ChatGPT app
- Open Settings → Plugins, or visit chatgpt.com/plugins.
- Select the plus button to create a developer-mode app.
- Enter the following information:
- Name:
Flip a Coin - Description:
Flips a fair virtual coin when the user asks to flip or toss a coin. - MCP server URL: your complete ngrok URL ending in
/mcp - Authentication: none
- Name:
- Select Create.
- Confirm ChatGPT discovers the
flip_cointool.
See OpenAI's current Connect from ChatGPT guide if the interface differs.
5. Test it in a conversation
- Start a new ChatGPT conversation.
- Click + → More near the message composer.
- Select Flip a Coin.
- Try one of these prompts:
Flip a coin using the Flip a Coin app.
Toss a coin for me.
Choose between pizza and tacos. Heads is pizza and tails is tacos.
Both npm start and ngrok must remain running. Free ngrok URLs may change after ngrok restarts; if that happens, update the MCP URL in ChatGPT.
Test with curl
Initialize the MCP server:
curl -sS http://localhost:8787/mcp \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": {},
"clientInfo": {
"name": "manual-test",
"version": "1.0.0"
}
}
}'
List the available tools:
curl -sS http://localhost:8787/mcp \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
--data '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}'
Call flip_coin:
curl -sS http://localhost:8787/mcp \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
--data '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "flip_coin",
"arguments": {}
}
}'
Project structure
.
├── README.md
├── package-lock.json
├── package.json
└── server.js
server.jsdefines the MCP tool and HTTP server.package.jsoncontains the runtime dependencies and npm scripts.
Troubleshooting
ChatGPT cannot connect
- Confirm
npm startis still running. - Confirm ngrok is still running.
- Use the HTTPS forwarding URL, not
localhostor127.0.0.1:4040. - Ensure the URL ends with
/mcp. - Open the forwarding URL without
/mcpand confirm the health message appears. - Refresh the developer-mode app after changing tool metadata.
Port 8787 is already in use
Stop the process already using the port or choose another port:
PORT=3000 npm start
ngrok http 3000
The server exits on the first MCP request
Run npm install to ensure the locked dependency versions are installed, then restart the server. If it still exits, inspect the terminal running npm start for the complete error message.
MCP Inspector does not open
The first npm run inspect may download MCP Inspector through npx. Confirm the machine has internet access and try again.
Production considerations
The ngrok workflow is intended for development. For a persistent installation:
- Deploy the server to a host that supports a continuously running Node.js HTTP process.
- Use a stable HTTPS domain.
- Add request logging, rate limiting, monitoring, and graceful shutdown handling.
- Add authentication if the endpoint should not be public.
- Keep dependencies updated and test tool discovery after upgrades.
For private deployments, OpenAI also documents Secure MCP Tunnel, which lets supported OpenAI products reach a private MCP server without opening inbound firewall ports.
Contributing
Issues and pull requests are welcome. Please keep changes small, document user-visible behavior, and verify the server through MCP Inspector or the curl examples before submitting.
License
Add a LICENSE file before publishing the repository and update this section with the selected open-source license. MIT and Apache-2.0 are common choices for small developer tools.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。