Tic-Tac-Toe MCP Server

Tic-Tac-Toe MCP Server

Enables two Claude Code sessions to play tic-tac-toe against each other by providing tools to join a game, view the board, and make moves, with turn notifications pushed over channels.

Category
访问服务器

README

tic-tac-toe over an MCP channel

Two Claude Code sessions play tic-tac-toe against each other, coordinating through a shared MCP server — no human relaying moves. Each session is woken on its turn by a Claude Code channel push, plays, and goes idle until the next push.

        ┌───────────────── the referee (one process, owns the game) ─────────────────┐
        │  POST /join · POST /move · GET /state · GET /subscribe · GET /spectate      │
        └──────────▲──────────────────────────────────────────────────▲──────────────┘
                   │ HTTP + SSE                                        │ HTTP + SSE
            channel adapter (X)                                channel adapter (O)
        stdio MCP server spawned by                        stdio MCP server spawned by
             Claude session X                                   Claude session O
        tools: join_game/view_board/make_move             (same) — pushes "your turn" in

Open http://127.0.0.1:8787/ to watch it live, or read the built-in Docs tab on that page for the architecture and turn-flow diagrams.

Project layout

Organised by feature, not by layer: everything about the game lives in game/, everything about the channel in channel/, every prompt in prompts/.

src/
  game/
    engine.ts             pure rules — win, draw, legal moves (unit-tested)
    game.ts               authoritative state + transitions, announces events
    serialize.ts          model → wire payloads (public + spectator shapes)
    routes.ts             the Express router: join / move / state / reset
    streams.ts            every open SSE stream; routes events to the right player
  prompts/                what the agent is told, as Jinja (Nunjucks) templates
    channel-instructions.j2   goes into the session's system prompt
    your-turn.j2 · game-over.j2   the pushed channel notifications
    seed.j2               paste this into a session to start it
    render.ts             the tiny loader
  server.ts               Express app: routes, templates, static assets, listen
  templates/              EJS page, split into partials
    index.ejs             the shell — head + includes
    partials/
      header.ejs          title + connection indicator
      tabs.ejs            Board / Docs switch
      panel-board.ejs     the live game
      panel-docs.ejs      the documentation sections
      diagram-architecture.ejs   inline SVG
      diagram-sequence.ejs       inline SVG
  channel/
    index.ts              the MCP channel: capability, tools, stdio
    refereeClient.ts      HTTP + SSE link to the referee (self-healing)
    tools.ts              join_game / view_board / make_move
    notifications.ts      referee event → channel notification

public/
  styles/                 tokens · base · board · docs
  scripts/
    model.js              MODEL: game state + which seat this browser holds
    view.js               VIEW: the only module touching the DOM
    controller.js         CONTROLLER: intent in, model updates out
    api.js                fetch + EventSource, nothing else
    main.js               entry point

game.ts knows the rules but no transport — it announces events, and streams.ts decides how to deliver them. Prompts are content, not code: edit a .j2 file to change what the agent is told, without touching TypeScript.

Requirements

  • Node 20+ and pnpm (pnpm install once).
  • Channels enabled. Channels are a Claude Code research preview.
    • Pro / Max personal account: enabled by default. ✅ use this.
    • Team / Enterprise org (e.g. a work account): blocked until an Owner enables channelsEnabled — you'll get blocked by org policy. Log in with a personal Pro/Max account instead, or have the Owner enable it.

Run it

cd ~/dev/tic-tac-toe
pnpm install          # once

# 1. start the referee (leave running)
pnpm server           # listens on http://127.0.0.1:8787

Open the live board in a browser: http://127.0.0.1:8787/ — it shows each session joining, whose turn it is, every move, the winning line, and a live event feed, all pushed over SSE. Leave it open while the match runs.

Then open two more terminals, both in this directory. In each:

claude --dangerously-load-development-channels server:tictactoe
  • Accept the dev-channels warning ("I am using this for local development").
  • Accept "New MCP server found in this project: tictactoe" → Use this MCP server.
  • Paste the contents of src/prompts/seed.j2 as your first message.
  • The session calls join_game and goes idle. Do the same in the other terminal.

The first session to call join_game is X, the second is O. As soon as both have joined, the referee wakes X — and from there the two sessions ping-pong on their own until someone wins or it's a draw. You just watch.

A dim line under each session's banner confirms the channel is live: Channels (experimental) messages from server:tictactoe inject directly in this session.

Play against Claude yourself (human vs AI)

You can take one seat. Start the server, open http://127.0.0.1:8787/, and click 🙋 Join as human — you get whichever mark is free. Launch one Claude session (claude --dangerously-load-development-channels server:tictactoe, then the seed) to fill the other seat. When it's your turn the board highlights and you click an empty cell; your move flips the turn and the Claude opponent is woken by its channel to reply.

Only one human seat is allowed — the point of the demo is the Claude-channel side, so the second player is always a Claude session (a second human join is rejected).

Try it without Claude (sanity check)

pnpm test             # engine unit tests
pnpm server           # then, in another shell, drive it with curl:
curl -s -XPOST localhost:8787/join -d '{}'   # -> {"playerId":...,"mark":"X",...}
curl -s -XPOST localhost:8787/join -d '{}'   # -> mark O; X is now woken
curl -s localhost:8787/state

Notes

  • One game at a time. POST /reset (or restart the server) starts a fresh match; a new pair joining after a finished game also resets automatically.
  • Everything binds to 127.0.0.1 only. Change the port with TTT_PORT=9000 pnpm server (the channel reads the same TTT_PORT, or set TTT_SERVER=http://host:port).
  • This is the same pattern as the rounders channel adapter, in miniature: a shared event source + a per-session stdio channel that wakes an idle session.
  • pnpm format / pnpm format:check run Prettier over the whole repo.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选