Content
# MCP Python Demo
This is a project based on MCP (Model Context Protocol), integrating Zhipu AI and Tencent Map API, providing functionalities such as weather queries, geocoding, and web search. The project includes both command-line interface and web interface for interaction.
## Features
- 🤖 Zhipu AI powered dialogue system
- 🌤️ Tencent Map weather query
- 🗺️ Geocoding query
- 🔍 Intelligent web search
- 💻 Dual support for command-line and web interface
- 🌐 Supports external network access
## Project Structure
```
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
```
## Quick Start
### Environment Requirements
- Python >= 3.10
- uv (recommended) or pip
### Installation
1. Clone the project:
```bash
git clone https://github.com/chenchen0611/mcp-python-demo.git
cd mcp-python-demo
```
2. Install dependencies using uv:
```bash
uv venv
source .venv/bin/activate # Linux/Mac
# or
.venv\Scripts\activate # Windows
uv pip install -e .
```
### Configuration
1. Create a `.env` file and configure the necessary environment variables:
```bash
# Zhipu AI configuration
ZHIPU_API_KEY="your-zhipu-api-key"
ZHIPU_MODEL="glm-4-plus"
ZHIPU_BASE_URL="https://open.bigmodel.cn/api/paas/v4/"
# Tencent Map API configuration
TENCENT_MAP_API_KEY="your-tencent-map-api-key"
TENCENT_MAP_API_BASE="https://apis.map.qq.com/ws/"
```
### Running
#### Web Interface (Recommended)
```bash
cd src/mcp_python_demo
streamlit run web_client.py
```
Access one of the following addresses:
- Local access: http://localhost:8501
- LAN access: http://[your-local-ip]:8501
- External access: http://[your-public-ip]:8501
##### Page Configuration
- Directly input `server.py` and click connect

- Open a new terminal, run the command below, and then enter http://127.0.0.1:8000 in the web page
```bash
cd src/mcp_python_demo
uv run server.py
```

#### Command-Line Interface
```bash
cd src/mcp_python_demo
# Use local server
uv run client.py --agent server.py
# Or use remote server
uv run server.py
uv run client.py --agent http://127.0.0.1:8000
```

## Available Tools
### 1. Weather Query
```python
async def query_weather(adcode: str, search_type: str = "now") -> str:
"""Get weather information for cities in China"""
```
### 2. Geocoding Query
```python
async def query_adcode(region_name: str) -> str:
"""Get administrative division code"""
```
### 3. Web Search
```python
async def web_search(search_query: str, search_engine: str = "search_std") -> str:
"""Perform web search using Zhipu AI"""
```
## Development Notes
### Adding New Tools
1. Use the `@mcp.tool()` decorator in `server.py` to add a new tool:
```python
@mcp.tool()
async def your_tool(param1: str, param2: str = "default") -> str:
"""Tool description"""
# Implementation logic
return result
```
2. The tool will automatically be available in the client.
### Environment Variables
- All sensitive information and configurations should be placed in the `.env` file.
- Do not commit the `.env` file to version control systems.
- Refer to `.env.example` for configuration guidance.
## Frequently Asked Questions
1. **Connection Error**
- Check if the server address is correct.
- Ensure all environment variables are configured correctly.
- Make sure the server is running and the port is accessible.
2. **API Call Failure**
- Verify if the API key is valid.
- Check the network connection.
- Confirm if the API call rate limit has been exceeded.
3. **Web UI Unreachable**
- Check firewall settings.
- Ensure the port is open.
- Verify if the server IP address is correct.
## Acknowledgements
This project is based on the following open-source projects:
- [Model Context Protocol Servers](https://github.com/modelcontextprotocol/servers) - Official reference implementation of MCP servers, providing rich examples and best practices.
- [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk) - Python SDK implementation, offering a concise and elegant API interface.
Connection Info
You Might Also Like
awesome-mcp-servers
A collection of MCP servers.
git
A Model Context Protocol server for Git automation and interaction.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
Appwrite
Build like a team of hundreds