Skip to content

Commit 41b011c

Browse files
Consolidate create_game tools
1 parent e2ab29c commit 41b011c

File tree

4 files changed

+26
-98
lines changed

4 files changed

+26
-98
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Prompt Handlers', () => {
6969
expect(message.content.type).toBe('text')
7070
expect(message.content.text).toContain('Please explain how to play Tic-Tac-Toe')
7171
expect(message.content.text).toContain('objective of the game')
72-
expect(message.content.text).toContain('create_tic_tac_toe_game')
72+
expect(message.content.text).toContain("create_game with gameType: 'tic-tac-toe'")
7373
})
7474

7575
it('should return rock-paper-scissors rules', async () => {
@@ -78,7 +78,7 @@ describe('Prompt Handlers', () => {
7878
expect(result.messages[0].role).toBe('user')
7979
expect(result.messages[0].content.text).toContain('Please explain how to play Rock Paper Scissors')
8080
expect(result.messages[0].content.text).toContain('what beats what')
81-
expect(result.messages[0].content.text).toContain('create_rock_paper_scissors_game')
81+
expect(result.messages[0].content.text).toContain("create_game with gameType: 'rock-paper-scissors'")
8282
})
8383
})
8484

@@ -248,7 +248,7 @@ describe('Prompt Handlers', () => {
248248
const content = result.messages[0].content.text
249249

250250
const gameType = gameName.replace('_rules', '').replace(/_/g, '-')
251-
expect(content).toContain(`create_${gameName.replace('_rules', '_game')}`)
251+
expect(content).toContain(`create_game with gameType: '${gameType}'`)
252252
expect(content).toContain(`play_${gameName.replace('_rules', '')}`)
253253
}
254254
})

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_tic_tac_toe_game, play_tic_tac_toe, wait_for_player_move)
43+
6. How to use the MCP commands (create_game with gameType: 'tic-tac-toe', play_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_rock_paper_scissors_game, play_rock_paper_scissors, wait_for_player_move)
69+
6. How to use the MCP commands (create_game with gameType: 'rock-paper-scissors', play_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: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -83,79 +83,23 @@ export const TOOL_DEFINITIONS = [
8383
},
8484
},
8585
{
86-
name: 'create_tic_tac_toe_game',
87-
description: 'Create a new Tic-Tac-Toe game with optional custom game ID',
86+
name: 'create_game',
87+
description: 'Create a new game with interactive setup. This will ask you for preferences like difficulty, player options, and other game-specific settings.',
8888
inputSchema: {
8989
type: 'object',
9090
properties: {
91-
playerName: {
92-
type: 'string',
93-
description: 'Name of the human player',
94-
default: 'Player',
95-
},
96-
gameId: {
97-
type: 'string',
98-
description: 'Optional custom game ID. If not provided, a random UUID will be generated.',
99-
},
100-
aiDifficulty: {
101-
type: 'string',
102-
enum: ['easy', 'medium', 'hard'],
103-
description: 'AI difficulty level',
104-
default: 'medium',
105-
},
106-
playerSymbol: {
107-
type: 'string',
108-
enum: ['X', 'O'],
109-
description: 'Your symbol: X (goes first) or O (goes second)',
110-
default: 'X',
111-
},
112-
},
113-
required: [],
114-
},
115-
},
116-
{
117-
name: 'create_rock_paper_scissors_game',
118-
description: 'Create a new Rock Paper Scissors game',
119-
inputSchema: {
120-
type: 'object',
121-
properties: {
122-
playerName: {
123-
type: 'string',
124-
description: 'Name of the human player',
125-
default: 'Player',
126-
},
127-
aiDifficulty: {
91+
gameType: {
12892
type: 'string',
129-
enum: ['easy', 'medium', 'hard'],
130-
description: 'AI difficulty level',
131-
default: 'medium',
93+
enum: ['tic-tac-toe', 'rock-paper-scissors'],
94+
description: 'Type of game to create'
13295
},
133-
},
134-
required: [],
135-
},
136-
},
137-
{
138-
name: 'create_tic_tac_toe_game_interactive',
139-
description: 'Create a new Tic-Tac-Toe game with interactive setup. This will ask you for preferences like difficulty and symbol choice.',
140-
inputSchema: {
141-
type: 'object',
142-
properties: {
14396
gameId: {
14497
type: 'string',
145-
description: 'Optional custom game ID. If not provided, a random UUID will be generated.',
146-
},
98+
description: 'Optional custom game ID. If not provided, a random UUID will be generated.'
99+
}
147100
},
148-
required: [],
149-
},
150-
},
151-
{
152-
name: 'create_rock_paper_scissors_game_interactive',
153-
description: 'Create a new Rock Paper Scissors game with interactive setup. This will ask you for preferences like difficulty and number of rounds.',
154-
inputSchema: {
155-
type: 'object',
156-
properties: {},
157-
required: [],
158-
},
101+
required: ['gameType']
102+
}
159103
},
160104
]
161105

