Skip to main content
Glama

ttt_get_legal_moves

Retrieve all empty squares on the tic-tac-toe board as (row, col) pairs to identify legal moves when needed separately.

Instructions

Returns all empty squares as (row, col) pairs. Legal moves are already included in every ttt_new_game/ttt_make_move response — only call this standalone if you need them in isolation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration and handler for the 'ttt_get_legal_moves' tool. Registers the tool with an empty schema (no params), returns all empty squares as (row, col) pairs by calling getLegalMoves().
    server.tool(
      "ttt_get_legal_moves",
      "Returns all empty squares as (row, col) pairs. Legal moves are already included in every ttt_new_game/ttt_make_move response — only call this standalone if you need them in isolation.",
      {},
      async () => {
        if (game.status !== "in_progress") {
          return {
            content: [{ type: "text", text: `Game is over (${game.status}). No legal moves.` }],
          };
        }
        const moves = getLegalMoves(game.board);
        const text =
          `Legal moves (${moves.length}): ` +
          moves.map(([r, c]) => `(row ${r}, col ${c})`).join("  ");
        return { content: [{ type: "text", text }] };
      }
    );
  • Helper function getLegalMoves that iterates the 3x3 board and returns all empty cell coordinates as [row, col] pairs.
    function getLegalMoves(board: Board): [number, number][] {
      const moves: [number, number][] = [];
      for (let r = 0; r < 3; r++) {
        for (let c = 0; c < 3; c++) {
          if (board[r][c] === null) moves.push([r, c]);
        }
      }
      return moves;
    }
  • The registerTicTacToeTools function registers all tic-tac-toe tools (ttt_new_game, ttt_get_state, ttt_make_move, ttt_get_legal_moves) with the MCP server. This is the entry point for tool registration.
    export function registerTicTacToeTools(server: McpServer): void {
      server.tool(
        "ttt_new_game",
        "Start a fresh Tic-Tac-Toe game. X always moves first. Optionally name the players so roles are explicit in every response.",
        {
          player_x_name: z
            .string()
            .optional()
            .default("X")
            .describe("Name for the X player (e.g. 'Claude', 'Human'). Defaults to 'X'."),
          player_o_name: z
            .string()
            .optional()
            .default("O")
            .describe("Name for the O player (e.g. 'Human', 'Claude'). Defaults to 'O'."),
        },
        async ({ player_x_name, player_o_name }) => ({
          content: [
            {
              type: "text",
              text: ((): string => {
                game = newGameState(player_x_name ?? "X", player_o_name ?? "O");
                return `New Tic-Tac-Toe game started.\n\n${renderState(game)}`;
              })(),
            },
          ],
        })
      );
    
      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) }],
        })
      );
    
      server.tool(
        "ttt_make_move",
        "Place the current player's mark at (row, col). Rows and columns are 0–2; top-left is row 0, col 0. The server alternates turns automatically. Returns updated board, status, and legal moves in one response.",
        {
          row: z.number().int().min(0).max(2).describe("Row index: 0 = top row, 1 = middle row, 2 = bottom row"),
          col: z.number().int().min(0).max(2).describe("Column index: 0 = left col, 1 = middle col, 2 = right col"),
        },
        async ({ row, col }) => {
          if (game.status !== "in_progress") {
            return {
              content: [{ type: "text", text: `Game is already over (${game.status}). Call ttt_new_game to play again.` }],
              isError: true,
            };
          }
    
          if (game.board[row][col] !== null) {
            const occupiedBy = game.board[row][col] as "X" | "O";
            const occupiedByName = occupiedBy === "X" ? game.playerX : game.playerO;
            return {
              content: [
                {
                  type: "text",
                  text: [
                    `Error: square_occupied`,
                    `(row ${row}, col ${col}) is already taken by ${occupiedBy} (${occupiedByName}).`,
                    ``,
                    renderState(game),
                  ].join("\n"),
                },
              ],
              isError: true,
            };
          }
    
          const placed = game.currentPlayer;
          const placedName = placed === "X" ? game.playerX : game.playerO;
          game.board[row][col] = placed;
          game.moveCount++;
    
          const result = checkWinner(game.board);
          if (result) {
            game.status = result.winner === "X" ? "x_wins" : "o_wins";
            game.winningLine = result.line;
          } else if (game.moveCount === 9) {
            game.status = "draw";
          } else {
            game.currentPlayer = placed === "X" ? "O" : "X";
          }
    
          return {
            content: [
              {
                type: "text",
                text: `${placedName} (${placed}) placed at row ${row}, col ${col}.\n\n${renderState(game)}`,
              },
            ],
          };
        }
      );
    
      server.tool(
        "ttt_get_legal_moves",
        "Returns all empty squares as (row, col) pairs. Legal moves are already included in every ttt_new_game/ttt_make_move response — only call this standalone if you need them in isolation.",
        {},
        async () => {
          if (game.status !== "in_progress") {
            return {
              content: [{ type: "text", text: `Game is over (${game.status}). No legal moves.` }],
            };
          }
          const moves = getLegalMoves(game.board);
          const text =
            `Legal moves (${moves.length}): ` +
            moves.map(([r, c]) => `(row ${r}, col ${c})`).join("  ");
          return { content: [{ type: "text", text }] };
        }
      );
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so the description carries the full burden. It discloses the return format and that it's a read operation, but does not mention preconditions (e.g., game must be ongoing) or error states. Adequate but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences, front-loaded with the main purpose. Every word is necessary and adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description explains the return format. It also covers when to use. Could mention preconditions or errors, but generally complete for a simple tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters exist, so schema coverage is 100%. The description does not add parameter details but provides context on return value and use. Baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it returns empty squares as (row, col) pairs, with a specific verb and resource. It distinguishes itself from siblings by noting that legal moves are included in other responses.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly advises to only call this standalone if needed in isolation, implying when not to use it (when you already have a game state). It implicitly names alternatives (ttt_new_game/ttt_make_move).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SrmTech-git/MCPArcade'

If you have feedback or need assistance with the MCP directory API, please join our Discord server