finish
End a Rubik's Cube solving session by submitting the game ID. This tool ensures proper closure and tracking of progress within the Rubik's Cube MCP Server.
Instructions
Complete the Rubik's Cube game session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gameId | Yes | The game session ID |
Implementation Reference
- src/app.ts:186-214 (handler)Handler function for the 'finish' tool. Retrieves the game session, marks it as completed, checks if the cube is solved, generates an appropriate success or failure message, creates a CubeResponse with nextAction null, and returns structured content with the message and JSON response.async ({ gameId }: { gameId: string }) => { const game = this.games.get(gameId); if (!game) { throw new Error(`Game session ${gameId} not found`); } const { cube, session } = game; const finalState = cube.getState(); session.status = 'completed'; session.lastActivity = Date.now(); const response: CubeResponse = { gameId, cube: finalState, nextAction: null, }; const message = finalState.solved ? `π Congratulations! You solved the cube for game ${gameId}.` : `Game ${gameId} finished. The cube was not solved.` return { content: [ { type: "text", text: message }, { type: "text", text: JSON.stringify(response, null, 2) }, ], }; }
- src/app.ts:183-185 (schema)Input schema for the 'finish' tool using Zod, validating the required 'gameId' string parameter.{ gameId: z.string().describe("The game session ID") },
- src/app.ts:180-215 (registration)Registration of the 'finish' MCP tool on the McpServer instance, specifying name, description, input schema, and handler function.this.mcpServer.tool( "finish", "Complete the Rubik's Cube game session", { gameId: z.string().describe("The game session ID") }, async ({ gameId }: { gameId: string }) => { const game = this.games.get(gameId); if (!game) { throw new Error(`Game session ${gameId} not found`); } const { cube, session } = game; const finalState = cube.getState(); session.status = 'completed'; session.lastActivity = Date.now(); const response: CubeResponse = { gameId, cube: finalState, nextAction: null, }; const message = finalState.solved ? `π Congratulations! You solved the cube for game ${gameId}.` : `Game ${gameId} finished. The cube was not solved.` return { content: [ { type: "text", text: message }, { type: "text", text: JSON.stringify(response, null, 2) }, ], }; } );