list_compilers_for_language
Retrieve a list of available compilers for a specified programming language, such as 'cpp', 'rust', or others, using the Compiler Explorer MCP server.
Instructions
Get available compilers for a specific programming language.
Args:
language: Programming language to get compilers for (e.g., 'cpp', 'rust')
Returns:
List of unversioned compiler names available for the language
Raises:
HTTPException: If the API request fails
Example:
>>> await list_compilers_for_language("cpp")
["gcc", "clang", "msvc"]
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | Yes |
Implementation Reference
- server.py:283-306 (handler)The core handler function for the 'list_compilers_for_language' tool. It is decorated with @mcp.tool() for registration, fetches compilers for the specified language using CompilerExplorerClient.list_compilers, extracts unversioned names using the helper get_unversioned_compiler_name, and handles errors by raising HTTPException.@mcp.tool() async def list_compilers_for_language(language: str) -> list[str]: """Get available compilers for a specific programming language. Args: language: Programming language to get compilers for (e.g., 'cpp', 'rust') Returns: List of unversioned compiler names available for the language Raises: HTTPException: If the API request fails Example: >>> await list_compilers_for_language("cpp") ["gcc", "clang", "msvc"] """ try: compilers = await ce_client.list_compilers(language) return list( {get_unversioned_compiler_name(c["name"], c["semver"]) for c in compilers} ) except CompilerExplorerError as e: raise HTTPException(status_code=e.status_code, detail=str(e))
- server.py:283-283 (registration)The @mcp.tool() decorator registers the list_compilers_for_language function as an MCP tool.@mcp.tool()
- server.py:196-212 (helper)Helper utility function used by the tool to derive unversioned compiler names from full names and semantic versions.def get_unversioned_compiler_name(compiler_name: str, semver: str) -> str: """Get the unversioned compiler name from the versioned name. Args: compiler_name: Full compiler name including version semver: Version string to remove Returns: Cleaned compiler name without version information Example: >>> get_unversioned_compiler_name("gcc-12.2", "12.2") "gcc" """ return ( compiler_name.replace(semver, "").replace("none", "").replace("()", "").strip() )
- server.py:124-144 (helper)Method in CompilerExplorerClient class that performs the API call to list compilers for a language, used internally by the tool handler.async def list_compilers(self, language: str | None = None) -> list[dict[str, str]]: """Get list of available compilers. Args: language: Optional language filter to get compilers for a specific language Returns: List of dictionaries containing compiler information, each with keys: - id: Unique identifier for the compiler - name: Display name of the compiler - semver: Version string of the compiler - language: Programming language the compiler supports Raises: CompilerExplorerError: If the API request fails """ url = f"{self.base_url}/compilers" if language: url += f"/{language}" return await self._make_request("GET", url)