Skip to main content
Glama
torshepherd

Compiler Explorer MCP

by torshepherd

list_compilers_for_language

Retrieve available compilers for a programming language to enable code compilation and optimization analysis.

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
NameRequiredDescriptionDefault
languageYes

Implementation Reference

  • The main handler function for the 'list_compilers_for_language' tool, decorated with @mcp.tool() for registration. It fetches compilers for the specified language using ce_client, extracts unversioned names, and returns a unique list.
    @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))
  • Helper utility function used by the handler 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()
        )

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/torshepherd/compiler-explorer-mcp'

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