Flip-a-Coin MCP

Flip-a-Coin MCP

A simple MCP server that provides a fair coin flip tool, returning heads or tails.

Category
访问服务器

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 PORT environment 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:

  1. Connect to http://localhost:8787/mcp using Streamable HTTP.
  2. Open Tools.
  3. Select flip_coin.
  4. Click Run Tool.
  5. Confirm the result is heads or tails.

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:4040 is 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

  1. Open ChatGPT.
  2. Open Settings → Security and login.
  3. 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

  1. Open Settings → Plugins, or visit chatgpt.com/plugins.
  2. Select the plus button to create a developer-mode app.
  3. 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
  4. Select Create.
  5. Confirm ChatGPT discovers the flip_coin tool.

See OpenAI's current Connect from ChatGPT guide if the interface differs.

5. Test it in a conversation

  1. Start a new ChatGPT conversation.
  2. Click + → More near the message composer.
  3. Select Flip a Coin.
  4. 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.js defines the MCP tool and HTTP server.
  • package.json contains the runtime dependencies and npm scripts.

Troubleshooting

ChatGPT cannot connect

  • Confirm npm start is still running.
  • Confirm ngrok is still running.
  • Use the HTTPS forwarding URL, not localhost or 127.0.0.1:4040.
  • Ensure the URL ends with /mcp.
  • Open the forwarding URL without /mcp and 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

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选