manipulateCube
Execute standard Rubik's Cube notation moves to manipulate cube positions within game sessions for solving puzzles.
Instructions
Execute a move on the Rubik's Cube
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gameId | Yes | The game session ID | |
| move | Yes | The cube move to execute |
Implementation Reference
- src/app.ts:122-176 (handler)Handler function that looks up the game session by ID, optionally checks if already completed, executes the cube move, updates session and visualization server, and returns the updated cube state with next action.async ({ gameId, move }: { gameId: string; move: string }) => { const game = this.games.get(gameId); if (!game) { throw new Error(`Game session ${gameId} not found`); } const { cube, session } = game; // 이미 해결된 큐브인지 확인 if (session.status === 'completed') { const response: CubeResponse = { gameId, cube: cube.getState(), nextAction: "finish" }; return { content: [ { type: "text", text: JSON.stringify(response, null, 2) } ] }; } // 움직임 실행 cube.executeMove(move as CubeMove); const newState = cube.getState(); // 세션 업데이트 session.cubeState = newState; session.lastActivity = Date.now(); if (newState.solved) { session.status = 'completed'; } // 시각화 서버 업데이트 this.visualizationServer.updateSession(gameId, newState); const response: CubeResponse = { gameId, cube: newState, nextAction: newState.solved ? "finish" : "manipulateCube" }; return { content: [ { type: "text", text: JSON.stringify(response, null, 2) } ] }; }
- src/app.ts:119-121 (schema)Zod input schema for the manipulateCube tool, validating gameId (string) and move (enum of valid Rubik's Cube moves).gameId: z.string().describe("The game session ID"), move: z.enum(['U', 'D', 'L', 'R', 'F', 'B', 'U\'', 'D\'', 'L\'', 'R\'', 'F\'', 'B\'', 'U2', 'D2', 'L2', 'R2', 'F2', 'B2']).describe("The cube move to execute") },
- src/app.ts:116-177 (registration)MCP tool registration call for 'manipulateCube', specifying name, description, input schema, and handler function."manipulateCube", "Execute a move on the Rubik's Cube", { gameId: z.string().describe("The game session ID"), move: z.enum(['U', 'D', 'L', 'R', 'F', 'B', 'U\'', 'D\'', 'L\'', 'R\'', 'F\'', 'B\'', 'U2', 'D2', 'L2', 'R2', 'F2', 'B2']).describe("The cube move to execute") }, async ({ gameId, move }: { gameId: string; move: string }) => { const game = this.games.get(gameId); if (!game) { throw new Error(`Game session ${gameId} not found`); } const { cube, session } = game; // 이미 해결된 큐브인지 확인 if (session.status === 'completed') { const response: CubeResponse = { gameId, cube: cube.getState(), nextAction: "finish" }; return { content: [ { type: "text", text: JSON.stringify(response, null, 2) } ] }; } // 움직임 실행 cube.executeMove(move as CubeMove); const newState = cube.getState(); // 세션 업데이트 session.cubeState = newState; session.lastActivity = Date.now(); if (newState.solved) { session.status = 'completed'; } // 시각화 서버 업데이트 this.visualizationServer.updateSession(gameId, newState); const response: CubeResponse = { gameId, cube: newState, nextAction: newState.solved ? "finish" : "manipulateCube" }; return { content: [ { type: "text", text: JSON.stringify(response, null, 2) } ] }; } );
- src/cubeLogic.ts:210-216 (helper)Core helper method in RubiksCube class that resolves the move to a function via getMoveFunction and executes it, then updates history and solved status. Used directly in the tool handler.executeMove(move: CubeMove): void { const moveFunc = this.getMoveFunction(move); moveFunc(); this.state.moveHistory.push(move); this.state.solved = this.checkSolved(); }
- src/types.ts:24-26 (schema)TypeScript type definition for CubeMove, used in the tool schema enum and executeMove parameter.export type CubeMove = 'U' | 'D' | 'L' | 'R' | 'F' | 'B' | 'U\'' | 'D\'' | 'L\'' | 'R\'' | 'F\'' | 'B\'' | 'U2' | 'D2' | 'L2' | 'R2' | 'F2' | 'B2';