Skip to main content
Glama

get_keys_tool

Extract all localization keys from Xcode String Catalog (.xcstrings) files to manage iOS/macOS project translations.

Instructions

MCP tool to get all localization keys from xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: str: List of all keys or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • The main handler function for the 'get_keys_tool' MCP tool. It is decorated with @mcp.tool() which handles both registration and execution. Validates the input file, extracts keys using the helper function, and formats the output as a string.
    @mcp.tool() def get_keys_tool(file_path: str) -> str: """ MCP tool to get all localization keys from xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: str: List of all keys or error message """ try: if not validate_xcstrings_file(file_path): return f"Error: Invalid file path or not an .xcstrings file: {file_path}" keys = extract_base_keys(file_path) return f"Found {len(keys)} keys:\n" + "\n".join(keys) except Exception as e: return format_error_message(e, "Failed to get keys")
  • Helper function that implements the core logic of extracting all localization keys from the .xcstrings JSON file by loading and parsing the 'strings' dictionary keys.
    def extract_base_keys(file_path: str) -> List[str]: """ Extract all string keys from a Localizable.xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: List[str]: List of all string keys Raises: FileNotFoundError: If the file doesn't exist json.JSONDecodeError: If the file is not valid JSON KeyError: If the file doesn't have the expected structure """ if not os.path.exists(file_path): raise FileNotFoundError(f"File not found: {file_path}") with open(file_path, 'r', encoding='utf-8') as f: data = json.load(f) if 'strings' not in data: return [] return list(data['strings'].keys())
  • Utility helper used by the handler to validate that the input file path exists and ends with .xcstrings extension.
    def validate_xcstrings_file(file_path: str) -> bool: """ Validate if a file exists and has the .xcstrings extension. Args: file_path (str): Path to check Returns: bool: True if valid, False otherwise """ if not os.path.exists(file_path): return False if not file_path.lower().endswith('.xcstrings'): return False return True
  • Utility helper used by the handler to format error messages consistently.
    def format_error_message(error: Exception, context: str = "") -> str: """ Format error messages consistently. Args: error (Exception): The exception to format context (str): Additional context for the error Returns: str: Formatted error message """

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/iamnotagentleman/localizable-xcstrings-mcp'

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