compile_code
Compile source code with chosen compiler and custom options, generate assembly, and filter output for debugging and analysis. Supports multiple languages and libraries for efficient code optimization.
Instructions
Compile source code using specified compiler and options.
Args:
source: Source code to compile
language: Programming language of the source code
compiler: Compiler name or ID to use
ctx: MCP context for logging and error reporting
options: Compiler flags and options
filters: Configuration for filtering compiler output
libraries: List of library dependencies
Returns:
Dictionary containing compilation results with keys:
- code: Exit code of the compilation
- stdout: Standard output from the compiler
- stderr: Standard error from the compiler
- asm: Generated assembly (if applicable)
Raises:
HTTPException: If compilation fails, compiler not found, or API request fails
Example:
>>> result = await compile_code(
... source="int main() { return 0; }",
... language="cpp",
... compiler="gcc",
... ctx=ctx
... )
Input Schema
Name | Required | Description | Default |
---|---|---|---|
compiler | Yes | ||
filters | No | ||
language | Yes | ||
libraries | No | ||
options | No | ||
source | Yes |
Input Schema (JSON Schema)
{
"$defs": {
"CompilationFilters": {
"description": "Configuration for filtering compiler output.\n\nAttributes:\n binary: Include binary output in the response (default: False)\n binary_object: Include binary object output (default: False)\n comment_only: Include only comments from the output (default: True)\n demangle: Demangle C++ symbols in the output (default: True)\n directives: Include compiler directives in the output (default: True)\n execute: Include execution results (default: False)\n intel: Use Intel syntax for assembly output (default: True)\n labels: Include labels in the output (default: True)\n library_code: Include library code in the output (default: False)\n trim: Trim whitespace from the output (default: False)",
"properties": {
"binary": {
"default": false,
"title": "Binary",
"type": "boolean"
},
"binary_object": {
"default": false,
"title": "Binary Object",
"type": "boolean"
},
"comment_only": {
"default": true,
"title": "Comment Only",
"type": "boolean"
},
"demangle": {
"default": true,
"title": "Demangle",
"type": "boolean"
},
"directives": {
"default": true,
"title": "Directives",
"type": "boolean"
},
"execute": {
"default": false,
"title": "Execute",
"type": "boolean"
},
"intel": {
"default": true,
"title": "Intel",
"type": "boolean"
},
"labels": {
"default": true,
"title": "Labels",
"type": "boolean"
},
"library_code": {
"default": false,
"title": "Library Code",
"type": "boolean"
},
"trim": {
"default": false,
"title": "Trim",
"type": "boolean"
}
},
"title": "CompilationFilters",
"type": "object"
},
"Library": {
"description": "Represents a library dependency for compilation.\n\nAttributes:\n id: Unique identifier for the library (e.g., 'boost', 'fmt')\n version: Version string of the library (e.g., '1.76.0')",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
}
},
"required": [
"id",
"version"
],
"title": "Library",
"type": "object"
}
},
"properties": {
"compiler": {
"title": "Compiler",
"type": "string"
},
"filters": {
"$ref": "#/$defs/CompilationFilters",
"default": {
"binary": false,
"binary_object": false,
"comment_only": true,
"demangle": true,
"directives": true,
"execute": false,
"intel": true,
"labels": true,
"library_code": false,
"trim": false
}
},
"language": {
"title": "Language",
"type": "string"
},
"libraries": {
"default": [],
"items": {
"$ref": "#/$defs/Library"
},
"title": "Libraries",
"type": "array"
},
"options": {
"default": "",
"title": "Options",
"type": "string"
},
"source": {
"title": "Source",
"type": "string"
}
},
"required": [
"source",
"language",
"compiler"
],
"title": "compile_codeArguments",
"type": "object"
}