MCP Study
MCP (Model Context Protocol) 学习与实践项目,包含多个可直接使用的 MCP Server。
🚀 快速安装
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
# 启动天气服务
weather-server
# 启动数据库查询服务
sql-server
方式二:在 MCP Client 中连接
{
"mcpServers": {
"weather": {
"command": "weather-server"
},
"sql": {
"command": "sql-server"
}
}
}
方式三:用 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(接大模型)
# 先配置 .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
Metadata
Release files for mcp-study 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_study-0.1.0.tar.gz | 27.0 kB | Without provenance | Details for mcp_study-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_study-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_study-0.1.0-py3-none-any.whl |
Total release size: 60.7 kB
Release files / mcp_study-0.1.0.tar.gz
| Download URL | mcp_study-0.1.0.tar.gz |
|---|---|
| Size | 27.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04be34b6221c39c798391e468ca93673b62c7709b0fdb19938bda2c9d94fedfc
|
|
BLAKE2b-256 checksum How to use checksums |
08c7b559147569437d8a7728a638aa780b0f17a08945eb21eb45a57c576f927b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / mcp_study-0.1.0-py3-none-any.whl
| Download URL | mcp_study-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca8ae9e379424af23a4032feee985125cd7251412ff3b531cd0e13c8726642b4
|
|
BLAKE2b-256 checksum How to use checksums |
97c753fdbb0b5095393804117d0528cfb95b0a91124ec6337520237114e95114
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for mcp-study 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.