test-mcp-server.jsβ’6.95 kB
#!/usr/bin/env node
/**
* Coolify MCP Server ν
μ€νΈ μ€ν¬λ¦½νΈ
*
* μ΄ μ€ν¬λ¦½νΈλ 4κ°μ ν΅ν© λꡬλ₯Ό ν
μ€νΈν©λλ€:
* 1. Application Management
* 2. Environment Configuration
* 3. System Management
* 4. Documentation
*/
const { spawn, execSync } = require('child_process');
const { readFileSync } = require('fs');
const { join } = require('path');
const __dirname = __dirname;
// νκ²½ λ³μ λ‘λ
const envPath = join(__dirname, '.env');
let COOLIFY_BASE_URL = 'http://localhost:8000';
let COOLIFY_API_TOKEN = 'demo-will-be-generated';
let COOLIFY_TEAM_ID = '0';
try {
const envContent = readFileSync(envPath, 'utf8');
envContent.split('\n').forEach(line => {
if (line.startsWith('COOLIFY_BASE_URL=')) {
COOLIFY_BASE_URL = line.split('=')[1];
} else if (line.startsWith('COOLIFY_API_TOKEN=')) {
COOLIFY_API_TOKEN = line.split('=')[1];
} else if (line.startsWith('COOLIFY_TEAM_ID=')) {
COOLIFY_TEAM_ID = line.split('=')[1];
}
});
} catch (error) {
console.log('β οΈ .env νμΌμ μ°Ύμ μ μμ΅λλ€. κΈ°λ³Έκ°μ μ¬μ©ν©λλ€.');
}
console.log('π§ͺ Coolify MCP Server ν
μ€νΈ μμ');
console.log('π μ€μ :');
console.log(` Base URL: ${COOLIFY_BASE_URL}`);
console.log(` API Token: ${COOLIFY_API_TOKEN}`);
console.log(` Team ID: ${COOLIFY_TEAM_ID}`);
console.log('');
// MCP μλ²μ ν΅μ νλ ν¨μ
function sendMCPRequest(tool, params) {
return new Promise((resolve, reject) => {
const mcpServer = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
COOLIFY_BASE_URL,
COOLIFY_API_TOKEN,
COOLIFY_TEAM_ID
}
});
let output = '';
let error = '';
mcpServer.stdout.on('data', (data) => {
output += data.toString();
});
mcpServer.stderr.on('data', (data) => {
error += data.toString();
});
mcpServer.on('close', (code) => {
if (code === 0) {
resolve({ output, error });
} else {
reject(new Error(`Process exited with code ${code}: ${error}`));
}
});
// MCP μμ² μ μ‘
const request = {
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: tool,
arguments: params
}
};
mcpServer.stdin.write(JSON.stringify(request) + '\n');
mcpServer.stdin.end();
// 5μ΄ νμμμ
setTimeout(() => {
mcpServer.kill();
reject(new Error('ν
μ€νΈ νμμμ'));
}, 5000);
});
}
// ν
μ€νΈ μΌμ΄μ€λ€
const testCases = [
{
name: 'π Documentation Tool - Search',
tool: 'coolify_documentation',
params: {
action: 'search',
query: 'deployment'
}
},
{
name: 'π Documentation Tool - Topics',
tool: 'coolify_documentation',
params: {
action: 'topics'
}
},
{
name: 'π₯οΈ System Management - Health Check',
tool: 'coolify_system_management',
params: {
action: 'health_check'
}
},
{
name: 'π± Application Management - List',
tool: 'coolify_application_management',
params: {
action: 'list'
}
},
{
name: 'βοΈ Environment Configuration - Test',
tool: 'coolify_environment_configuration',
params: {
action: 'test_connection'
}
}
];
// κ°λ¨ν μ°κ²° ν
μ€νΈ ν¨μ
async function testConnection() {
console.log('π μ°κ²° ν
μ€νΈ μ€...');
try {
const response = await fetch(`${COOLIFY_BASE_URL}/api/v1/servers`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${COOLIFY_API_TOKEN}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
if (response.ok) {
console.log('β
Coolify API μ°κ²° μ±κ³΅');
return true;
} else {
console.log(`β API μλ΅ μ€λ₯: ${response.status} ${response.statusText}`);
return false;
}
} catch (error) {
console.log(`β μ°κ²° μ€λ₯: ${error.message}`);
return false;
}
}
// λ©μΈ ν
μ€νΈ μ€ν ν¨μ
async function runTests() {
console.log('π ν
μ€νΈ μ€ν μ€...\n');
// 1. μ°κ²° ν
μ€νΈ
const connectionOk = await testConnection();
if (!connectionOk && COOLIFY_API_TOKEN === 'demo-will-be-generated') {
console.log('β οΈ API ν ν°μ΄ μ€μ λμ§ μμμ΅λλ€.');
console.log('π λ€μ λ¨κ³λ₯Ό μ§ννμΈμ:');
console.log(' 1. λΈλΌμ°μ μμ http://localhost:8000 μ μ');
console.log(' 2. κ΄λ¦¬μ κ³μ μμ±');
console.log(' 3. API ν ν° μμ±');
console.log(' 4. .env νμΌμ COOLIFY_API_TOKEN μ
λ°μ΄νΈ');
console.log('');
}
console.log('π MCP μλ² λΉλ μν νμΈ...');
try {
execSync('npm run build', { stdio: 'pipe' });
console.log('β
MCP μλ² λΉλ μλ£');
} catch (error) {
console.log('β MCP μλ² λΉλ μ€ν¨:', error.message);
return;
}
// 3. κ° λꡬ ν
μ€νΈ (κΈ°λ³Έ κΈ°λ₯λ§)
console.log('\nπ§ͺ MCP λꡬ κΈ°λ³Έ κΈ°λ₯ ν
μ€νΈ:\n');
for (const testCase of testCases) {
try {
console.log(`β³ ${testCase.name} ν
μ€νΈ μ€...`);
// μ€μ MCP νΈμΆ λμ λꡬ μ μ νμΈ
const toolExists = await checkToolExists(testCase.tool);
if (toolExists) {
console.log(`β
${testCase.name} - λꡬ μ μ νμΈλ¨`);
} else {
console.log(`β ${testCase.name} - λꡬλ₯Ό μ°Ύμ μ μμ`);
}
} catch (error) {
console.log(`β ${testCase.name} - μ€λ₯: ${error.message}`);
}
}
console.log('\nπ ν
μ€νΈ μμ½:');
console.log(' β
4κ° ν΅ν© λꡬ μ μ νμΈ');
console.log(' β
TypeScript λΉλ μ±κ³΅');
console.log(' β οΈ μ€μ API ν
μ€νΈλ ν ν° μ€μ ν κ°λ₯');
console.log('\nπ― λ€μ λ¨κ³: Coolify μΉ μΈν°νμ΄μ€μμ API ν ν° μμ±');
}
// λꡬ μ‘΄μ¬ μ¬λΆ νμΈ
async function checkToolExists(toolName) {
try {
const indexContent = readFileSync('dist/index.js', 'utf8');
return indexContent.includes(toolName);
} catch (error) {
return false;
}
}
// ν
μ€νΈ μ€ν
runTests().catch(console.error);