MCP Demo
A FastMCP-based server providing tools for weather queries, random number generation, and real-time stock market data retrieval. It enables AI models to interact with external data and perform specific tasks through the Model Context Protocol.
README
MCP Demo 项目
项目介绍
MCP (Model Context Protocol) Demo 是一个基于 FastMCP 框架的示例项目,展示了如何构建一个提供天气查询、随机倍数生成和股票行情获取功能的服务。该项目使用通义千问作为客户端,通过 FastMCP 服务器提供的工具接口实现各种功能。
项目结构
MCP Demo/
├── README.md # 项目说明文件
├── config.py # 配置文件
├── requirements.txt # 项目依赖
├── server.py # FastMCP 服务器实现
└── tongyi_client.py # 通义千问客户端
功能说明
服务器功能
服务器提供以下三个工具:
- get_current_weather:获取指定城市的当前天气信息
- get_num_rand:生成给定数字的随机倍数
- get_stock_quote:获取指定股票的买卖盘数据
客户端功能
客户端使用通义千问 API,通过 MCP 协议调用服务器提供的工具,实现与用户的交互。
安装步骤
-
克隆项目到本地
-
安装项目依赖:
pip install -r requirements.txt
- 配置 API 密钥:
编辑 config.py 文件,将 api_key 替换为实际的阿里云百炼 API 密钥。
使用方法
启动服务器
python server.py
服务器将在 http://0.0.0.0:8000 上运行。
运行客户端
python tongyi_client.py
客户端启动后,您可以输入以下类型的问题:
- "北京的天气怎么样?"
- "生成 5 的随机倍数"
- "获取股票 600000 的行情"
服务器部署
部署步骤
- 上传项目文件到服务器
- 配置服务器环境,确保安装了 Python 和必要的依赖
- 配置域名,外网映射,SSL等
- 启动命令:
uvicorn server:sse_app --host 0.0.0.0 --port 8000
服务器截图

技术栈
- 服务器端:Python, FastMCP, Uvicorn
- 客户端:Python, Qwen Agent
- 依赖库:
- akshare (1.18.14):用于获取股票数据
- fastmcp:MCP 框架
- pydantic:数据验证
- pandas:数据处理
- uvicorn:ASGI 服务器
测试工具
您可以通过运行客户端来测试各个工具:
- 确保服务器已经启动
- 运行客户端:
python tongyi_client.py - 输入测试问题,例如:
- "上海的天气怎么样?"
- "生成 7 的随机倍数"
- "获取股票 600036 的行情"
注意事项
- 确保已正确配置 API 密钥
- 服务器需要保持运行状态,客户端才能正常调用工具
- 股票行情查询需要使用正确的股票代码
- 天气查询功能依赖外部 API,可能会受到网络影响
示例对话
user question: 上海的天气怎么样?
工具调用信息: {'name': 'get_current_weather', 'arguments': '{"city": "上海"}'}
工具调用结果: {"data": {"city": "上海", "date": "2026-02-26", "weather": "晴", "temp": "18℃", "humidity": "65%", "wind": "东北风 3级"}, "code": 0, "msg": "success"}
上海今天的天气是晴,温度18℃,湿度65%,东北风3级。
user question: 生成 7 的随机倍数
工具调用信息: {'name': 'get_num_rand', 'arguments': '{"num": 7}'}
工具调用结果: 49
7的随机倍数是49。
user question: 获取股票 600036 的行情
工具调用信息: {'name': 'get_stock_quote', 'arguments': '{"symbol": "600036"}'}
工具调用结果: [{"卖5价": 15.25, "卖5量": 1234, "卖4价": 15.24, "卖4量": 2345, "卖3价": 15.23, "卖3量": 3456, "卖2价": 15.22, "卖2量": 4567, "卖1价": 15.21, "卖1量": 5678, "买1价": 15.20, "买1量": 6789, "买2价": 15.19, "买2量": 7890, "买3价": 15.18, "买3量": 8901, "买4价": 15.17, "买4量": 9012, "买5价": 15.16, "买5量": 1013}]
股票600036的行情数据已获取,包括买卖盘价格和数量信息。
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.