Skip to main content

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)

Source distribution for mcp-study 0.1.0
File Size Uploaded
mcp_study-0.1.0.tar.gz 27.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-study 0.1.0
File Interpreter ABI Platform
mcp_study-0.1.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page