Token导航 LogoToken导航TokenDH.com
My MCP Server Demo Stable logo
设计创作stdio官方级别未说明来源级核验

My MCP Server Demo Stable

MCP Server

一个基于FastMCP框架的模块化、可扩展的MCP服务器示例,包含工具、资源和提示的演示,支持结构化输出、错误处理和异步操作。

工具数

6

提示词数

0

GitHub Stars

0

资源数

0
PythonClaude模块化设计Claude DesktopClaudeCursor

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

jasonshen190

提供方

jasonshen190

最后核验

2026/5/17 20:20

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

python src/demo_server.py

详细介绍

我的mcp服务器演示稳定的mcp服务器

概述

我的mcp服务器是一个全面的mcp服务器示例,演示了使用FastMCP框架的工具、资源和提示。它是模块化的、可扩展的,包括结构化输出、错误处理和异步支持。

本地测试说明

如果您想在克隆存储库或下载并解压缩包后在本地测试服务器:

  1. 打开 src/demo_server.py 转到第114行和第115行。
  2. 注释mcp.run()
  3. 取消注释或更新这些行以启用 streamable-http 模式:
   # mcp.run(transport="streamable-http")
   # print("Starting MCP server...")
   mcp.run(transport="streamable-http")
  1. 通过以下方式运行 与客户进行测试
  2. 要使用Cursor等IDE进行测试,请使用~/.cours/mcp.json中mcp-local.json的内容(可能需要重新启动Cursor)

远程测试(uvx)

  1. 在mcp.json、.fastmcp.json和pyproject.toml中,将Github所有者名称“jasonshen190”替换为您自己的名称
  2. 不要在本地运行demo_server.py,而是使用~/.cursor/mcp.json中的mcp.json将其用作远程mcp服务器

项目结构

my-mcp-server/
├── src/
│   ├── demo_server.py         # Main MCP server with tool/resource/prompt registration
│   ├── setup_and_run.py      # Interactive setup and run script
│   ├── test_client.py        # Async test client for all features
|   |── mcp-local.json        # local test server configuration
│   ├── mcp.json              # Server configuration
│   └── components/
│       ├── tools.py          # Tool logic and models
│       ├── resources.py      # Resource logic
│       ├── prompts.py        # Prompt logic
│       └── __init__.py
├── requirements.txt
├── pyproject.toml
├── README.md

用法

在本地测试服务器

方法1:直接执行

python src/demo_server.py

方法2:交互式设置(推荐)

python src/setup_and_run.py

与客户进行测试

运行测试客户端以查看所有功能的运行情况:

python src/test_client.py

输出示例

运行测试客户端时,您应该看到如下输出:

Connected to my-mcp-server MCP Server!
==================================================

1. Testing Tools:
--------------------
add_numbers_tool(5, 3) = 8
multiply_numbers_tool(4.5, 2.0) = 9.0
calculate_bmi_tool(70kg, 1.75m) = 22.857142857142858
get_weather_tool('New York') = {"temperature": 22.5, "humidity": 65.0, "condition": "partly cloudy", "wind_speed": 12.3}
format_text_tool('hello world', 'uppercase') = HELLO WORLD
get_current_time_tool('UTC') = Current time in UTC: 2024-01-15 10:30:45

2. Testing Resources:
--------------------
config://app = {
  "name": "my-mcp-server",
  "version": "1.0.0",
  "features": ["tools", "resources", "prompts"],
  "status": "active"
}...
greeting://Alice = Hello, Alice! Welcome to the my-mcp-server MCP Server.
info://server = {
  "server_name": "my-mcp-server",
  "description": "A comprehensive MCP server demonstrating various features",
  "available_tools": [...]
}...
math://constants = {
  "pi": 3.14159265359,
  "e": 2.71828182846,
  "golden_ratio": 1.61803398875,
  "sqrt_2": 1.41421356237
}...

3. Testing Prompts:
--------------------
Available prompts: ['calculator_assistant_prompt', 'weather_assistant_prompt', 'text_formatter_prompt']
calculator_assistant_prompt = You are a helpful calculator assistant. You can:
- Add numbers using the add_numbers tool
- Multiply numbers using the multiply_numbers tool
- Calculate BMI using the calculate_bmi tool
- Get mathematical constants from the math://constants resource

Please help users with their calculations!

==================================================
All tests completed successfully!

特性

工具

  • add_numbers_tool(a,b):加两个数字(int)
  • multiply_numbers_tool(a,b):将两个数字相乘(浮点数)
  • calculate_bmi_tool(weight_kg,height_m):根据体重(kg)和身高(m)计算BMI
  • get_weather_tool(城市):获取城市的模拟天气数据(返回结构化WeatherData)
  • format_text_tool(文本、样式):设置不同样式的文本格式(大写、小写、标题、反转、正常)
  • get_current_time_tool(时区):获取指定时区的当前时间(默认:UTC)

资源

  • config://app:应用程序配置(名称、版本、功能、状态)
  • 问候语://{姓名}:个性化问候
  • info://server:服务器信息和可用功能
  • math://constants:常见的数学常数(pi、e、golden_ratio、sqrt_2)

鼓励

  • 计算器_助手\_ mpt:数学计算助理
  • 天气助理:天气相关查询助理
  • text_formatter_prompt:文本格式化助手

主文件

  • src/demo_server.py:在FastMCP中注册所有工具、资源和提示。运行服务器的入口点。
  • src/setup_and_run.py:安装依赖项并以交互方式运行服务器或测试客户端。
  • src/test_client.py:异步客户端,通过HTTP测试所有工具、资源和提示。
  • src/components/tools.py:实现工具逻辑和WeatherData模型。
  • src/components/resources.py:实现资源逻辑并返回JSON编码的数据。
  • src/components/prompts.py:为助手实现提示逻辑。

高级用法

  • 结构化输出: get_weather_tool 返回结构化天气数据的Pydantic模型。
  • 错误处理:工具如 calculate_bmi_tool 为无效输入(例如非正高度)引发错误。
  • 定制:通过在中编辑相应的文件来添加新的工具/资源/提示 src/components/.

发展

  • 模块化、解耦设计,易于扩展和调试
  • 用于类型安全的Pydantic模型
  • 异步/等待支持
  • 全面的错误处理

后续步骤

  • 探索 MCP Python SDK文档
  • 使用自定义功能构建自己的MCP服务器
  • 与Claude Desktop或其他MCP客户端集成

目录标签

目录标签

PythonClaude模块化设计MCP框架本地部署服务器示例异步支持结构化输出

支持客户端

Claude DesktopClaudeCursor

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

6

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP