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; }

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