Skip to main content
Glama

push_to_repo

Push content to a GitHub repository by specifying the repository name, file path, and content to commit. This tool enables updating files in GitHub repositories through the MCP protocol.

Instructions

Push content to a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_nameYesThe name of the repository to push to
file_pathYesThe path where the file should be created in the repository
contentYesThe content to push to the repository
messageNoThe commit messageUpdate via GitHub MCP

Implementation Reference

  • Handler for the 'push_to_repo' tool. Validates input parameters, retrieves the authenticated user's username, checks if the file exists to get its SHA, and uses the GitHub Contents API to create or update the file with base64-encoded content.
    } else if (request.params.name === 'push_to_repo') {
      const repo_name = args.repo_name;
      const file_path = args.file_path;
      const content = args.content;
      if (!repo_name || !file_path || !content) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Repository name, file path, and content are required'
        );
      }
    
      try {
        // Get the authenticated user's information
        const userResponse = await this.axiosInstance.get('/user');
        const username = userResponse.data.login;
    
        // Check if the file already exists
        let sha: string | undefined;
        try {
          const fileResponse = await this.axiosInstance.get(
            `/repos/${username}/${repo_name}/contents/${file_path}`
          );
          sha = fileResponse.data.sha;
        } catch (error) {
          // File doesn't exist, which is fine
        }
    
        // Create or update the file in the repository
        const response = await this.axiosInstance.put(
          `/repos/${username}/${repo_name}/contents/${file_path}`,
          {
            message: args.message ?? 'Update via GitHub MCP',
            content: Buffer.from(content).toString('base64'),
            sha: sha, // Include sha if updating an existing file
          }
        );
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(response.data, null, 2),
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          return {
            content: [
              {
                type: 'text',
                text: `GitHub API error: ${
                  error.response?.data.message ?? error.message
                }`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    } else {
  • Input schema definition for the 'push_to_repo' tool, specifying properties like repo_name, file_path, content, and message with required fields.
    inputSchema: {
      type: 'object',
      properties: {
        repo_name: {
          type: 'string',
          description: 'The name of the repository to push to',
        },
        file_path: {
          type: 'string',
          description: 'The path where the file should be created in the repository',
        },
        content: {
          type: 'string',
          description: 'The content to push to the repository',
        },
        message: {
          type: 'string',
          description: 'The commit message',
          default: 'Update via GitHub MCP',
        },
      },
      required: ['repo_name', 'file_path', 'content'],
    },
  • src/index.ts:133-159 (registration)
    Registration of the 'push_to_repo' tool in the MCP server's list of tools, including name, description, and input schema.
    {
      name: 'push_to_repo',
      description: 'Push content to a GitHub repository',
      inputSchema: {
        type: 'object',
        properties: {
          repo_name: {
            type: 'string',
            description: 'The name of the repository to push to',
          },
          file_path: {
            type: 'string',
            description: 'The path where the file should be created in the repository',
          },
          content: {
            type: 'string',
            description: 'The content to push to the repository',
          },
          message: {
            type: 'string',
            description: 'The commit message',
            default: 'Update via GitHub MCP',
          },
        },
        required: ['repo_name', 'file_path', 'content'],
      },
    },
  • TypeScript interface defining arguments for GitHub tools, including those used by push_to_repo.
    interface GithubToolArguments {
      username?: string;
      repo_name?: string;
      description?: string;
      private?: boolean;
      file_path?: string;
      content?: string;
      message?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It states 'push content' but doesn't disclose if this creates/overwrites files, requires authentication, has rate limits, or what happens on success/failure (e.g., commit creation). It's minimal and misses key operational traits for a write operation.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded and appropriately sized for the tool's complexity, making it easy to parse quickly without unnecessary elaboration.

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

Completeness2/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 write operation to GitHub with 4 parameters), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects, return values, or error handling, leaving significant gaps for an agent to understand how to invoke it correctly.

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?

The input schema has 100% description coverage, clearly documenting all 4 parameters (repo_name, file_path, content, message). The description adds no meaning beyond the schema, as it doesn't explain parameter interactions or usage nuances. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Push content to a GitHub repository' states a clear verb ('push') and resource ('GitHub repository'), but it's vague about what 'push' entails (e.g., creating/updating files, committing changes) and doesn't distinguish it from sibling tools like 'create_repo' (which likely creates repositories) or 'get_user' (which likely retrieves user data). It's not tautological, but lacks specificity.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing repository), exclusions (e.g., not for creating repos), or compare to siblings like 'create_repo' for repository creation. Usage is implied by the action but without explicit context.

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/oghenetejiriorukpegmail/github-mcp'

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