Skip to main content
Glama
gabrielserrao

pyResToolbox MCP Server

gas_density

Calculate gas density at reservoir conditions using real gas equation of state for gradient calculations, well pressure analysis, and material balance in petroleum engineering.

Instructions

Calculate gas density (ρg) at reservoir conditions.

CRITICAL GAS PVT PROPERTY - Computes gas density from real gas equation of state. Essential for gradient calculations, well pressure analysis, and material balance. Gas density increases significantly with pressure due to compressibility.

Parameters:

  • sg (float, required): Gas specific gravity (air=1.0). Valid: 0.55-3.0. Typical: 0.6-1.2. Example: 0.7.

  • degf (float, required): Reservoir temperature in °F. Valid: -460 to 1000. Typical: 100-400°F. Example: 180.0.

  • p (float or list, required): Pressure(s) in psia. Must be > 0. Can be scalar or array. Example: 3500.0 or [1000, 2000, 3000, 4000].

  • h2s (float, optional, default=0.0): H2S mole fraction (0-1). Typical: 0-0.05. Example: 0.02.

  • co2 (float, optional, default=0.0): CO2 mole fraction (0-1). Typical: 0-0.20. Example: 0.05.

  • n2 (float, optional, default=0.0): N2 mole fraction (0-1). Typical: 0-0.10. Example: 0.01.

  • zmethod (str, optional, default="DAK"): Z-factor method for density calculation. Options: "DAK", "HY", "WYW", "BUR". DAK recommended.

Density Formula: ρg = (P × MW) / (Z × R × T)

Where:

  • P = pressure (psia)

  • MW = molecular weight = sg × 28.97 lb/lbmol

  • Z = gas compressibility factor

  • R = gas constant = 10.732 psia·ft³/(lbmol·°R)

  • T = temperature (°R = °F + 460)

Density Behavior:

  • Increases with pressure (gas compresses)

  • Decreases with temperature (gas expands)

  • Typical range: 5-20 lb/cuft at reservoir conditions

  • At standard conditions: ~0.05-0.1 lb/cuft

Returns: Dictionary with:

  • value (float or list): Density in lb/cuft (matches input p shape)

  • method (str): Z-factor method used

  • units (str): "lb/cuft"

  • inputs (dict): Echo of input parameters

Common Mistakes:

  • Using separator temperature instead of reservoir temperature

  • Pressure in barg/psig instead of psia (must be absolute)

  • Not accounting for non-hydrocarbon fractions

  • Using ideal gas law (Z=1) instead of real gas (Z<1)

  • Temperature in Celsius instead of Fahrenheit

Example Usage:

{
    "sg": 0.7,
    "degf": 180.0,
    "p": [1000, 2000, 3000, 4000],
    "h2s": 0.0,
    "co2": 0.05,
    "n2": 0.01,
    "zmethod": "DAK"
}

Result: Density increases from ~8 lb/cuft at 1000 psia to ~18 lb/cuft at 4000 psia.

