Skip to main content
Glama

get_languages_tool

Retrieve supported languages from an iOS/macOS Xcode String Catalog (.xcstrings file) to identify available localizations for your project.

Instructions

MCP tool to get supported languages from xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: str: JSON string of supported languages or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Implementation Reference

  • Handler function decorated with @mcp.tool(), which registers the tool and implements the logic: validates the xcstrings file, extracts supported languages using helper function, and returns formatted list or error.
    @mcp.tool() def get_languages_tool(file_path: str) -> str: """ MCP tool to get supported languages from xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: str: JSON string of supported languages or error message """ try: if not validate_xcstrings_file(file_path): return f"Error: Invalid file path or not an .xcstrings file: {file_path}" languages = get_supported_languages(file_path) return f"Supported languages: {', '.join(languages)}" except Exception as e: return format_error_message(e, "Failed to get supported languages")
  • Core helper function that parses the .xcstrings JSON file, extracts sourceLanguage and all localization languages from strings entries, and returns sorted list of unique language codes.
    def get_supported_languages(file_path: str) -> List[str]: """ Extract supported language codes from a Localizable.xcstrings file. Args: file_path (str): Path to the .xcstrings file Returns: List[str]: List of supported language codes 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) languages = set() # Add source language if 'sourceLanguage' in data: languages.add(data['sourceLanguage']) # Extract languages from localizations if 'strings' in data: for key, value in data['strings'].items(): if 'localizations' in value: languages.update(value['localizations'].keys()) return sorted(list(languages))
  • Utility function used by the handler to validate that the provided 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

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