Metadata-Version: 2.4
Name: mcp-study
Version: 0.1.0
Summary: MCP (Model Context Protocol) 学习与实践项目 — 包含天气查询、数据库查询、Python 代码执行等多个 MCP Server 示例
Keywords: mcp,model-context-protocol,ai-agent,llm-tools,weather,deepseek
Author: wf
Author-email: wf <2978055723@qq.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Dist: httpx>=0.28.1
Requires-Dist: mcp>=2.2.0
Requires-Dist: openai>=3.14.0
Requires-Dist: python-dotenv>=1.2.3
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/username/mcp-study
Project-URL: Repository, https://github.com/username/mcp-study
Description-Content-Type: text/markdown

# MCP Study

MCP (Model Context Protocol) 学习与实践项目，包含多个可直接使用的 MCP Server。

## 🚀 快速安装

```bash
pip install mcp-study
```

## 📦 包含的 MCP Server

| Server | 命令 | 功能 |
|---|---|---|
| Weather Server | `weather-server` | 查询全球城市实时天气和预报（数据源：wttr.in） |
| SQL Server | `sql-server` | SQLite 数据库查询（内置学生成绩示例数据） |
| Agent | `python -m mcp_study.weather_agent` | 自然语言驱动的天气 Agent（DeepSeek） |
| 多 Server Agent | `python -m mcp_study.multi_server_agent` | 同时连接 3 个 Server 的智能 Agent |

## 🔧 使用方式

### 方式一：命令行直接启动 Server

```bash
# 启动天气服务
weather-server

# 启动数据库查询服务
sql-server
```

### 方式二：在 MCP Client 中连接

```json
{
  "mcpServers": {
    "weather": {
      "command": "weather-server"
    },
    "sql": {
      "command": "sql-server"
    }
  }
}
```

### 方式三：用 Python 代码连接

```python
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    params = StdioServerParameters(command="weather-server")
    async with stdio_client(params) as (r, w):
        async with ClientSession(r, w) as session:
            await session.initialize()
            result = await session.call_tool("get_weather", {"city": "北京"})
            print(result.content[0].text)

asyncio.run(main())
```

### 方式四：使用 Agent（接大模型）

```bash
# 先配置 .env 文件
# DEEPSEEK_API_KEY=sk-xxx
# DEEPSEEK_BASE_URL=https://api.deepseek.com
# DEFAULT_MODEL=deepseek-chat

# 运行天气 Agent
python -m mcp_study.weather_agent

# 运行多 Server Agent
python -m mcp_study.multi_server_agent
```

## 🛠️ 工具列表

### Weather Server (`weather-server`)

| 工具 | 说明 |
|---|---|
| `get_weather(city)` | 查询指定城市实时天气 |
| `get_forecast(city, days)` | 查询指定城市未来 N 天预报 |

### SQL Server (`sql-server`)

| 工具 | 说明 |
|---|---|
| `sql_inter(sql_query)` | 执行 SQL 查询 |
| `list_tables()` | 列出所有表名 |
| `describe_table(table_name)` | 查看表结构 |
| `export_to_csv(table_name, output_file)` | 导出表数据为 CSV |

## 📁 项目结构

```
mcp-study/
├── src/mcp_study/
│   ├── weather_server.py      # 天气查询 Server
│   ├── weather_client.py      # 天气 Client（固定调用）
│   ├── weather_agent.py       # Agent（DeepSeek 驱动）
│   ├── sql_server.py          # 数据库查询 Server
│   ├── python_server.py       # Python 代码执行 Server
│   ├── multi_server_agent.py  # 多 Server Agent
│   └── config.py              # 环境变量配置
├── pyproject.toml
└── README.md
```

## 📄 License

MIT