Note: Gas density is much lower than oil density (typically 5-20 lb/cuft vs 40-60 lb/cuft). Always use reservoir conditions. Account for all non-hydrocarbon components - they significantly affect molecular weight and density.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'gas_density' tool. It takes a GasDensityRequest, computes density using pyrestoolbox.gas.gas_den with specified Z-factor method, handles array inputs, and returns structured response with value, method, units, and inputs.
    def gas_density(request: GasDensityRequest) -> dict:
        """Calculate gas density (ρg) at reservoir conditions.
    
        **CRITICAL GAS PVT PROPERTY** - Computes gas density from real gas equation of state.
        Essential for gradient calculations, well pressure analysis, and material balance.
        Gas density increases significantly with pressure due to compressibility.
    
        **Parameters:**
        - **sg** (float, required): Gas specific gravity (air=1.0). Valid: 0.55-3.0.
          Typical: 0.6-1.2. Example: 0.7.
        - **degf** (float, required): Reservoir temperature in °F. Valid: -460 to 1000.
          Typical: 100-400°F. Example: 180.0.
        - **p** (float or list, required): Pressure(s) in psia. Must be > 0.
          Can be scalar or array. Example: 3500.0 or [1000, 2000, 3000, 4000].
        - **h2s** (float, optional, default=0.0): H2S mole fraction (0-1).
          Typical: 0-0.05. Example: 0.02.
        - **co2** (float, optional, default=0.0): CO2 mole fraction (0-1).
          Typical: 0-0.20. Example: 0.05.
        - **n2** (float, optional, default=0.0): N2 mole fraction (0-1).
          Typical: 0-0.10. Example: 0.01.
        - **zmethod** (str, optional, default="DAK"): Z-factor method for density calculation.
          Options: "DAK", "HY", "WYW", "BUR". DAK recommended.
    
        **Density Formula:**
        ρg = (P × MW) / (Z × R × T)
    
        Where:
        - P = pressure (psia)
        - MW = molecular weight = sg × 28.97 lb/lbmol
        - Z = gas compressibility factor
        - R = gas constant = 10.732 psia·ft³/(lbmol·°R)
        - T = temperature (°R = °F + 460)
    
        **Density Behavior:**
        - Increases with pressure (gas compresses)
        - Decreases with temperature (gas expands)
        - Typical range: 5-20 lb/cuft at reservoir conditions
        - At standard conditions: ~0.05-0.1 lb/cuft
    
        **Returns:**
        Dictionary with:
        - **value** (float or list): Density in lb/cuft (matches input p shape)
        - **method** (str): Z-factor method used
        - **units** (str): "lb/cuft"
        - **inputs** (dict): Echo of input parameters
    
        **Common Mistakes:**
        - Using separator temperature instead of reservoir temperature
        - Pressure in barg/psig instead of psia (must be absolute)
        - Not accounting for non-hydrocarbon fractions
        - Using ideal gas law (Z=1) instead of real gas (Z<1)
        - Temperature in Celsius instead of Fahrenheit
    
        **Example Usage:**
        ```python
        {
            "sg": 0.7,
            "degf": 180.0,
            "p": [1000, 2000, 3000, 4000],
            "h2s": 0.0,
            "co2": 0.05,
            "n2": 0.01,
            "zmethod": "DAK"
        }
        ```
        Result: Density increases from ~8 lb/cuft at 1000 psia to ~18 lb/cuft at 4000 psia.
    
        **Note:** Gas density is much lower than oil density (typically 5-20 lb/cuft
        vs 40-60 lb/cuft). Always use reservoir conditions. Account for all non-hydrocarbon
        components - they significantly affect molecular weight and density.
        """
        method_enum = getattr(z_method, request.zmethod)
    
        den = gas.gas_den(
            sg=request.sg,
            degf=request.degf,
            p=request.p,
            h2s=request.h2s,
            co2=request.co2,
            n2=request.n2,
            zmethod=method_enum,
        )
    
        # Convert numpy array to list for JSON serialization
        if isinstance(den, np.ndarray):
            value = den.tolist()
        else:
            value = float(den)
    
        return {
            "value": value,
            "method": request.zmethod,
            "units": "lb/cuft",
            "inputs": request.model_dump(),
        }
  • Pydantic schema (BaseModel) defining input parameters and validation for the gas_density tool, including sg, degf, p (scalar or list), h2s, co2, n2, zmethod with field validators for positive pressure.
    class GasDensityRequest(BaseModel):
        """Request model for gas density calculation."""
    
        sg: float = Field(
            ..., ge=0.5, le=2.0, description="Gas specific gravity (air=1, dimensionless)"
        )
        degf: float = Field(
            ..., gt=-460, lt=1000, description="Temperature (degrees Fahrenheit)"
        )
        p: Union[float, List[float]] = Field(
            ..., description="Pressure (psia) - scalar or array"
        )
        h2s: float = Field(
            0.0, ge=0.0, le=1.0, description="H2S mole fraction (dimensionless)"
        )
        co2: float = Field(
            0.0, ge=0.0, le=1.0, description="CO2 mole fraction (dimensionless)"
        )
        n2: float = Field(
            0.0, ge=0.0, le=1.0, description="N2 mole fraction (dimensionless)"
        )
        zmethod: Literal["DAK", "HY", "WYW", "BUR"] = Field(
            "DAK", description="Z-factor calculation method"
        )
    
        @field_validator("p")
        @classmethod
        def validate_pressure(cls, v):
            """Validate pressure values."""
            if isinstance(v, list):
                if not all(p > 0 for p in v):
                    raise ValueError("All pressure values must be positive")
            else:
                if v <= 0:
                    raise ValueError("Pressure must be positive")
            return v
  • Call to register_gas_tools(mcp) which defines and registers all gas tools including gas_density via @mcp.tool() decorators within the function.
    register_gas_tools(mcp)
  • The register_gas_tools function where the gas_density tool is defined with @mcp.tool() decorator for registration.
    def register_gas_tools(mcp: FastMCP) -> None:
Behavior5/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 and excels. It details the density formula, behavior (e.g., 'Increases with pressure', 'Decreases with temperature'), typical ranges, and critical notes on units and conditions. It also warns about common mistakes, providing rich context beyond basic functionality.

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

Conciseness3/5

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

The description is well-structured with sections like 'Parameters', 'Density Formula', and 'Common Mistakes', but it is lengthy with some redundant information (e.g., repeating parameter details in the example). While informative, it could be more front-loaded and concise, as not all sentences earn their place equally.

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

Completeness5/5

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

For a complex tool with 0% schema description coverage and no annotations, the description is highly complete. It covers purpose, parameters, formula, behavior, returns (though an output schema exists), common mistakes, and example usage. It provides all necessary context for an AI agent to use the tool correctly.

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

Parameters5/5

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

Given 0% schema description coverage, the description fully compensates by providing detailed parameter semantics. Each parameter is explained with descriptions, valid ranges, typical values, examples, and optionality. It adds meaning beyond the schema, such as the significance of 'zmethod' options and the impact of non-hydrocarbon fractions.

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

Purpose5/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 with a specific verb ('Calculate') and resource ('gas density (ρg) at reservoir conditions'), distinguishing it from siblings like 'oil_density' or 'gas_compressibility'. It emphasizes this as a 'CRITICAL GAS PVT PROPERTY' for specific applications like gradient calculations and material balance.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (e.g., 'Essential for gradient calculations, well pressure analysis, and material balance') and includes a 'Common Mistakes' section that implicitly guides usage by highlighting pitfalls. However, it does not explicitly compare to alternatives like 'gas_z_factor' or specify when not to use it.

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/gabrielserrao/pyrestoolbox-mcp'

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