my-project-repo_mgit_push
Push changes to the 'my-project-repo' Git repository with a commit message after reviewing recent push history to avoid duplicates.
Instructions
[My Awesome Project] Execute mgit push command for repository "my-project-repo" with a commit message.
IMPORTANT:
You MUST call get_push_history tool FIRST to view the last 5 push records before using this tool
Confirm that the changes in this push have not been pushed before, otherwise modify the push message and push again
The repository name is configured via REPO_NAME environment variable
Language setting: en (default: en)
Push history check is enabled (CHECK_PUSH_HISTORY=true). You must review push history before pushing.
USAGE:
First call get_push_history to view recent push records
Then call this tool with the commit message parameter. Example: {message: "Update project files"}
Please provide the commit message in English language.
NOTE: If the push result contains a branch merge URL (such as a pull request URL), please output it to the user. If you can open a browser, you may also automatically open the URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Commit message in English language. Example: {message: "Update project files"} |
Implementation Reference
- src/server-final.js:231-325 (handler)The main handler function `mgit_push` that implements the tool logic: validates `message` param, enforces push history check if enabled, calls `executeMgitPush`, logs and records history, returns structured result or throws on error.async mgit_push(params) { const { message } = params; if (!message || typeof message !== 'string') { throw new Error('Missing message parameter'); } // Check if push history has been checked (only if CHECK_PUSH_HISTORY is enabled) if (CHECK_PUSH_HISTORY && !this.hasCheckedPushHistory) { // Get the actual tool name (with prefix if REPO_NAME is set) const pushHistoryToolName = REPO_NAME ? `${REPO_NAME}_get_push_history` : 'get_push_history'; const pushToolName = REPO_NAME ? `${REPO_NAME}_mgit_push` : 'mgit_push'; // Return JSON-RPC 2.0 compliant result with multiple prompt messages return { content: [ { type: 'text', text: '⚠️ ERROR: Push history check is required before pushing code.' }, { type: 'text', text: `🔧 REQUIRED ACTION: You must call the "${pushHistoryToolName}" tool first to view recent push records.` }, { type: 'text', text: `📋 TOOL NAME: "${pushHistoryToolName}" - Use this tool to get the last 5 push history records.` }, { type: 'text', text: `📝 TOOL CALL EXAMPLE: Call tools/call with name="${pushHistoryToolName}" and empty arguments: {"name": "${pushHistoryToolName}", "arguments": {}}` }, { type: 'text', text: '🔍 STEP 1: Call get_push_history tool to view the last 5 push records for this repository.' }, { type: 'text', text: '📊 STEP 2: Review the push history records to see what has been pushed recently.' }, { type: 'text', text: '✅ STEP 3: Confirm that the changes you want to push have NOT been pushed before by comparing with the history.' }, { type: 'text', text: '🔄 STEP 4: If the changes have already been pushed, modify the commit message to reflect new changes, then try again.' }, { type: 'text', text: `🚀 STEP 5: After reviewing and confirming, you can then call "${pushToolName}" tool to proceed with the push.` }, { type: 'text', text: `⚠️ IMPORTANT: The "${pushHistoryToolName}" tool must be called before "${pushToolName}" tool, otherwise the push will be rejected.` } ], isError: true, errorCode: 'PUSH_HISTORY_CHECK_REQUIRED' }; } try { const result = await executeMgitPush(message); // Log operation logRequest('mgit_push', { repo_name: REPO_NAME, message }, result); // Record push history recordPushHistory(message, result, null); // Reset the flag after successful push this.hasCheckedPushHistory = false; return { success: true, repo_name: REPO_NAME, message: message, output: result.stdout, error_output: result.stderr, exit_code: result.exitCode }; } catch (err) { // Log operation error logRequest('mgit_push', { repo_name: REPO_NAME, message }, null, err.error || err.message); // Record push history even on error recordPushHistory(message, null, err.error || err.message); // Reset the flag after error this.hasCheckedPushHistory = false; throw new Error(`MGit push failed: ${err.error || err.message}`); } }
- src/server-final.js:138-202 (helper)Helper function `executeMgitPush` that spawns the `mgit push <repo> <message>` subprocess, captures output streams and exit code, resolves success or rejects with error details.const executeMgitPush = async (message) => { return new Promise((resolve, reject) => { const command = MGIT_CMD; // Clean the message: remove or escape problematic characters // Remove double quotes from the message to avoid argument parsing issues // Replace double quotes with single quotes or remove them const cleanedMessage = message.replace(/"/g, "'"); // When using spawn with array args, we don't need quotes // The message will be passed as a single argument even if it contains spaces const args = ['push', REPO_NAME, cleanedMessage]; console.error(`Executing: ${command} ${args.map(arg => arg.includes(' ') ? `"${arg}"` : arg).join(' ')}`); // Use shell: false to pass arguments directly without shell interpretation // This ensures the message is passed as a single argument even with spaces const child = spawn(command, args, { stdio: ['inherit', 'pipe', 'pipe'], shell: false }); let stdout = ''; let stderr = ''; child.stdout.on('data', (data) => { const output = data.toString(); stdout += output; console.error(output); }); child.stderr.on('data', (data) => { const output = data.toString(); stderr += output; console.error(output); }); child.on('close', (code) => { if (code === 0) { resolve({ success: true, stdout: stdout, stderr: stderr, exitCode: code }); } else { reject({ success: false, stdout: stdout, stderr: stderr, exitCode: code, error: `Command exited with code ${code}` }); } }); child.on('error', (err) => { reject({ success: false, error: err.message, stdout: stdout, stderr: stderr }); }); }); };
- src/server-final.js:457-483 (registration)Tool registration in `tools/list` method: defines the tool name as `${REPO_NAME}_mgit_push` (e.g., 'my-project-repo_mgit_push'), detailed description, and input schema requiring 'message' string.{ name: getToolName('mgit_push'), description: getToolDescription(`Execute ${MGIT_CMD} push command for repository "${REPO_NAME}" with a commit message. IMPORTANT: ${CHECK_PUSH_HISTORY ? '- You MUST call get_push_history tool FIRST to view the last 5 push records before using this tool\n- Confirm that the changes in this push have not been pushed before, otherwise modify the push message and push again\n' : ''}- The repository name is configured via REPO_NAME environment variable - Language setting: ${LANGUAGE} (default: en) ${CHECK_PUSH_HISTORY ? '- Push history check is enabled (CHECK_PUSH_HISTORY=true). You must review push history before pushing.\n' : '- Push history check is disabled (CHECK_PUSH_HISTORY=false). You can push directly without checking history.\n'} USAGE: ${CHECK_PUSH_HISTORY ? '1. First call get_push_history to view recent push records\n2. ' : ''}Then call this tool with the commit message parameter. Example: {message: "${LANGUAGE === 'en' ? 'Update project files' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? '更新项目文件' : LANGUAGE === 'zh-TW' ? '更新專案檔案' : 'Update project files'}"} Please provide the commit message in ${LANGUAGE === 'en' ? 'English' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? 'Chinese' : LANGUAGE === 'zh-TW' ? 'Traditional Chinese' : LANGUAGE} language. NOTE: If the push result contains a branch merge URL (such as a pull request URL), please output it to the user. If you can open a browser, you may also automatically open the URL.`), inputSchema: { type: 'object', properties: { message: { type: 'string', description: `Commit message in ${LANGUAGE === 'en' ? 'English' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? 'Chinese' : LANGUAGE === 'zh-TW' ? 'Traditional Chinese' : LANGUAGE} language. Example: {message: "${LANGUAGE === 'en' ? 'Update project files' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? '更新项目文件' : LANGUAGE === 'zh-TW' ? '更新專案檔案' : 'Update project files'}"}` } }, required: ['message'] } }
- src/server-final.js:473-482 (schema)Input schema definition for the tool: object with required 'message' property of type string, including language-specific description and example.inputSchema: { type: 'object', properties: { message: { type: 'string', description: `Commit message in ${LANGUAGE === 'en' ? 'English' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? 'Chinese' : LANGUAGE === 'zh-TW' ? 'Traditional Chinese' : LANGUAGE} language. Example: {message: "${LANGUAGE === 'en' ? 'Update project files' : LANGUAGE === 'zh' || LANGUAGE === 'zh-CN' ? '更新项目文件' : LANGUAGE === 'zh-TW' ? '更新專案檔案' : 'Update project files'}"}` } }, required: ['message'] }
- src/server-final.js:603-606 (helper)Helper logic in `tools/call` handler that strips the repo prefix (e.g., 'my-project-repo_') from tool name to map to internal `mgit_push` method.let actualMethodName = name; if (REPO_NAME && name.startsWith(`${REPO_NAME}_`)) { actualMethodName = name.substring(REPO_NAME.length + 1); }