Symbolic Algebra MCP Server
A Model Context Protocol server that enables LLMs to autonomously perform symbolic mathematics and computer algebra through SymPy's functionality for manipulating mathematical expressions and equations.
Tools
solve_linear_system
Solves a system of linear equations using SymPy's linsolve. Args: expr_keys: The keys of the expressions (previously introduced) forming the system. var_names: The names of the variables to solve for. domain: The domain to solve in (Domain.COMPLEX, Domain.REAL, etc.). Defaults to Domain.COMPLEX. Returns: A LaTeX string representing the solution set. Returns an error message string if issues occur.
solve_nonlinear_system
Solves a system of nonlinear equations using SymPy's nonlinsolve. Args: expr_keys: The keys of the expressions (previously introduced) forming the system. var_names: The names of the variables to solve for. domain: The domain to solve in (Domain.COMPLEX, Domain.REAL, etc.). Defaults to Domain.COMPLEX. Returns: A LaTeX string representing the solution set. Returns an error message string if issues occur.
introduce_function
Introduces a SymPy function variable and stores it. Takes a function name and creates a SymPy Function object for use in defining differential equations. Example: {func_name: "f"} will create the function f(x), f(t), etc. that can be used in expressions Returns: The name of the created function.
create_custom_metric
Creates a custom metric tensor from provided components and symbols.
calculate_gradient
Calculates the gradient of a scalar field using SymPy's gradient function. Args: scalar_field_key: The key of the scalar field expression. Example: # First create a coordinate system create_coordinate_system("R") # Create a scalar field f = x^2 + y^2 + z^2 scalar_field = introduce_expression("R_x**2 + R_y**2 + R_z**2") # Calculate gradient grad_result = calculate_gradient(scalar_field) # Returns (2x, 2y, 2z) Returns: A key for the gradient vector field expression.
substitute_expression
Substitutes a variable in an expression with another expression using SymPy's subs method. Args: expr_key: The key of the expression to perform substitution on. var_name: The name of the variable to substitute. replacement_expr_key: The key of the expression to substitute in place of the variable. Example: # Create variables x and y intro("x", [], []) intro("y", [], []) # Create expressions expr1 = introduce_expression("x**2 + y**2") expr2 = introduce_expression("sin(x)") # Substitute y with sin(x) in x^2 + y^2 result = substitute_expression(expr1, "y", expr2) # Results in x^2 + sin^2(x) Returns: A key for the resulting expression after substitution.
intro
Introduces a sympy variable with specified assumptions and stores it. Takes a variable name and a list of positive and negative assumptions.
intro_many
Introduces multiple sympy variables with specified assumptions and stores them. Takes a list of VariableDefinition objects for the 'variables' parameter. Each object in the list specifies: - var_name: The name of the variable (string). - pos_assumptions: A list of positive assumption strings (e.g., ["real", "positive"]). - neg_assumptions: A list of negative assumption strings (e.g., ["complex"]). The JSON payload for the 'variables' argument should be a direct list of these objects, for example: ```json [ { "var_name": "x", "pos_assumptions": ["real", "positive"], "neg_assumptions": ["complex"] }, { "var_name": "y", "pos_assumptions": [], "neg_assumptions": ["commutative"] } ] ``` The assumptions must be consistent, so a real number is not allowed to be non-commutative. Prefer this over intro() for multiple variables because it's more efficient.
introduce_expression
Parses a sympy expression string using available local variables and stores it. Assigns it to either a temporary name (expr_0, expr_1, etc.) or a user-specified global name. Uses Sympy parse_expr to parse the expression string. Applies default Sympy canonicalization rules unless canonicalize is False. For equations (x^2 = 1) make the input string "Eq(x^2, 1") not "x^2 == 1" Examples: {expr_str: "Eq(x^2 + y^2, 1)"} {expr_str: "Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))"} {expr_str: "pi+e", "expr_var_name": "z"}
print_latex_expression
Prints a stored expression in LaTeX format, along with variable assumptions.
solve_algebraically
Solves an equation (expression = 0) algebraically for a given variable. Args: expr_key: The key of the expression (previously introduced) to be solved. solve_for_var_name: The name of the variable (previously introduced) to solve for. domain: The domain to solve in: Domain.COMPLEX, Domain.REAL, Domain.INTEGERS, or Domain.NATURALS. Defaults to Domain.COMPLEX. Returns: A LaTeX string representing the set of solutions. Returns an error message string if issues occur.
dsolve_ode
Solves an ordinary differential equation using SymPy's dsolve function. Args: expr_key: The key of the expression (previously introduced) containing the differential equation. func_name: The name of the function (previously introduced) to solve for. hint: Optional solving method from ODEHint enum. If None, SymPy will try to determine the best method. Example: # First introduce a variable and a function intro("x", [Assumption.REAL], []) introduce_function("f") # Create a second-order ODE: f''(x) + 9*f(x) = 0 expr_key = introduce_expression("Derivative(f(x), x, x) + 9*f(x)") # Solve the ODE result = dsolve_ode(expr_key, "f") # Returns solution with sin(3*x) and cos(3*x) terms Returns: A LaTeX string representing the solution. Returns an error message string if issues occur.
pdsolve_pde
Solves a partial differential equation using SymPy's pdsolve function. Args: expr_key: The key of the expression (previously introduced) containing the PDE. If the expression is not an equation (Eq), it will be interpreted as PDE = 0. func_name: The name of the function (previously introduced) to solve for. This should be a function of multiple variables. Example: # First introduce variables and a function intro("x", [Assumption.REAL], []) intro("y", [Assumption.REAL], []) introduce_function("f") # Create a PDE: 1 + 2*(ux/u) + 3*(uy/u) = 0 expr_key = introduce_expression( "Eq(1 + 2*Derivative(f(x, y), x)/f(x, y) + 3*Derivative(f(x, y), y)/f(x, y), 0)" ) # Solve the PDE result = pdsolve_pde(expr_key, "f") # Returns solution with exponential terms and arbitrary function Returns: A LaTeX string representing the solution. Returns an error message string if issues occur.
create_predefined_metric
Creates a predefined spacetime metric.
search_predefined_metrics
Searches for predefined metrics in einsteinpy.symbolic.predefined.
calculate_tensor
Calculates a tensor from a metric using einsteinpy.symbolic.
print_latex_tensor
Prints a stored tensor expression in LaTeX format.
simplify_expression
Simplifies a mathematical expression using SymPy's simplify function. Args: expr_key: The key of the expression (previously introduced) to simplify. Example: # Introduce variables intro("x", [Assumption.REAL], []) intro("y", [Assumption.REAL], []) # Create an expression to simplify: sin(x)^2 + cos(x)^2 expr_key = introduce_expression("sin(x)**2 + cos(x)**2") # Simplify the expression simplified = simplify_expression(expr_key) # Returns 1 Returns: A key for the simplified expression.
integrate_expression
Integrates an expression with respect to a variable using SymPy's integrate function. Args: expr_key: The key of the expression (previously introduced) to integrate. var_name: The name of the variable to integrate with respect to. lower_bound: Optional lower bound for definite integration. upper_bound: Optional upper bound for definite integration. Example: # Introduce a variable intro("x", [Assumption.REAL], []) # Create an expression to integrate: x^2 expr_key = introduce_expression("x**2") # Indefinite integration indefinite_result = integrate_expression(expr_key, "x") # Returns x³/3 # Definite integration from 0 to 1 definite_result = integrate_expression(expr_key, "x", "0", "1") # Returns 1/3 Returns: A key for the integrated expression.
differentiate_expression
Differentiates an expression with respect to a variable using SymPy's diff function. Args: expr_key: The key of the expression (previously introduced) to differentiate. var_name: The name of the variable to differentiate with respect to. order: The order of differentiation (default is 1 for first derivative). Example: # Introduce a variable intro("x", [Assumption.REAL], []) # Create an expression to differentiate: x^3 expr_key = introduce_expression("x**3") # First derivative first_deriv = differentiate_expression(expr_key, "x") # Returns 3x² # Second derivative second_deriv = differentiate_expression(expr_key, "x", 2) # Returns 6x Returns: A key for the differentiated expression.
create_coordinate_system
Creates a 3D coordinate system for vector calculus operations. Args: name: The name for the coordinate system. coord_names: Optional list of coordinate names (3 names for x, y, z). If not provided, defaults to [name+'_x', name+'_y', name+'_z']. Example: # Create a coordinate system coord_sys = create_coordinate_system("R") # Creates a coordinate system R with coordinates R_x, R_y, R_z # Create a coordinate system with custom coordinate names coord_sys = create_coordinate_system("C", ["rho", "phi", "z"]) Returns: The name of the created coordinate system.
create_vector_field
Creates a vector field in the specified coordinate system. Args: coord_sys_name: The name of the coordinate system to use. component_x: String expression for the x-component of the vector field. component_y: String expression for the y-component of the vector field. component_z: String expression for the z-component of the vector field. Example: # First create a coordinate system create_coordinate_system("R") # Create a vector field F = (y, -x, z) vector_field = create_vector_field("R", "R_y", "-R_x", "R_z") Returns: A key for the vector field expression.
calculate_curl
Calculates the curl of a vector field using SymPy's curl function. Args: vector_field_key: The key of the vector field expression. Example: # First create a coordinate system create_coordinate_system("R") # Create a vector field F = (y, -x, 0) vector_field = create_vector_field("R", "R_y", "-R_x", "0") # Calculate curl curl_result = calculate_curl(vector_field) # Returns (0, 0, -2) Returns: A key for the curl expression.
calculate_divergence
Calculates the divergence of a vector field using SymPy's divergence function. Args: vector_field_key: The key of the vector field expression. Example: # First create a coordinate system create_coordinate_system("R") # Create a vector field F = (x, y, z) vector_field = create_vector_field("R", "R_x", "R_y", "R_z") # Calculate divergence div_result = calculate_divergence(vector_field) # Returns 3 Returns: A key for the divergence expression.
convert_to_units
Converts a quantity to the given target units using sympy.physics.units.convert_to. Args: expr_key: The key of the expression (previously introduced) to convert. target_units: List of unit names as strings (e.g., ["meter", "1/second"]). unit_system: Optional unit system (from UnitSystem enum). Defaults to SI. The following units are available by default: SI base units: meter, second, kilogram, ampere, kelvin, mole, candela Length: kilometer, millimeter Mass: gram Energy: joule Force: newton Pressure: pascal Power: watt Electric: coulomb, volt, ohm, farad, henry Constants: speed_of_light, gravitational_constant, planck IMPORTANT: For compound units like meter/second, you must separate the numerator and denominator into separate units in the list. For example: - For meter/second: use ["meter", "1/second"] - For newton*meter: use ["newton", "meter"] - For kilogram*meter²/second²: use ["kilogram", "meter**2", "1/second**2"] Example: # Convert speed of light to kilometers per hour expr_key = introduce_expression("speed_of_light") result = convert_to_units(expr_key, ["kilometer", "1/hour"]) # Returns approximately 1.08e9 kilometer/hour # Convert gravitational constant to CGS units expr_key = introduce_expression("gravitational_constant") result = convert_to_units(expr_key, ["centimeter**3", "1/gram", "1/second**2"], UnitSystem.CGS) SI prefixes (femto, pico, nano, micro, milli, centi, deci, deca, hecto, kilo, mega, giga, tera) can be used directly with base units. Returns: A key for the converted expression, or an error message.
quantity_simplify_units
Simplifies a quantity with units using sympy's built-in simplify method for Quantity objects. Args: expr_key: The key of the expression (previously introduced) to simplify. unit_system: Optional unit system (from UnitSystem enum). Not used with direct simplify method. The following units are available by default: SI base units: meter, second, kilogram, ampere, kelvin, mole, candela Length: kilometer, millimeter Mass: gram Energy: joule Force: newton Pressure: pascal Power: watt Electric: coulomb, volt, ohm, farad, henry Constants: speed_of_light, gravitational_constant, planck Example: # Simplify force expressed in base units expr_key = introduce_expression("kilogram*meter/second**2") result = quantity_simplify_units(expr_key) # Returns newton (as N = kg·m/s²) # Simplify a complex expression with mixed units expr_key = introduce_expression("joule/(kilogram*meter**2/second**2)") result = quantity_simplify_units(expr_key) # Returns a dimensionless quantity (1) # Simplify electrical power expression expr_key = introduce_expression("volt*ampere") result = quantity_simplify_units(expr_key) # Returns watt Example with Speed of Light: # Introduce the speed of light c_key = introduce_expression("speed_of_light") # Convert to kilometers per hour km_per_hour_key = convert_to_units(c_key, ["kilometer", "1/hour"]) # Simplify to get the numerical value simplified_key = quantity_simplify_units(km_per_hour_key) # Print the result print_latex_expression(simplified_key) # Shows the numeric value of speed of light in km/h Returns: A key for the simplified expression, or an error message.
create_matrix
Creates a SymPy matrix from the provided data. Args: matrix_data: A list of lists representing the rows and columns of the matrix. Each element can be a number or a string expression. matrix_var_name: Optional name for storing the matrix. If not provided, a sequential name will be generated. Example: # Create a 2x2 matrix with numeric values matrix_key = create_matrix([[1, 2], [3, 4]], "M") # Create a matrix with symbolic expressions (assuming x, y are defined) matrix_key = create_matrix([["x", "y"], ["x*y", "x+y"]]) Returns: A key for the stored matrix.
matrix_determinant
Calculates the determinant of a matrix using SymPy's det method. Args: matrix_key: The key of the matrix to calculate the determinant for. Example: # Create a matrix matrix_key = create_matrix([[1, 2], [3, 4]]) # Calculate its determinant det_key = matrix_determinant(matrix_key) # Results in -2 Returns: A key for the determinant expression.
matrix_inverse
Calculates the inverse of a matrix using SymPy's inv method. Args: matrix_key: The key of the matrix to invert. Example: # Create a matrix matrix_key = create_matrix([[1, 2], [3, 4]]) # Calculate its inverse inv_key = matrix_inverse(matrix_key) Returns: A key for the inverted matrix.
matrix_eigenvalues
Calculates the eigenvalues of a matrix using SymPy's eigenvals method. Args: matrix_key: The key of the matrix to calculate eigenvalues for. Example: # Create a matrix matrix_key = create_matrix([[1, 2], [2, 1]]) # Calculate its eigenvalues evals_key = matrix_eigenvalues(matrix_key) Returns: A key for the eigenvalues expression (usually a dictionary mapping eigenvalues to their multiplicities).
matrix_eigenvectors
Calculates the eigenvectors of a matrix using SymPy's eigenvects method. Args: matrix_key: The key of the matrix to calculate eigenvectors for. Example: # Create a matrix matrix_key = create_matrix([[1, 2], [2, 1]]) # Calculate its eigenvectors evecs_key = matrix_eigenvectors(matrix_key) Returns: A key for the eigenvectors expression (usually a list of tuples (eigenvalue, multiplicity, [eigenvectors])).
README
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.