mlgym-deploy 2.7.1 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +96 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -17,7 +17,7 @@ import crypto from 'crypto';
17
17
  const execAsync = promisify(exec);
18
18
 
19
19
  // Current version of this MCP server - INCREMENT FOR WORKFLOW FIXES
20
- const CURRENT_VERSION = '2.7.1';
20
+ const CURRENT_VERSION = '2.9.0'; // Fixed to match CLI workflow: flat API payload structure, git push, deployment monitoring
21
21
  const PACKAGE_NAME = 'mlgym-deploy';
22
22
 
23
23
  // Version check state
@@ -945,11 +945,10 @@ async function initProject(args) {
945
945
 
946
946
  console.error(`Creating project: ${name}`);
947
947
 
948
- // Create project via backend API
948
+ // Create project via backend API with FLAT structure (matching CLI)
949
949
  const projectData = {
950
950
  name: name,
951
- description: description,
952
- enable_deployment: enable_deployment
951
+ description: description
953
952
  };
954
953
 
955
954
  if (enable_deployment) {
@@ -959,11 +958,11 @@ async function initProject(args) {
959
958
  byte => byte.toString(16).padStart(2, '0')
960
959
  ).join('');
961
960
 
961
+ // Use FLAT structure exactly like CLI does - no nested deployment_info
962
+ projectData.enable_deployment = true;
962
963
  projectData.webhook_secret = webhookSecret;
963
-
964
- if (hostname) {
965
- projectData.hostname = hostname;
966
- }
964
+ projectData.hostname = hostname;
965
+ projectData.local_path = local_path;
967
966
  }
968
967
 
969
968
  const result = await apiRequest('POST', '/api/v1/projects', projectData, true);
@@ -1002,12 +1001,92 @@ async function initProject(args) {
1002
1001
 
1003
1002
  await execAsync(`git remote add mlgym ${gitUrl}`, { cwd: absolutePath });
1004
1003
 
1004
+ // Create initial commit and push (like CLI does)
1005
+ const gitSteps = [];
1006
+
1007
+ try {
1008
+ // Check if there are any files to commit
1009
+ const { stdout: statusOutput } = await execAsync('git status --porcelain', { cwd: absolutePath });
1010
+
1011
+ if (statusOutput.trim()) {
1012
+ // There are uncommitted changes
1013
+ gitSteps.push('Adding files to git');
1014
+ await execAsync('git add .', { cwd: absolutePath });
1015
+
1016
+ gitSteps.push('Creating initial commit');
1017
+ await execAsync('git commit -m "Initial MLGym deployment"', { cwd: absolutePath });
1018
+ } else {
1019
+ // Check if there are any commits at all
1020
+ try {
1021
+ await execAsync('git rev-parse HEAD', { cwd: absolutePath });
1022
+ gitSteps.push('Repository already has commits');
1023
+ } catch {
1024
+ // No commits yet, create an initial one
1025
+ gitSteps.push('Creating README for initial commit');
1026
+ const readmePath = path.join(absolutePath, 'README.md');
1027
+ if (!await fs.access(readmePath).then(() => true).catch(() => false)) {
1028
+ await fs.writeFile(readmePath, `# ${name}\n\n${description}\n\nDeployed with MLGym\n`);
1029
+ }
1030
+ await execAsync('git add .', { cwd: absolutePath });
1031
+ await execAsync('git commit -m "Initial MLGym deployment"', { cwd: absolutePath });
1032
+ }
1033
+ }
1034
+
1035
+ // Push to trigger webhook and deployment
1036
+ gitSteps.push('Pushing to GitLab to trigger deployment');
1037
+ await execAsync('git push -u mlgym main', { cwd: absolutePath });
1038
+
1039
+ } catch (pushError) {
1040
+ console.error('Git operations warning:', pushError.message);
1041
+ gitSteps.push(`Warning: ${pushError.message}`);
1042
+ }
1043
+
1044
+ // Monitor deployment if enabled (like CLI does)
1045
+ let deploymentStatus = null;
1046
+ if (enable_deployment) {
1047
+ console.error('Monitoring deployment status...');
1048
+
1049
+ // Poll for deployment status (up to 60 seconds)
1050
+ for (let i = 0; i < 12; i++) {
1051
+ await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
1052
+
1053
+ const statusResult = await apiRequest('GET', `/api/v1/projects/${project.id}/deployment`, null, true);
1054
+ if (statusResult.success && statusResult.data) {
1055
+ const status = statusResult.data.status;
1056
+ console.error(`Deployment status: ${status}`);
1057
+
1058
+ if (status === 'deployed' || status === 'running') {
1059
+ deploymentStatus = {
1060
+ status: 'deployed',
1061
+ url: statusResult.data.url || `https://${hostname}.ezb.net`,
1062
+ message: 'Application successfully deployed'
1063
+ };
1064
+ break;
1065
+ } else if (status === 'failed') {
1066
+ deploymentStatus = {
1067
+ status: 'failed',
1068
+ message: 'Deployment failed. Check Coolify logs for details.'
1069
+ };
1070
+ break;
1071
+ }
1072
+ }
1073
+ }
1074
+
1075
+ if (!deploymentStatus) {
1076
+ deploymentStatus = {
1077
+ status: 'pending',
1078
+ message: 'Deployment is still in progress. Check status later.',
1079
+ expected_url: `https://${hostname}.ezb.net`
1080
+ };
1081
+ }
1082
+ }
1083
+
1005
1084
  return {
1006
1085
  content: [{
1007
1086
  type: 'text',
1008
1087
  text: JSON.stringify({
1009
1088
  status: 'success',
1010
- message: 'Project created successfully',
1089
+ message: 'Project created and pushed successfully',
1011
1090
  project: {
1012
1091
  id: project.id,
1013
1092
  name: project.name,
@@ -1016,12 +1095,14 @@ async function initProject(args) {
1016
1095
  deployment_enabled: enable_deployment,
1017
1096
  deployment_url: hostname ? `https://${hostname}.ezb.net` : null
1018
1097
  },
1019
- next_steps: [
1020
- 'Add your code files',
1021
- 'git add .',
1022
- `git commit -m "Initial commit"`,
1023
- 'git push mlgym main',
1024
- enable_deployment ? 'Your app will be automatically deployed after push' : null
1098
+ git_operations: gitSteps,
1099
+ deployment: deploymentStatus,
1100
+ next_steps: enable_deployment && deploymentStatus?.status === 'deployed' ? [
1101
+ `✅ Your application is live at: ${deploymentStatus.url}`,
1102
+ 'Future updates: git push mlgym main'
1103
+ ] : [
1104
+ 'To update: git push mlgym main',
1105
+ enable_deployment ? 'Deployment will trigger automatically' : null
1025
1106
  ].filter(Boolean)
1026
1107
  }, null, 2)
1027
1108
  }]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mlgym-deploy",
3
- "version": "2.7.1",
3
+ "version": "2.9.0",
4
4
  "description": "MCP server for GitLab Backend - User creation and project deployment",
5
5
  "main": "index.js",
6
6
  "type": "module",