@@ -204,30 +148,15 @@ export async function handleToolCall(name: string, args: any, server?: any) {
204148
}
205149
return await waitForPlayerMove(waitGameType, waitGameId, timeoutSeconds, pollInterval)
206150

207-
case 'create_tic_tac_toe_game':
208-
const {
209-
playerName: ticTacToePlayerName = 'Player',
210-
gameId: ticTacToeNewGameId,
211-
aiDifficulty: ticTacToeAiDifficulty = 'medium',
212-
playerSymbol: ticTacToePlayerSymbol = 'X'
213-
} = args
214-
215-
const ticTacToeGameOptions = ticTacToePlayerSymbol ? { playerSymbol: ticTacToePlayerSymbol } : undefined
216-
return await createGame('tic-tac-toe', ticTacToePlayerName, ticTacToeNewGameId, ticTacToeAiDifficulty, ticTacToeGameOptions)
217-
218-
case 'create_rock_paper_scissors_game':
219-
const {
220-
playerName: rpsPlayerName = 'Player',
221-
aiDifficulty: rpsAiDifficulty = 'medium'
222-
} = args
223-
return await createGame('rock-paper-scissors', rpsPlayerName, undefined, rpsAiDifficulty)
224-
225-
case 'create_tic_tac_toe_game_interactive':
226-
const { gameId: interactiveTTTGameId } = args
227-
return await createGameInteractive('tic-tac-toe', interactiveTTTGameId, server)
228-
229-
case 'create_rock_paper_scissors_game_interactive':
230-
return await createGameInteractive('rock-paper-scissors', undefined, server)
151+
case 'create_game':
152+
const { gameType: genericGameType, gameId: genericGameId } = args
153+
if (!genericGameType) {
154+
throw new Error('gameType is required')
155+
}
156+
if (!['tic-tac-toe', 'rock-paper-scissors'].includes(genericGameType)) {
157+
throw new Error(`Unsupported game type: ${genericGameType}`)
158+
}
159+
return await createGameWithElicitation(genericGameType, genericGameId, server)
231160

232161
default:
233162
throw new Error(`Unknown tool: ${name}`)
@@ -240,7 +169,7 @@ export async function handleToolCall(name: string, args: any, server?: any) {
240169
/**
241170
* Create game with interactive elicitation
242171
*/
243-
async function createGameInteractive(gameType: string, gameId?: string, server?: any) {
172+
async function createGameWithElicitation(gameType: string, gameId?: string, server?: any) {
244173
if (!server) {
245174
// Fallback to regular creation if no server for elicitation
246175
return await createGame(gameType, 'Player', gameId, 'medium')

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ describe('MCP Server Integration', () => {
127127
}
128128
})
129129

130-
const result = await handleToolCall('create_tic_tac_toe_game', {
131-
playerName: 'Test Player',
132-
aiDifficulty: 'medium'
130+
const result = await handleToolCall('create_game', {
131+
gameType: 'tic-tac-toe'
133132
})
134133

135134
expect(result.gameId).toBe('new-game-id')

0 commit comments

Comments
 (0)