mlgym-deploy
Version:
MCP server for GitLab Backend - User creation and project deployment
165 lines (133 loc) ⢠3.89 kB
JavaScript
/**
* Cursor Integration for GitLab Backend MCP
* This script provides command-line access to MCP tools for use in Cursor
*/
import { spawn } from 'child_process';
import readline from 'readline';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// MCP server path
const MCP_SERVER = path.join(__dirname, 'index.js');
// Create interface for user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Helper to call MCP server
async function callMCPTool(toolName, args) {
return new Promise((resolve, reject) => {
const mcp = spawn('node', [MCP_SERVER], {
stdio: ['pipe', 'pipe', 'pipe']
});
let output = '';
let error = '';
// Send request
const request = {
jsonrpc: '2.0',
method: 'tools/call',
params: {
name: toolName,
arguments: args
},
id: 1
};
mcp.stdin.write(JSON.stringify(request) + '\n');
mcp.stdout.on('data', (data) => {
output += data.toString();
});
mcp.stderr.on('data', (data) => {
error += data.toString();
});
mcp.on('close', (code) => {
if (code !== 0) {
reject(new Error(`MCP server exited with code ${code}: ${error}`));
} else {
try {
const response = JSON.parse(output);
resolve(response.result);
} catch (e) {
resolve(output);
}
}
});
});
}
// Command handlers
const commands = {
'create-user': async () => {
console.log('\nš Create GitLab Backend User\n');
const email = await question('Email: ');
const name = await question('Name: ');
const password = await question('Password: ');
console.log('\nCreating user...');
try {
const result = await callMCPTool('mlgym_user_create', {
email,
name,
password
});
console.log('\nā
User created successfully!');
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.error('\nā Error:', error.message);
}
},
'init-project': async () => {
console.log('\nš Initialize GitLab Project\n');
const name = await question('Project name: ');
const description = await question('Description (optional): ');
const enableDeployment = await question('Enable deployment? (y/n): ');
const localPath = await question('Local path (default: .): ') || '.';
console.log('\nInitializing project...');
try {
const result = await callMCPTool('mlgym_project_init', {
name,
description,
enable_deployment: enableDeployment.toLowerCase() === 'y',
local_path: localPath
});
console.log('\nā
Project initialized successfully!');
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.error('\nā Error:', error.message);
}
},
'help': async () => {
console.log(`
GitLab Backend MCP Tools for Cursor
====================================
Commands:
create-user - Create a new GitLab/Coolify user
init-project - Initialize a new project with deployment
help - Show this help message
exit - Exit the tool
Usage:
node cursor-integration.js <command>
Examples:
node cursor-integration.js create-user
node cursor-integration.js init-project
`);
}
};
// Helper to prompt for input
function question(prompt) {
return new Promise((resolve) => {
rl.question(prompt, resolve);
});
}
// Main execution
async function main() {
const command = process.argv[2] || 'help';
if (command === 'exit') {
rl.close();
process.exit(0);
}
const handler = commands[command] || commands.help;
await handler();
rl.close();
}
// Run
main().catch(console.error);