Skip to main content
Glama

xfoil.compute_polar

Calculate lift and drag coefficients for airfoils by running XFOIL polar sweeps at specified Reynolds numbers and angles of attack.

Instructions

Run XFOIL for an airfoil at specified Reynolds angle of attack sweep. Input airfoil coordinates or NACA code plus sweep parameters. Returns lift/drag polar tables and solver metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
csvYesCSV text containing XFOIL polar data

Implementation Reference

  • Core handler function that runs XFOIL subprocess, handles output, and returns formatted CSV polar data.
    def compute_polar(request: PolarRequest) -> PolarResponse:
        """Run XFOIL with the provided parameters and return a CSV payload."""
    
        script, polar_path = _prepare_script(request)
        try:
            result = subprocess.run(
                [XFOIL_BIN],
                input=script.encode("utf-8"),
                cwd=polar_path.parent,
                check=False,
                capture_output=True,
            )
        except FileNotFoundError as exc:  # pragma: no cover
            raise RuntimeError("XFOIL binary not found") from exc
    
        if not polar_path.exists():
            raise RuntimeError(
                "XFOIL did not create the polar output",
            )
    
        if result.returncode != 0:
            # XFOIL often exits with code 2 even when the polar file is valid. We keep
            # the output but annotate the CSV with a comment so downstream users are
            # aware of the non-zero status.
            warning_comment = f"# xfoil exit code {result.returncode}"
        else:
            warning_comment = None
    
        lines = polar_path.read_text(encoding="utf-8").splitlines()
        if warning_comment:
            lines.insert(0, warning_comment)
    
        rows = list(csv.reader(lines))
        if rows and rows[0] and "alpha" not in rows[0][0].lower():
            rows.insert(0, ["alpha", "CL", "CD", "CM"])
    
        csv_text = "\n".join(",".join(row) for row in rows)
        return PolarResponse(csv=csv_text)
  • Tool registration using FastMCP @app.tool decorator, which delegates to compute_polar.
    @app.tool(
        name="xfoil.compute_polar",
        description=(
            "Run XFOIL for an airfoil at specified Reynolds angle of attack sweep. "
            "Input airfoil coordinates or NACA code plus sweep parameters. "
            "Returns lift/drag polar tables and solver metadata."
        ),
        meta={"version": "0.1.1", "categories": ["aero", "analysis"]},
    )
    def polar(request: PolarRequest) -> PolarResponse:
        return compute_polar(request)
  • Pydantic input schema defining parameters for the XFOIL polar computation.
    class PolarRequest(BaseModel):
        """Parameters required to run an XFOIL polar sweep."""
    
        airfoil_name: str = Field(..., description="Identifier used when writing temporary files")
        airfoil_data: str = Field(..., description="Airfoil coordinate data in XFOIL DAT format")
        alphas: list[float] = Field(..., description="Angles of attack to analyse")
        reynolds: float = Field(..., gt=0.0, description="Reynolds number")
        mach: float = Field(0.0, ge=0.0, description="Mach number")
        iterations: int = Field(200, ge=10, le=10000, description="Maximum solver iterations")
  • Pydantic output schema for the CSV polar data response.
    class PolarResponse(BaseModel):
        """CSV payload returned by `compute_polar`."""
    
        csv: str = Field(..., description="CSV text containing XFOIL polar data")
  • Helper function to prepare the XFOIL input script and temporary file paths.
    def _prepare_script(request: PolarRequest) -> tuple[str, Path]:
        tmpdir = Path(tempfile.mkdtemp(prefix="xfoil_mcp_"))
        airfoil_path = tmpdir / f"{request.airfoil_name}.dat"
        polar_path = tmpdir / "polar.txt"
        airfoil_path.write_text(request.airfoil_data, encoding="utf-8")
    
        airfoil_name = airfoil_path.name
        polar_name = polar_path.name
    
        commands: Iterable[str] = [
            f"LOAD {airfoil_name}",
            "PANE",
            "OPER",
            f"VISC {request.reynolds}",
            f"MACH {request.mach}",
            f"ITER {request.iterations}",
            "PACC",
            polar_name,
            "",
        ]
        alpha_cmds = [f"ALFA {alpha}" for alpha in request.alphas]
        if not alpha_cmds:
            raise RuntimeError("At least one angle of attack must be supplied")
    
        footer = ["PACC", "", "QUIT"]
        script = "\n".join([*commands, *alpha_cmds, *footer]) + "\n"
        return script, polar_path
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the tool 'Returns lift/drag polar tables and solver metadata,' which hints at output but lacks details on performance (e.g., computational cost, error handling, or runtime behavior). For a tool involving complex simulations, this is insufficient to inform safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, with two sentences that efficiently cover purpose and output. Every sentence adds value, avoiding redundancy. It could be slightly more structured for clarity but remains appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (simulation with multiple parameters) and no annotations, the description is moderately complete but has gaps. It mentions output types, which aligns with the presence of an output schema, but lacks behavioral context and detailed parameter guidance. For a tool with such technical depth, more context would be beneficial.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal parameter semantics beyond the schema, mentioning 'airfoil coordinates or NACA code plus sweep parameters' and 'Reynolds angle of attack sweep,' which loosely maps to schema fields. However, with 0% schema description coverage, it doesn't fully compensate by explaining parameter roles, formats, or interactions, leaving gaps in understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Run XFOIL for an airfoil at specified Reynolds angle of attack sweep.' It specifies the verb ('Run XFOIL'), resource ('airfoil'), and scope ('polar sweep'), though it doesn't differentiate from siblings as none exist. The description is specific but could be slightly more precise about the computational nature.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or constraints. It mentions input options ('airfoil coordinates or NACA code') but lacks explicit usage context, such as typical scenarios or limitations, leaving the agent with minimal operational direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Three-Little-Birds/xfoil-mcp'

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