Skip to main content
Glama
IBM

Physics MCP Server

by IBM

calculate_hookes_law

Calculate spring force and elastic potential energy using Hooke's Law. Input spring constant and displacement to get restoring force and stored energy.

Instructions

Calculate spring force using Hooke's Law: F = -kx.

The restoring force is proportional to displacement from equilibrium.
Fundamental for springs, elastic materials, and simple harmonic motion.

Args:
    spring_constant: Spring constant k in N/m (stiffness)
    displacement: Displacement from equilibrium in meters

Returns:
    Dict containing:
        - force: Restoring force magnitude in Newtons
        - potential_energy: Elastic potential energy in Joules

Tips for LLMs:
    - Stiffer spring → larger k → more force for same displacement
    - Potential energy stored in spring: PE = (1/2)kx²
    - Negative sign in F = -kx means force opposes displacement

Example - Compressing a car spring:
    result = await calculate_hookes_law(
        spring_constant=10000,  # N/m (stiff car spring)
        displacement=0.05  # 5cm compression
    )
    # Force = 500 N, PE = 12.5 J

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spring_constantYes
displacementYes

Implementation Reference

  • Core calculation function that implements Hooke's Law F = |kx| and potential energy PE = 0.5*k*x^2. Takes a HookesLawRequest pydantic model and returns a HookesLawResponse.
    def calculate_hookes_law(request: HookesLawRequest) -> HookesLawResponse:
        """Calculate spring force using Hooke's Law: F = -kx.
    
        Args:
            request: Hooke's Law request
    
        Returns:
            Restoring force and potential energy
        """
        k = request.spring_constant
        x = request.displacement
    
        force = k * abs(x)  # Magnitude only
        potential_energy = 0.5 * k * x * x
    
        return HookesLawResponse(force=force, potential_energy=potential_energy)
  • MCP tool wrapper for calculate_hookes_law. Decorated with @tool, accepts spring_constant and displacement as float parameters, delegates to the core calculation function via the 'from ..oscillations import' path.
    @tool  # type: ignore[arg-type]
    async def calculate_hookes_law(
        spring_constant: float,
        displacement: float,
    ) -> dict:
        """Calculate spring force using Hooke's Law: F = -kx.
    
        The restoring force is proportional to displacement from equilibrium.
        Fundamental for springs, elastic materials, and simple harmonic motion.
    
        Args:
            spring_constant: Spring constant k in N/m (stiffness)
            displacement: Displacement from equilibrium in meters
    
        Returns:
            Dict containing:
                - force: Restoring force magnitude in Newtons
                - potential_energy: Elastic potential energy in Joules
    
        Tips for LLMs:
            - Stiffer spring → larger k → more force for same displacement
            - Potential energy stored in spring: PE = (1/2)kx²
            - Negative sign in F = -kx means force opposes displacement
    
        Example - Compressing a car spring:
            result = await calculate_hookes_law(
                spring_constant=10000,  # N/m (stiff car spring)
                displacement=0.05  # 5cm compression
            )
            # Force = 500 N, PE = 12.5 J
        """
        from ..oscillations import HookesLawRequest, calculate_hookes_law as calc_hookes
    
        request = HookesLawRequest(
            spring_constant=spring_constant,
            displacement=displacement,
        )
        response = calc_hookes(request)
        return response.model_dump()
  • HookesLawRequest pydantic model with spring_constant (gt=0.0) and displacement float fields for input validation.
    class HookesLawRequest(BaseModel):
        """Request for Hooke's Law calculation."""
    
        spring_constant: float = Field(..., description="Spring constant k in N/m", gt=0.0)
        displacement: float = Field(..., description="Displacement from equilibrium in meters")
  • HookesLawResponse pydantic model with force and potential_energy float fields for the output.
    class HookesLawResponse(BaseModel):
        """Response for Hooke's Law calculation."""
    
        force: float = Field(..., description="Restoring force magnitude in Newtons")
        potential_energy: float = Field(..., description="Elastic potential energy in Joules")
Behavior5/5

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

Despite no annotations, the description fully discloses behavior: the formula, parameter meanings, return values, and even the negative sign implication. It is completely transparent.

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

Conciseness5/5

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

The description is concise yet comprehensive, with a clear structure: formula, explanation, parameter details, return, tips, and example. No wasted words.

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?

The description is complete for a simple 2-param tool without output schema. It covers purpose, physics, parameters, return values, and provides an example.

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?

With 0% schema coverage, the description compensates fully by explaining each parameter's units and meaning, and also describes the return structure.

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 it calculates spring force using Hooke's Law, with a clear verb and resource. It distinguishes from siblings like calculate_force by specifying the exact law and application.

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 context for when to use (springs, elastic materials, SHM) and includes tips, but does not explicitly state when not to use or compare to similar tools like calculate_elastic_collision.

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/IBM/chuk-mcp-physics'

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