Math MCP Server

Math MCP Server

Enables LLMs to perform accurate mathematical calculations by evaluating expressions using mathjs. Supports basic arithmetic, functions, constants, and complex mathematical operations through natural language requests.

Category
访问服务器

README

Math Quiz with MCP Server

A demonstration application showing how an MCP (Model Context Protocol) server can act as a mathematical coprocessor. The LLM decides what calculations to perform, and the MCP server handles the computation using mathjs.

Architecture

  • Frontend: React + Vite + Tailwind CSS - Simple math quiz interface
  • MCP Server: Node.js + TypeScript - Mathematical evaluation service

Project Structure

mcp-math/
├── frontend/           # React quiz application
│   ├── src/
│   │   ├── App.tsx    # Main quiz component
│   │   ├── main.tsx   # React entry point
│   │   └── index.css  # Tailwind styles
│   └── package.json
├── mcp-server/        # MCP server for math operations
│   ├── src/
│   │   └── index.ts   # MCP server implementation
│   └── package.json
└── package.json       # Workspace root

Setup Instructions

1. Install Dependencies

From the root directory:

npm install
cd frontend && npm install
cd ../mcp-server && npm install
cd ..

Or use the convenience script:

npm run install:all

2. Build the MCP Server

cd mcp-server
npm run build

3. Configure MCP Client

For Cursor

Add the MCP server to your Cursor configuration file:

Location: ~/.cursor/mcp.json

Example configuration:

{
  "mcpServers": {
    "math": {
      "command": "node",
      "args": ["${HOME}/path/to/mcp-math/mcp-server/dist/index.js"]
    }
  }
}

Important: Replace path/to/mcp-math with the actual path from your home directory to your project directory. The ${HOME} variable will be automatically expanded.

After updating the configuration, restart Cursor for the changes to take effect.

For Claude Desktop

Add the MCP server to your Claude Desktop configuration file:

MacOS/Linux: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

Example configuration:

{
  "mcpServers": {
    "math": {
      "command": "node",
      "args": ["${HOME}/path/to/mcp-math/mcp-server/dist/index.js"]
    }
  }
}

Important: Replace path/to/mcp-math with the actual path from your home directory to your project directory.

After updating the configuration, restart Claude Desktop for the changes to take effect.

Running the Application

Start the Frontend

cd frontend
npm run dev

The quiz app will be available at http://localhost:5173

Using the MCP Server with Claude/Cursor

Once configured, you can ask Claude (or Cursor AI) to use the math server:

Example prompts:

  • "Use the math server to calculate 123 * 456"
  • "Evaluate sqrt(144) + sin(pi/2) using the evaluate tool"
  • "What is (25 + 75) / (10 - 5)?"

The AI will automatically use the evaluate tool from the MCP server to perform calculations.

MCP Server Tools

evaluate

Evaluates a mathematical expression and returns the result.

Input:

  • expression (string): Mathematical expression to evaluate

Supported Operations:

  • Basic arithmetic: +, -, *, /
  • Exponents: ^ or **
  • Parentheses: (, )
  • Common functions: sqrt(), sin(), cos(), tan(), log(), etc.
  • Constants: pi, e

Example:

{
  "expression": "2 * (3 + 4)"
}

Response:

{
  "expression": "2 * (3 + 4)",
  "result": "14",
  "success": true
}

Development

Frontend Development

npm run dev:frontend

MCP Server Development

After making changes to the MCP server:

cd mcp-server
npm run build

Then restart Claude Desktop to load the updated server.

Build for Production

# Build frontend
npm run build:frontend

# Build MCP server
npm run build:mcp

How It Works

The MCP Pattern

This application demonstrates the "coprocessor" pattern:

  1. Frontend displays math problems to users
  2. LLM (Claude) understands user intent and decides what calculations to perform
  3. MCP Server executes the calculations accurately using mathjs
  4. Result flows back through Claude to the application

Why Use MCP for Math?

  • Accuracy: LLMs can struggle with precise calculations. The MCP server uses mathjs for exact results.
  • Separation of Concerns: The LLM focuses on understanding and orchestration, while the MCP server handles computation.
  • Extensibility: Easy to add new mathematical operations without retraining the model.

Notes

  • The current frontend implementation calculates answers locally for demo simplicity
  • In a production setup, you would connect the frontend to Claude (via API or desktop app) which would use the MCP server
  • This is a demonstration project showing MCP architecture - not production-ready

Future Enhancements

Potential improvements:

  • Add database for storing quiz results
  • Connect frontend directly to Claude API with MCP
  • Add more quiz types (algebra, geometry, etc.)
  • Implement user authentication and progress tracking
  • Add difficulty levels and adaptive quizzing

Troubleshooting

MCP Server not showing in Claude/Cursor

  1. Check the configuration file path is correct (~/.cursor/mcp.json for Cursor)
  2. Ensure the path to index.js is correct (use ${HOME}/... for portability)
  3. Verify the server builds without errors: cd mcp-server && npm run build
  4. Check logs:
    • Claude Desktop: Help → Show Logs
    • Cursor: Check the MCP server output in Cursor settings
  5. Restart Claude Desktop or Cursor after configuration changes

Frontend not starting

  1. Ensure dependencies are installed: cd frontend && npm install
  2. Check Node.js version (requires Node 18+)
  3. Try clearing node_modules and reinstalling

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选