ttt_get_state
Retrieve the current Tic-Tac-Toe game state, including board, status, player names, and legal moves.
Instructions
Get the current Tic-Tac-Toe board, status, player names, and legal moves.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/games/tictactoe.ts:142-149 (registration)Registration of the 'ttt_get_state' tool via server.tool(), with description and empty schema.
server.tool( "ttt_get_state", "Get the current Tic-Tac-Toe board, status, player names, and legal moves.", {}, async () => ({ content: [{ type: "text", text: renderState(game) }], }) ); - src/games/tictactoe.ts:146-148 (handler)Handler function that returns the rendered state of the current game by calling renderState(game).
async () => ({ content: [{ type: "text", text: renderState(game) }], }) - src/games/tictactoe.ts:74-110 (helper)The renderState() helper function that formats the board, status, player names, and legal moves into a text response.
function renderState(g: GameState): string { const cell = (c: Cell) => (c === null ? " " : c); const lines = [ ` col 0 col 1 col 2`, `row 0 ${cell(g.board[0][0])} | ${cell(g.board[0][1])} | ${cell(g.board[0][2])}`, ` -----+-------+-----`, `row 1 ${cell(g.board[1][0])} | ${cell(g.board[1][1])} | ${cell(g.board[1][2])}`, ` -----+-------+-----`, `row 2 ${cell(g.board[2][0])} | ${cell(g.board[2][1])} | ${cell(g.board[2][2])}`, ``, `Players: X = ${g.playerX} | O = ${g.playerO}`, `Status: ${g.status}`, ]; if (g.status === "in_progress") { const currentName = g.currentPlayer === "X" ? g.playerX : g.playerO; lines.push(`Next move: ${g.currentPlayer} (${currentName})`); const legal = getLegalMoves(g.board) .map(([r, c]) => `(row ${r}, col ${c})`) .join(" "); lines.push(`Legal moves: ${legal}`); } else if (g.status === "x_wins" || g.status === "o_wins") { const winnerName = g.status === "x_wins" ? g.playerX : g.playerO; const winnerMark = g.status === "x_wins" ? "X" : "O"; lines.push(`Winner: ${winnerMark} (${winnerName})`); if (g.winningLine) { const wl = g.winningLine.map(([r, c]) => `(row ${r}, col ${c})`).join(", "); lines.push(`Winning line: ${wl}`); } } else if (g.status === "draw") { lines.push("Result: It's a draw!"); } lines.push(`\n[Show the board above verbatim to the human player — they need the row/col labels to know where to move.]`); return lines.join("\n"); } - src/index.ts:16-16 (registration)Top-level registration call that passes the server to registerTicTacToeTools(), which registers ttt_get_state.
registerTicTacToeTools(server);