Skip to main content
Glama

create_predefined_metric

Generate predefined spacetime metrics for symbolic algebra calculations, enabling precise mathematical modeling and analysis within the Symbolic Algebra MCP Server environment.

Instructions

Creates a predefined spacetime metric.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
metric_nameYes

Implementation Reference

  • The core handler function decorated with @mcp.tool(), which implements the logic to create predefined metrics from EinsteinPy library based on the input metric name or Metric enum value. It validates the input, maps to the appropriate class, instantiates it, stores in global state, and returns the metric key.
    def create_predefined_metric(metric_name: str) -> str: """Creates a predefined spacetime metric from einsteinpy.symbolic.predefined. Args: metric_name: The name of the metric to create (e.g., "AntiDeSitter", "Schwarzschild"). Returns: A key for the stored metric object. """ try: # Handle if metric_name is actually a Metric enum already if isinstance(metric_name, Metric): metric_enum = metric_name else: # First try direct mapping to enum value metric_enum = None # Try to match by enum value (the string in the enum definition) for metric in Metric: if metric.value.lower() == metric_name.lower(): metric_enum = metric break # If it didn't match any enum value, try to match by enum name if metric_enum is None: try: # Try exact name match metric_enum = Metric[metric_name.upper()] except KeyError: # Try normalized name (remove spaces, underscores, etc.) normalized_name = "".join( c.upper() for c in metric_name if c.isalnum() ) for m in Metric: if ( "".join(c for c in m.name if c.isalnum()) == normalized_name ): metric_enum = m break if metric_enum is None: return f"Error: Invalid metric name '{metric_name}'. Available metrics are: {', '.join(m.value for m in Metric)}" metric_map = { Metric.SCHWARZSCHILD: Schwarzschild, Metric.MINKOWSKI: Minkowski, Metric.MINKOWSKI_CARTESIAN: MinkowskiCartesian, Metric.KERR_NEWMAN: KerrNewman, Metric.KERR: Kerr, Metric.ANTI_DE_SITTER: AntiDeSitter, Metric.DE_SITTER: DeSitter, Metric.REISSNER_NORDSTROM: ReissnerNordstorm, } if metric_enum not in metric_map: return f"Error: Metric '{metric_enum.value}' not implemented. Available metrics are: {', '.join(m.value for m in Metric)}" metric_class = metric_map[metric_enum] metric_obj = metric_class() metric_key = f"metric_{metric_enum.value}" metrics[metric_key] = metric_obj expressions[metric_key] = metric_obj.tensor() return metric_key except Exception as e: return f"Error creating metric: {str(e)}"
  • The Metric Enum provides the type definitions for valid predefined metric names, used for input validation and mapping in the tool handler.
    class Metric(Enum): ALCUBIERRE_WARP = "AlcubierreWarp" BARRIOLA_VILEKIN = "BarriolaVilekin" BERTOTTI_KASNER = "BertottiKasner" BESSEL_GRAVITATIONAL_WAVE = "BesselGravitationalWave" C_METRIC = "CMetric" DAVIDSON = "Davidson" ANTI_DE_SITTER = "AntiDeSitter" ANTI_DE_SITTER_STATIC = "AntiDeSitterStatic" DE_SITTER = "DeSitter" ERNST = "Ernst" GODEL = "Godel" JANIS_NEWMAN_WINICOUR = "JanisNewmanWinicour" MINKOWSKI = "Minkowski" MINKOWSKI_CARTESIAN = "MinkowskiCartesian" MINKOWSKI_POLAR = "MinkowskiPolar" KERR = "Kerr" KERR_NEWMAN = "KerrNewman" REISSNER_NORDSTROM = "ReissnerNordstorm" SCHWARZSCHILD = "Schwarzschild"
  • The metric_map dictionary maps Metric enum values to the corresponding EinsteinPy predefined metric classes.
    metric_map = { Metric.SCHWARZSCHILD: Schwarzschild, Metric.MINKOWSKI: Minkowski, Metric.MINKOWSKI_CARTESIAN: MinkowskiCartesian, Metric.KERR_NEWMAN: KerrNewman, Metric.KERR: Kerr, Metric.ANTI_DE_SITTER: AntiDeSitter, Metric.DE_SITTER: DeSitter, Metric.REISSNER_NORDSTROM: ReissnerNordstorm, }

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/sdiehl/sympy-mcp'

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