Skip to content

Commit ee6012f

Browse files
Phase 1-2: Consolidate HTTP clients and remove dead code
Co-authored-by: chrisreddington <[email protected]>
1 parent c8fa39f commit ee6012f

File tree

8 files changed

+67
-49
lines changed

8 files changed

+67
-49
lines changed

mcp-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "@turn-based-mcp/mcp-server",
33
"version": "1.0.0",
44
"description": "MCP server for turn-based games AI opponent",
5-
"main": "dist/index.js",
5+
"main": "dist/server.js",
66
"type": "module",
77
"scripts": {
88
"build": "tsc",
99
"dev": "tsc --watch",
10-
"start": "node dist/index.js",
10+
"start": "node dist/server.js",
1111
"clean": "rm -rf dist",
1212
"type-check": "tsc --noEmit",
1313
"test": "vitest run",

mcp-server/src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

mcp-server/src/utils/http-client.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
/**
22
* HTTP client utilities for communicating with the web API
3+
*
4+
* This module provides higher-level API functions for the MCP server
5+
* while using shared HTTP utilities to eliminate code duplication.
36
*/
47

5-
const WEB_API_BASE = process.env.WEB_API_BASE || 'http://localhost:3000'
6-
7-
export async function httpGet(url: string): Promise<any> {
8-
const response = await fetch(url)
9-
if (!response.ok) {
10-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
11-
}
12-
return response.json()
13-
}
14-
15-
export async function httpPost(url: string, data: any): Promise<any> {
16-
const response = await fetch(url, {
17-
method: 'POST',
18-
headers: { 'Content-Type': 'application/json' },
19-
body: JSON.stringify(data)
20-
})
21-
if (!response.ok) {
22-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
23-
}
24-
return response.json()
25-
}
8+
import { httpGet, httpPost, WEB_API_BASE } from '@turn-based-mcp/shared'
269

2710
/**
2811
* Generic game state fetcher for resources

mcp-server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"allowSyntheticDefaultImports": true
1616
},
1717
"include": ["src/**/*"],
18-
"exclude": ["dist", "node_modules"]
18+
"exclude": ["dist", "node_modules", "**/*.test.ts", "**/*.test.tsx"]
1919
}

shared/src/storage/mcp-api-client.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
import type { GameSession } from '../types/game'
22
import type { TicTacToeGameState, RPSGameState } from '../types/games'
3-
4-
// Web app base URL for API calls (when called from MCP server)
5-
const WEB_API_BASE = process.env.WEB_API_BASE || 'http://localhost:3000'
6-
7-
// HTTP client functions for MCP server
8-
async function httpGet(url: string): Promise<any> {
9-
const response = await fetch(url)
10-
if (!response.ok) {
11-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
12-
}
13-
return response.json()
14-
}
15-
16-
async function httpPost(url: string, data: any): Promise<any> {
17-
const response = await fetch(url, {
18-
method: 'POST',
19-
headers: { 'Content-Type': 'application/json' },
20-
body: JSON.stringify(data)
21-
})
22-
if (!response.ok) {
23-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
24-
}
25-
return response.json()
26-
}
3+
import { httpGet, httpPost, WEB_API_BASE } from '../utils/http-client'
274

285
// MCP-specific API functions that make HTTP calls to web app
296
export async function getTicTacToeGameForMCP(gameId: string): Promise<GameSession<TicTacToeGameState> | undefined> {

shared/src/utils/http-client.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Shared HTTP client utilities for communicating with the web API
3+
*
4+
* Provides centralized HTTP functions to eliminate duplication between
5+
* the MCP server and shared library API clients.
6+
*/
7+
8+
// Web app base URL for API calls (configurable via environment)
9+
export const WEB_API_BASE = process.env.WEB_API_BASE || 'http://localhost:3000'
10+
11+
/**
12+
* Performs an HTTP GET request
13+
*
14+
* @param url - The URL to fetch from
15+
* @returns Promise resolving to the JSON response
16+
* @throws Error if the request fails or returns non-2xx status
17+
*/
18+
export async function httpGet(url: string): Promise<any> {
19+
const response = await fetch(url)
20+
if (!response.ok) {
21+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
22+
}
23+
return response.json()
24+
}
25+
26+
/**
27+
* Performs an HTTP POST request with JSON data
28+
*
29+
* @param url - The URL to post to
30+
* @param data - The data to send in the request body
31+
* @returns Promise resolving to the JSON response
32+
* @throws Error if the request fails or returns non-2xx status
33+
*/
34+
export async function httpPost(url: string, data: any): Promise<any> {
35+
const response = await fetch(url, {
36+
method: 'POST',
37+
headers: { 'Content-Type': 'application/json' },
38+
body: JSON.stringify(data)
39+
})
40+
if (!response.ok) {
41+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
42+
}
43+
return response.json()
44+
}

shared/src/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ export function getGameDisplayName(gameType: GameType): string {
3434
}
3535
}
3636

37+
// Re-export HTTP client utilities
38+
export * from './http-client';
39+
3740

web/src/lib/game-storage.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1+
/**
2+
* Game Storage Re-export Module
3+
*
4+
* This module provides backward compatibility by re-exporting all storage
5+
* functions from the shared library. This allows existing web application
6+
* code to continue using storage functions via this path while the actual
7+
* implementation is centralized in the shared package.
8+
*
9+
* Purpose: Maintains API stability during the monorepo consolidation process.
10+
* Future: Consider migrating imports to use @turn-based-mcp/shared directly.
11+
*/
12+
113
// Re-export from shared package for backward compatibility
214
export * from '@turn-based-mcp/shared';

0 commit comments

Comments
 (0)