Test FastMCP

Test FastMCP

A basic MCP server built with the FastMCP framework that provides fundamental mathematical operations like addition, subtraction, multiplication, and division. It serves as a demonstration for integrating math-based tools into MCP-compatible environments like Cursor IDE.

Category
Visit Server

README

Test FastMCP

一个使用 FastMCP 框架构建的 MCP 服务器,提供基本的数学运算功能。

🚀 功能特性

  • 加法运算 (add) - 计算两个整数的和
  • 减法运算 (subtract) - 计算两个整数的差
  • 乘法运算 (multiply) - 计算两个整数的积
  • 除法运算 (divide) - 计算两个整数的商

📋 系统要求

  • Python 3.12+
  • uv 包管理器
  • Cursor IDE (用于MCP集成)

🛠️ 安装和设置

1. 安装 uv

如果你还没有安装 uv,请先安装:

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# 或者使用 pip
pip install uv

2. 项目设置

  1. 克隆项目

    git clone <repository-url>
    cd test_fast_mcp
    
  2. 安装依赖

    uv sync
    
  3. 激活虚拟环境

    uv shell
    
  4. 运行服务器

    uv run python main.py
    

🔧 开发命令

  • 启动开发服务器

    uv run dev
    
  • 运行测试

    uv run test
    
  • 代码格式化

    uv run format
    
  • 代码检查

    uv run lint
    
  • 导入排序

    uv run sort
    

添加新依赖

# 添加生产依赖
uv add package-name

# 添加开发依赖
uv add --dev package-name

更新依赖

uv lock --upgrade

🔌 Cursor 集成

配置 MCP 服务器

将以下配置添加到你的 Cursor MCP 配置文件 (~/.cursor/mcp.json) 中:

{
  "mcpServers": {
    "test-fast-mcp": {
      "command": "uv",
      "args": ["run", "python", "/Users/guosong/Desktop/Sina/Code/test_fast_mcp/main.py"],
      "env": {
        "PYTHONPATH": ".",
        "TRANSPORT": "stdio"
      }
    }
  }
}

重要配置说明:

  • 使用绝对路径指向 main.py 文件
  • 添加 "TRANSPORT": "stdio" 环境变量
  • 确保 PYTHONPATH 设置正确

验证集成

  1. 重启 Cursor IDE
  2. 检查 MCP 服务器状态(应该显示 "4 tools enabled")
  3. 测试工具调用

📁 项目结构

test_fast_mcp/
├── main.py          # 主服务器文件,包含所有工具定义
├── pyproject.toml   # 项目配置和依赖管理
├── uv.lock         # 依赖锁定文件
├── mcp.json        # Cursor MCP 配置示例
├── test_tools.py   # 工具测试文件
└── README.md       # 项目说明文档

🧪 测试工具

运行测试脚本来验证数学函数:

python test_tools.py

预期输出:

Testing math functions:
add(5, 4) = 9
subtract(10, 3) = 7
multiply(6, 7) = 42
divide(15, 3) = 5.0

🔍 故障排除

常见问题

  1. "No tools or prompts" 错误

    • 确保使用绝对路径配置
    • 添加 TRANSPORT: "stdio" 环境变量
    • 重启 Cursor IDE
  2. 构建错误

    • 运行 uv sync 重新安装依赖
    • 检查 pyproject.toml 配置
  3. 工具无法调用

    • 确认 MCP 服务器正在运行
    • 检查工具名称格式:mcp_test-fast-mcp_<tool_name>

调试步骤

  1. 检查服务器状态:

    ps aux | grep "python main.py"
    
  2. 查看服务器日志:

    uv run python main.py
    
  3. 测试工具功能:

    python -c "from main import add; print(add(5, 4))"
    

🏗️ 开发指南

这个项目使用 FastMCP 框架,它简化了 MCP 服务器的创建过程。

添加新工具

  1. main.py 中定义新函数
  2. 使用 @mcp.tool 装饰器
  3. 添加详细的文档字符串
  4. 重启服务器

示例:

@mcp.tool
def new_tool(param: str) -> str:
    """Tool description.
    
    Args:
        param: Parameter description
        
    Returns:
        Return value description
    """
    return f"Processed: {param}"

工具命名规范

  • 使用小写字母和下划线
  • 提供清晰的参数类型注解
  • 包含详细的文档字符串
  • 添加适当的错误处理

📄 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📞 支持

如果遇到问题,请:

  1. 检查故障排除部分
  2. 查看项目 Issues
  3. 提交新的 Issue

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured