Skip to main content
Glama

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:

  1. First call get_push_history to view recent push records

  2. 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

TableJSON Schema
NameRequiredDescriptionDefault
messageYesCommit message in English language. Example: {message: "Update project files"}

Implementation Reference

  • 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}`);
      }
    }
  • 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
          });
        });
      });
    };
  • 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']
                  }
                }
  • 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']
    }
  • 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);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the requirement to check push history first, the repository configuration via environment variable, language settings, and what to do with output (e.g., handling branch merge URLs). However, it doesn't mention potential side effects like overwriting data or error conditions, which would be helpful for a push operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose but includes redundant sections (e.g., repeating usage steps and language requirements). Some sentences, like 'Language setting: en (default: en)' and 'Push history check is enabled (CHECK_PUSH_HISTORY=true)', could be condensed or integrated more smoothly. The structure is clear but not optimally concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a push operation with preconditions), no annotations, and no output schema, the description does a good job covering usage steps, prerequisites, and output handling. It mentions sibling tools and environment configurations. However, it lacks details on error cases or what happens on failure, which would improve completeness for this type of tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the single parameter 'message' with its type and example. The description adds minimal value beyond this, only restating that the commit message should be in English. It doesn't provide additional context like message formatting rules or constraints beyond what's in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Execute mgit push command for repository "my-project-repo" with a commit message.' This specifies the verb (execute push command), resource (repository), and required input (commit message). However, it doesn't explicitly differentiate from sibling tools like get_push_history or get_operation_logs beyond mentioning they should be called first.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit, step-by-step usage guidelines: 'You MUST call get_push_history tool FIRST to view the last 5 push records before using this tool' and 'Confirm that the changes in this push have not been pushed before, otherwise modify the push message and push again.' It names the specific alternative tool (get_push_history) and includes clear prerequisites and conditions for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/liliangshan/mcp-server-mgit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server