@qinggeng2015/mcp-tool-math
v1.1.0
Published
A Model Context Protocol tool for mathematical calculations and matrix operations using mathjs
Maintainers
Readme
MathJS MCP 工具插件
这是一个基于 Node.js 和 MathJS 库的 Model Context Protocol (MCP) 工具插件。它提供了数学计算功能,可以作为 MCP 工具集成到支持 MCP 的应用中。
功能
基础计算
- calculate - 执行任意数学表达式计算
- basic_arithmetic - 执行基本算术运算(加、减、乘、除)
矩阵计算
- create_matrix - 创建矩阵
- matrix_operation - 执行矩阵运算(加法、减法、乘法)
- matrix_transpose - 计算矩阵的转置
- matrix_inverse - 计算矩阵的逆矩阵
- matrix_determinant - 计算矩阵的行列式
- matrix_trace - 计算矩阵的迹(主对角线元素之和)
- matrix_eigenvalues - 计算矩阵的特征值
- matrix_rank - 计算矩阵的秩
安装
npm install使用方法
npm start启动后,该工具会监听 stdin 并通过 stdout 输出 MCP 协议消息。
工具详情
calculate 工具
执行任意数学表达式计算。
参数:
expression(string, 必需): 要计算的数学表达式,例如: "2+2", "sqrt(16)", "sin(pi/2)"
示例:
{
"method": "tools/call",
"params": {
"name": "calculate",
"arguments": {
"expression": "2+2*3"
}
}
}basic_arithmetic 工具
执行基本算术运算。
参数:
operation(string, 必需): 运算类型,可选值: "add", "subtract", "multiply", "divide"a(number, 必需): 第一个操作数b(number, 必需): 第二个操作数
示例:
{
"method": "tools/call",
"params": {
"name": "basic_arithmetic",
"arguments": {
"operation": "add",
"a": 5,
"b": 3
}
}
}create_matrix 工具
创建矩阵对象。
参数:
matrix(array, 必需): 二维数组表示的矩阵,例如:[[1,2],[3,4]]
示例:
{
"method": "tools/call",
"params": {
"name": "create_matrix",
"arguments": {
"matrix": [[1, 2], [3, 4]]
}
}
}matrix_operation 工具
执行矩阵运算(加法、减法、乘法)。
参数:
operation(string, 必需): 运算类型,可选值: "add", "subtract", "multiply"matrixA(array, 必需): 第一个矩阵,二维数组格式matrixB(array, 必需): 第二个矩阵,二维数组格式
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_operation",
"arguments": {
"operation": "multiply",
"matrixA": [[1, 2], [3, 4]],
"matrixB": [[5, 6], [7, 8]]
}
}
}matrix_transpose 工具
计算矩阵的转置。
参数:
matrix(array, 必需): 要转置的矩阵,二维数组格式
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_transpose",
"arguments": {
"matrix": [[1, 2, 3], [4, 5, 6]]
}
}
}matrix_inverse 工具
计算矩阵的逆矩阵(必须是方阵且可逆)。
参数:
matrix(array, 必需): 要求逆的矩阵,必须是方阵
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_inverse",
"arguments": {
"matrix": [[1, 2], [3, 4]]
}
}
}matrix_determinant 工具
计算矩阵的行列式(必须是方阵)。
参数:
matrix(array, 必需): 要计算行列式的矩阵,必须是方阵
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_determinant",
"arguments": {
"matrix": [[1, 2], [3, 4]]
}
}
}matrix_trace 工具
计算矩阵的迹(主对角线元素之和,必须是方阵)。
参数:
matrix(array, 必需): 要计算迹的矩阵,必须是方阵
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_trace",
"arguments": {
"matrix": [[1, 2], [3, 4]]
}
}
}matrix_eigenvalues 工具
计算矩阵的特征值(必须是方阵)。
参数:
matrix(array, 必需): 要计算特征值的矩阵,必须是方阵
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_eigenvalues",
"arguments": {
"matrix": [[1, 2], [3, 4]]
}
}
}matrix_rank 工具
计算矩阵的秩。
参数:
matrix(array, 必需): 要计算秩的矩阵,二维数组格式
示例:
{
"method": "tools/call",
"params": {
"name": "matrix_rank",
"arguments": {
"matrix": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
}
}
}MathJS 功能
该插件使用 MathJS 库,支持多种数学运算:
- 基本运算:+, -, *, /
- 数学函数:sin, cos, tan, log, sqrt 等
- 常量:pi, e 等
- 复杂表达式求值
- 矩阵运算:创建矩阵、矩阵加减乘、转置、求逆、行列式、迹、特征值、秩等
了解更多 MathJS 功能,请参考 MathJS 文档。
