Skip to content

Commit 5454e71

Browse files
Consolidate play tools
1 parent 41b011c commit 5454e71

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

mcp-server/src/handlers/prompt-handlers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('Prompt Handlers', () => {
249249

250250
const gameType = gameName.replace('_rules', '').replace(/_/g, '-')
251251
expect(content).toContain(`create_game with gameType: '${gameType}'`)
252-
expect(content).toContain(`play_${gameName.replace('_rules', '')}`)
252+
expect(content).toContain(`play_game with gameType: '${gameType}'`)
253253
}
254254
})
255255

mcp-server/src/handlers/prompt-handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const GAME_RULES_PROMPTS: PromptDefinition[] = [
4040
3. How to make moves (using positions 1-9)
4141
4. All possible winning conditions
4242
5. Basic strategy tips for beginners
43-
6. How to use the MCP commands (create_game with gameType: 'tic-tac-toe', play_tic_tac_toe, wait_for_player_move)
43+
6. How to use the MCP commands (create_game with gameType: 'tic-tac-toe', play_game with gameType: 'tic-tac-toe', wait_for_player_move)
4444
7. What happens with perfect play
4545
4646
Make it comprehensive but easy to understand for someone who has never played before.`
@@ -66,7 +66,7 @@ Make it comprehensive but easy to understand for someone who has never played be
6666
3. Strategy tips for beginners and advanced players
6767
4. How psychology and pattern recognition work in this game
6868
5. What the different AI difficulty levels mean and how to counter them
69-
6. How to use the MCP commands (create_game with gameType: 'rock-paper-scissors', play_rock_paper_scissors, wait_for_player_move)
69+
6. How to use the MCP commands (create_game with gameType: 'rock-paper-scissors', play_game with gameType: 'rock-paper-scissors', wait_for_player_move)
7070
7. Why unpredictability is key to mastery
7171
7272
Make it comprehensive and include both basic rules and advanced psychological strategies.`

mcp-server/src/handlers/tool-handlers.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,22 @@ import { elicitGameCreationPreferences } from './elicitation-handlers.js'
77

88
export const TOOL_DEFINITIONS = [
99
{
10-
name: 'play_tic_tac_toe',
11-
description: 'Make an AI move in Tic-Tac-Toe game. IMPORTANT: After calling this tool when the game is still playing, you MUST call wait_for_player_move to continue the game flow.',
10+
name: 'play_game',
11+
description: 'Make an AI move in a game. IMPORTANT: After calling this tool when the game is still playing, you MUST call wait_for_player_move to continue the game flow.',
1212
inputSchema: {
1313
type: 'object',
1414
properties: {
1515
gameId: {
1616
type: 'string',
17-
description: 'The ID of the Tic-Tac-Toe game to play',
17+
description: 'The ID of the game to play',
1818
},
19-
},
20-
required: ['gameId'],
21-
},
22-
},
23-
{
24-
name: 'play_rock_paper_scissors',
25-
description: 'Make an AI choice in Rock Paper Scissors game. IMPORTANT: After calling this tool when the game is still playing, you MUST call wait_for_player_move to continue the game flow.',
26-
inputSchema: {
27-
type: 'object',
28-
properties: {
29-
gameId: {
19+
gameType: {
3020
type: 'string',
31-
description: 'The ID of the Rock Paper Scissors game to play',
21+
enum: ['tic-tac-toe', 'rock-paper-scissors'],
22+
description: 'Type of game to play',
3223
},
3324
},
34-
required: ['gameId'],
25+
required: ['gameId', 'gameType'],
3526
},
3627
},
3728
{
@@ -55,7 +46,7 @@ export const TOOL_DEFINITIONS = [
5546
},
5647
{
5748
name: 'wait_for_player_move',
58-
description: 'Wait for human player to make their move after AI has played. This tool should be called after any play_* tool when the game is still ongoing.',
49+
description: 'Wait for human player to make their move after AI has played. This tool should be called after the play_game tool when the game is still ongoing.',
5950
inputSchema: {
6051
type: 'object',
6152
properties: {
@@ -109,19 +100,18 @@ export const TOOL_DEFINITIONS = [
109100
export async function handleToolCall(name: string, args: any, server?: any) {
110101
try {
111102
switch (name) {
112-
case 'play_tic_tac_toe':
113-
const { gameId: ticTacToeGameId } = args
114-
if (!ticTacToeGameId) {
103+
case 'play_game':
104+
const { gameId: playGameId, gameType: playGameType } = args
105+
if (!playGameId) {
115106
throw new Error('gameId is required')
116107
}
117-
return await playGame('tic-tac-toe', ticTacToeGameId)
118-
119-
case 'play_rock_paper_scissors':
120-
const { gameId: rpsGameId } = args
121-
if (!rpsGameId) {
122-
throw new Error('gameId is required')
108+
if (!playGameType) {
109+
throw new Error('gameType is required')
110+
}
111+
if (!['tic-tac-toe', 'rock-paper-scissors'].includes(playGameType)) {
112+
throw new Error(`Unsupported game type: ${playGameType}`)
123113
}
124-
return await playGame('rock-paper-scissors', rpsGameId)
114+
return await playGame(playGameType, playGameId)
125115

126116
case 'analyze_game':
127117
const { gameId: analyzeGameId, gameType: analyzeGameType } = args

mcp-server/src/integration/integration.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ describe('MCP Server Integration', () => {
156156
}
157157
})
158158

159-
const result = await handleToolCall('play_tic_tac_toe', {
160-
gameId: 'test-game'
159+
const result = await handleToolCall('play_game', {
160+
gameId: 'test-game',
161+
gameType: 'tic-tac-toe'
161162
})
162163

163164
expect(result.gameId).toBe('test-game')

0 commit comments

Comments
 (0)