Skip to main content
Glama
IBM

Physics MCP Server

by IBM

calculate_spring_mass_period

Compute oscillation period, frequency, and angular frequency of a spring-mass system from mass and spring constant.

Instructions

Calculate period of spring-mass system: T = 2π√(m/k).

Natural oscillation frequency of a mass attached to a spring.
Independent of amplitude (for ideal springs).

Args:
    mass: Mass in kg
    spring_constant: Spring constant k in N/m

Returns:
    Dict containing:
        - period: T in seconds
        - frequency: f in Hz
        - angular_frequency: ω in rad/s

Tips for LLMs:
    - Heavier mass → longer period (slower oscillation)
    - Stiffer spring → shorter period (faster oscillation)
    - ω = 2πf = √(k/m)

Example - Mass on spring:
    result = await calculate_spring_mass_period(
        mass=0.5,  # 500g mass
        spring_constant=20.0  # N/m
    )
    # T ≈ 0.99s, f ≈ 1.01 Hz

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
massYes
spring_constantYes

Implementation Reference

  • Core calculation function: computes period T = 2π√(m/k), frequency f = 1/T, and angular frequency ω = √(k/m) for a spring-mass system.
    def calculate_spring_mass_period(request: SpringMassPeriodRequest) -> SpringMassPeriodResponse:
        """Calculate period of spring-mass system: T = 2π√(m/k).
    
        Args:
            request: Spring-mass period request
    
        Returns:
            Period, frequency, and angular frequency
        """
        m = request.mass
        k = request.spring_constant
    
        omega = math.sqrt(k / m)
        T = 2.0 * math.pi / omega
        f = 1.0 / T
    
        return SpringMassPeriodResponse(period=T, frequency=f, angular_frequency=omega)
  • SpringMassPeriodRequest: Pydantic model for input validation (mass > 0, spring_constant > 0).
    class SpringMassPeriodRequest(BaseModel):
        """Request for spring-mass period calculation."""
    
        mass: float = Field(..., description="Mass in kg", gt=0.0)
        spring_constant: float = Field(..., description="Spring constant k in N/m", gt=0.0)
    
    
    class SpringMassPeriodResponse(BaseModel):
        """Response for spring-mass period calculation."""
    
        period: float = Field(..., description="Period T in seconds")
        frequency: float = Field(..., description="Frequency f in Hz")
        angular_frequency: float = Field(..., description="Angular frequency ω in rad/s")
  • SpringMassPeriodResponse: Pydantic model defining output fields (period, frequency, angular_frequency).
    class SpringMassPeriodResponse(BaseModel):
        """Response for spring-mass period calculation."""
    
        period: float = Field(..., description="Period T in seconds")
        frequency: float = Field(..., description="Frequency f in Hz")
        angular_frequency: float = Field(..., description="Angular frequency ω in rad/s")
  • @tool-decorated async wrapper that registers 'calculate_spring_mass_period' as an MCP tool endpoint. Converts function params to request model, calls core calculation, returns dict.
    @tool  # type: ignore[arg-type]
    async def calculate_spring_mass_period(
        mass: float,
        spring_constant: float,
    ) -> dict:
        """Calculate period of spring-mass system: T = 2π√(m/k).
    
        Natural oscillation frequency of a mass attached to a spring.
        Independent of amplitude (for ideal springs).
    
        Args:
            mass: Mass in kg
            spring_constant: Spring constant k in N/m
    
        Returns:
            Dict containing:
                - period: T in seconds
                - frequency: f in Hz
                - angular_frequency: ω in rad/s
    
        Tips for LLMs:
            - Heavier mass → longer period (slower oscillation)
            - Stiffer spring → shorter period (faster oscillation)
            - ω = 2πf = √(k/m)
    
        Example - Mass on spring:
            result = await calculate_spring_mass_period(
                mass=0.5,  # 500g mass
                spring_constant=20.0  # N/m
            )
            # T ≈ 0.99s, f ≈ 1.01 Hz
        """
        from ..oscillations import SpringMassPeriodRequest, calculate_spring_mass_period as calc_period
    
        request = SpringMassPeriodRequest(
            mass=mass,
            spring_constant=spring_constant,
        )
        response = calc_period(request)
        return response.model_dump()
  • Imports math and Pydantic BaseModel used by the spring-mass period calculation.
    import math
    from typing import Literal
    
    from pydantic import BaseModel, Field
    
    
    # ============================================================================
    # Request/Response Models
    # ============================================================================
    
    
    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")
    
    
    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")
    
    
    class SpringMassPeriodRequest(BaseModel):
        """Request for spring-mass period calculation."""
    
        mass: float = Field(..., description="Mass in kg", gt=0.0)
        spring_constant: float = Field(..., description="Spring constant k in N/m", gt=0.0)
    
    
    class SpringMassPeriodResponse(BaseModel):
        """Response for spring-mass period calculation."""
    
        period: float = Field(..., description="Period T in seconds")
        frequency: float = Field(..., description="Frequency f in Hz")
        angular_frequency: float = Field(..., description="Angular frequency ω in rad/s")
Behavior4/5

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

With no annotations, the description carries the full burden, disclosing the physics assumptions (ideal springs, amplitude independence), output structure, and units. However, it lacks explicit mention of parameter limits or potential errors.

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 well-structured with sections for args, returns, tips, and an example, and every sentence provides essential information without redundancy.

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?

Given no annotations, no output schema, and only two parameters, the description covers all necessary aspects: formula, parameters, return values, assumptions, and an example, making it fully complete.

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?

The input schema has no descriptions, but the tool description fully explains each parameter's units and physical meaning, and provides tips on how they affect the results, adding substantial value beyond the schema.

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 explicitly states that the tool calculates the period of a spring-mass system using the formula T = 2π√(m/k), clearly distinguishing it from sibling tools like calculate_pendulum_period and calculate_damped_oscillation.

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 tips on how mass and spring constant affect the period and includes an example, but does not explicitly state when to avoid using this tool (e.g., for non-ideal springs or damped systems).

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