Skip to content

feat: add a framework for translations #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged

Conversation

SamMorrowDrums
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums commented Mar 19, 2025

Closes #24

i18n / Overriding descriptions

The descriptions of the tools can be overridden by creating a github-mcp-server.json file in the same directory as the binary.
The file should contain a JSON object with the tool names as keys and the new descriptions as values.
For example:

{
  "TOOL_ADD_ISSUE_COMMENT_DESCRIPTION": "an alternative description",
  "TOOL_CREATE_BRANCH_DESCRIPTION": "Create a new branch in a GitHub repository"
}

You can create an export of the current translations by running the binary with the --export-translations flag.
This flag will preserve any translations/overrides you have made, while adding any new translations that have been added to the binary since the last time you exported.

./github-mcp-server --export-translations
cat github-mcp-server.json

You can also use ENV vars to override the descriptions. The environment variable names are the same as the keys in the JSON file,
prefixed with GITHUB_MCP_ and all uppercase.
For example, to override the TOOL_ADD_ISSUE_COMMENT_DESCRIPTION tool, you can set the following environment variable:

export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description"

The JSON Dump

So far, I have drawn the line at descriptions, but parameters can easily be added, I just didn't want this PR to touch any more parts. This is the whole shebang:

{
  "RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION": "Repository Content for specific branch",
  "RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION": "Repository Content for specific commit",
  "RESOURCE_REPOSITORY_CONTENT_DESCRIPTION": "Repository Content",
  "RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION": "Repository Content for specific pull request",
  "RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION": "Repository Content for specific tag",
  "TOOL_ADD_ISSUE_COMMENT_DESCRIPTION": "Add a comment to an existing issue",
  "TOOL_CREATE_BRANCH_DESCRIPTION": "Create a new branch in a GitHub repository",
  "TOOL_CREATE_OR_UPDATE_FILE_DESCRIPTION": "Create or update a single file in a GitHub repository",
  "TOOL_CREATE_REPOSITORY_DESCRIPTION": "Create a new GitHub repository in your account",
  "TOOL_FORK_REPOSITORY_DESCRIPTION": "Fork a GitHub repository to your account or specified organization",
  "TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION": "Get details of a specific code scanning alert in a GitHub repository.",
  "TOOL_GET_FILE_CONTENTS_DESCRIPTION": "Get the contents of a file or directory from a GitHub repository",
  "TOOL_GET_ISSUE_DESCRIPTION": "Get details of a specific issue in a GitHub repository.",
  "TOOL_GET_ME_DESCRIPTION": "Get details of the authenticated GitHub user",
  "TOOL_GET_PULL_REQUEST_COMMENTS_DESCRIPTION": "Get the review comments on a pull request",
  "TOOL_GET_PULL_REQUEST_DESCRIPTION": "Get details of a specific pull request",
  "TOOL_GET_PULL_REQUEST_FILES_DESCRIPTION": "Get the list of files changed in a pull request",
  "TOOL_GET_PULL_REQUEST_REVIEWS_DESCRIPTION": "Get the reviews on a pull request",
  "TOOL_GET_PULL_REQUEST_STATUS_DESCRIPTION": "Get the combined status of all status checks for a pull request",
  "TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION": "List code scanning alerts in a GitHub repository.",
  "TOOL_LIST_COMMITS_DESCRIPTION": "Get list of commits of a branch in a GitHub repository",
  "TOOL_LIST_PULL_REQUESTS_DESCRIPTION": "List and filter repository pull requests",
  "TOOL_MERGE_PULL_REQUEST_DESCRIPTION": "Merge a pull request",
  "TOOL_SEARCH_CODE_DESCRIPTION": "Search for code across GitHub repositories",
  "TOOL_SEARCH_ISSUES_DESCRIPTION": "Search for issues and pull requests across GitHub repositories",
  "TOOL_SEARCH_REPOSITORIES_DESCRIPTION": "Search for GitHub repositories",
  "TOOL_SEARCH_USERS_DESCRIPTION": "Search for GitHub users",
  "TOOL_UPDATE_PULL_REQUEST_BRANCH_DESCRIPTION": "Update a pull request branch with the latest changes from the base branch"
}

Live example tools/list

An example running with a file, and an env var:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "tools": [
      {
        "description": "an alternative description",
        "inputSchema": {
          "type": "object",
          "properties": {
            "body": {
              "description": "Comment text",
              "type": "string"
            },
            "issue_number": {
              "description": "Issue number to comment on",
              "type": "number"
            },
            "owner": {
              "description": "Repository owner",
              "type": "string"
            },
            "repo": {
              "description": "Repository name",
              "type": "string"
            }
          },
          "required": [
            "owner",
            "repo",
            "issue_number",
            "body"
          ]
        },
        "name": "add_issue_comment"
      },
      {
        "description": "OVERRIDE DESCRIPTION",
        "inputSchema": {
          "type": "object",
          "properties": {
            "branch": {
              "description": "Name for new branch",
              "type": "string"
            },
            "from_branch": {
              "description": "Source branch (defaults to repo default)",
              "type": "string"
            },
            "owner": {
              "description": "Repository owner",
              "type": "string"
            },
            "repo": {
              "description": "Repository name",
              "type": "string"
            }
          },
          "required": [
            "owner",
            "repo",
            "branch"
          ]
        },
        "name": "create_branch"
      },
      ...
    ]
  }
}

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a new translation framework that enables overriding tool and resource descriptions through environment variables and JSON configuration. The key changes include updating all GitHub tool and resource functions to accept a translation function parameter, modifying tests to pass a default translation function, and adding preliminary translation support in the server initialization.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/github/server.go Updated NewServer to retrieve and pass the translation helper.
pkg/github/repositories.go Updated tool functions to accept the translation function.
pkg/github/search.go Updated search tool functions to use the translation function.
pkg/github/issues.go Updated issue tool functions to use the translation function.
pkg/github/pullrequests.go Updated pull request tool functions to accept the translation function.
pkg/github/code_scanning.go Updated code scanning tool functions to use the translation function.
Various test files Modified test cases to pass the default translation function.

Tip: Leave feedback on Copilot's review comments with the 👎 and 👍 buttons to help improve review quality. Learn more

@SamMorrowDrums SamMorrowDrums changed the title Add a framework for translations feat: add a framework for translations Mar 20, 2025
@SamMorrowDrums SamMorrowDrums merged commit dd46f8a into main Mar 20, 2025
4 checks passed
@SamMorrowDrums SamMorrowDrums deleted the override-text-i18n branch March 20, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User-defined tool descriptions
2 participants