Localization & Translations
Relevant source files
The following files were used as context for generating this wiki page:
The localization and translation system in the GitHub MCP Server provides a centralized mechanism for managing user-facing strings, tool descriptions, and prompt instructions. By decoupling text content from logic, the system ensures that the Model Context Protocol (MCP) server can provide localized context to AI agents and end-users.
The architecture relies on a helper function pattern where components receive a translation function at initialization. This allows for flexible implementations, including a "Null" helper for testing or default scenarios where original English strings are returned without modification.
Translation Architecture
The system is built around the TranslationHelperFunc type, which serves as the primary interface for retrieving localized strings. This function takes a unique identifier (key) and a default English string.
Core Components
The translation logic is distributed across three main layers: initialization, helper implementation, and tool/prompt registration.
The diagram above shows the relationship between the translation package and the consumers like tools, documentation generators, and tests.
Sources: pkg/translations/translations.go, cmd/github-mcp-server/generate_docs.go:81-83
Key Functions and Types
| Element | Type | Description |
|---|---|---|
TranslationHelperFunc | func(string, string) string | A function type that takes a translation key and a fallback string, returning the localized result. |
NullTranslationHelper | Function | A mock implementation that always returns the default fallback string. Used extensively in tests and documentation generation. |
TranslationHelper() | Function | Returns an active translation helper for production use. |
Sources: pkg/translations/translations.go, pkg/github/repositories_test.go:34, cmd/github-mcp-server/generate_docs.go:81
Implementation in Tools and Prompts
Localization is integrated directly into the definition of MCP tools and prompts. During the registration phase, the TranslationHelperFunc is passed to the tool constructors to localize descriptions and annotations.
Tool Localization
Tools use the translation helper to define their descriptions and titles, which are then exposed to the AI model via the MCP schema.
func ListDiscussions(getGQLClient GetGQLClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_discussions",
mcp.WithDescription(t("TOOL_LIST_DISCUSSIONS_DESCRIPTION", "List discussions for a repository or organisation.")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_DISCUSSIONS_USER_TITLE", "List discussions"),
ReadOnlyHint: ToBoolPtr(true),
}),
// ... parameters
), nil
}
Sources: pkg/github/discussions.go:106-113
Prompt Localization
Prompts utilize the same helper to localize the high-level description of a workflow, ensuring that the AI agent understands the intent of the prompt in the target language.
Sources: pkg/github/workflow_prompts.go:13-15
Automated Documentation Integration
The translation system is a critical component of the generate-docs command. When documentation is updated automatically, the system initializes a TranslationHelper to ensure that the generated README.md and server documentation contain accurate descriptions.
This flow illustrates how the documentation generator uses the translation system to ensure descriptions are correctly retrieved before being written to files.
Sources: cmd/github-mcp-server/generate_docs.go:81-87, cmd/github-mcp-server/generate_docs.go:217-220
Usage in Testing
For unit testing, the project employs a NullTranslationHelper. This avoids dependencies on actual translation files or external localization services during the test suite execution. It ensures that tests are deterministic by verifying the default English strings provided in the source code.
Files utilizing NullTranslationHelper for testing:
pkg/github/repositories_test.go(e.g., lines 34, 1140, 1152)pkg/github/discussions_test.go(e.g., lines 218, 375, 521)pkg/github/repository_resource_test.go(e.g., lines 190, 196, 201)pkg/github/pullrequests_test.go(e.g., lines 25, 102, 608)
Sources: pkg/github/repositories_test.go:34, pkg/github/discussions_test.go:218, pkg/github/repository_resource_test.go:190
Conclusion
The Localization & Translations system provides a standardized, functional approach to string management across the GitHub MCP Server. By utilizing the TranslationHelperFunc pattern, the project maintains a clean separation between implementation logic and user-facing content, supporting both production localization and simplified testing environments.