const { spawn } = require('child_process');
class MCPTestClient {
constructor() {
this.server = null;
this.requestId = 1;
}
async start() {
return new Promise((resolve, reject) => {
this.server = spawn('npx', ['openai-mcp-server'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: process.cwd()
});
this.server.stderr.on('data', (data) => {
const output = data.toString();
if (output.includes('OpenAI MCP Server started')) {
console.log('โ
MCP Server started successfully');
resolve();
} else if (output.includes('ERROR')) {
reject(new Error(output));
}
});
this.server.on('error', reject);
});
}
async callTool(name, args) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: this.requestId++,
method: 'tools/call',
params: { name, arguments: args }
};
let responseData = '';
const timeout = setTimeout(() => {
reject(new Error('Request timeout'));
}, 30000);
const onData = (data) => {
responseData += data.toString();
try {
const response = JSON.parse(responseData);
clearTimeout(timeout);
this.server.stdout.off('data', onData);
if (response.error) {
reject(new Error(response.error.message));
} else {
resolve(response.result);
}
} catch (e) {
// Still receiving data
}
};
this.server.stdout.on('data', onData);
this.server.stdin.write(JSON.stringify(request) + '\n');
});
}
stop() {
if (this.server) {
this.server.kill();
}
}
}
async function runTests() {
const client = new MCPTestClient();
try {
console.log('๐ Starting MCP Server...');
await client.start();
console.log('๐ Testing web development question...');
// Test 1: Web development analysis
const result1 = await client.callTool('call_gpt5', {
prompt: "๋ชจ๋ ์น ํ๋ก ํธ์๋ ๊ฐ๋ฐ์์ React์ Vue.js ์ค ์ด๋ค ๊ฒ์ ์ ํํด์ผ ํ ๊น์? ๊ฐ๊ฐ์ ์ฅ๋จ์ ์ ๋น๊ตํด์ฃผ์ธ์.",
taskType: "analysis",
domain: "frontend",
context: {
projectType: "enterprise",
teamSize: "medium",
timeline: "6months"
}
});
console.log('โ
Test 1 - Frontend Framework Analysis:');
console.log('Response:', result1.content[0].text.substring(0, 200) + '...');
// Test 2: Code generation
const result2 = await client.callTool('call_gpt5', {
prompt: "React์์ ์ฌ์ฉ์ ์ธ์ฆ์ ์ํ ์ปค์คํ
ํ
์ ๋ง๋ค์ด์ฃผ์ธ์. JWT ํ ํฐ ๊ด๋ฆฌ๋ฅผ ํฌํจํด์ผ ํฉ๋๋ค.",
taskType: "coding",
domain: "authentication",
optimizationLevel: "precise"
});
console.log('โ
Test 2 - Code Generation:');
console.log('Response:', result2.content[0].text.substring(0, 200) + '...');
// Test 3: Creative solution
const result3 = await client.callTool('call_gpt5', {
prompt: "์น ์ ๊ทผ์ฑ์ ๊ณ ๋ คํ ์ฐฝ์์ ์ธ UI/UX ์์ด๋์ด๋ฅผ ์ ์ํด์ฃผ์ธ์.",
taskType: "generation",
domain: "design",
optimizationLevel: "creative"
});
console.log('โ
Test 3 - Creative Design Ideas:');
console.log('Response:', result3.content[0].text.substring(0, 200) + '...');
console.log('๐ All tests completed successfully!');
} catch (error) {
console.error('โ Test failed:', error.message);
} finally {
client.stop();
}
}
runTests();