这是一个基于MCP(模型上下文协议)的项目,集成了智谱AI和腾讯地图API,提供天气查询、地理编码和网络搜索等功能。该项目包括两种交互方式:命令行界面和Web界面。
mcp-python-demo/
├── src/
│ └── mcp_python_demo/
│ ├── __init__.py
│ ├── server.py
│ ├── client.py
│ ├── web_client.py
│ └── main.py
├── images/
├── pyproject.toml
├── .env
├── .env.example
├── .gitignore
└── README.md
git clone https://github.com/chenchen0611/mcp-python-demo.git
cd mcp-python-demo
uv venv
source .venv/bin/activate # Linux/Mac
# 或
.venv\Scripts\activate # Windows
uv pip install -e .
.env文件并配置必要的环境变量:# 智谱AI配置
ZHIPU_API_KEY="your-zhipu-api-key"
ZHIPU_MODEL="glm-4-plus"
ZHIPU_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"
# 腾讯地图API配置
TENCENT_MAP_API_KEY="your-tencent-map-api-key"
TENCENT_MAP_API_BASE="https://apis.map.qq.com/ws/"
cd src/mcp_python_demo
streamlit run web_client.py
访问以下地址之一:

cd src/mcp_python_demo
uv run server.py

cd src/mcp_python_demo
# 使用本地服务器
uv run client.py --agent server.py
# 或使用远程服务器
uv run server.py
uv run client.py --agent http://127.0.0.1:8000

async def query_weather(adcode: str, search_type: str = "now") -> str:
"""获取中国城市天气信息"""
async def query_adcode(region_name: str) -> str:
"""获取行政区划代码"""
async def web_search(search_query: str, search_engine: str = "search_std") -> str:
"""使用智谱AI进行网络搜索"""
server.py中使用@mcp.tool()装饰器添加新工具:@mcp.tool()
async def your_tool(param1: str, param2: str = "default") -> str:
"""工具描述"""
# 实现逻辑
return result
.env文件中.env文件到版本控制系统.env.example进行配置连接错误
API调用失败
无法访问Web UI
本项目基于以下开源项目: