test_client.jsβ’3.67 kB
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();