微信扫码
添加专属顾问
我要投稿
探索AI Agent新领域,从搭建MCP服务器开始。本文手把手教你使用VS Code和Python环境,快速入门Manus AI Agent工具。 核心内容: 1. VS Code和Python环境的下载与安装 2. VS Code配置Cline插件及GitHub账号授权 3. 搭建MCP服务端并初始化项目
最近一段时间,相信大家对于MCP的大名如雷贯耳,说的直白些,就是一个AI Agent工具服务器,本文就带您搭建简化版Manus走进AI Agent的大门。
笔者用过Claude等工具,为了方便大家快速入门,本文以VS Code来和大家分享MCP的搭建和使用。
1
下载工具
请先下载VS Code工具,下载链接:
https://code.visualstudio.com/download
如果是Windows系统,则下载Windows版本:
还需要下载Python环境,大家可以下载Anaconda工具来安装Python,下载链接:
https://www.anaconda.com/download
完成了VS Code和Anaconda Python环境的安装,就可以开始进入正轨了。
2
VSCode安装cline
打开VSCode工具:
选择左侧的扩展图标:
如果发现电脑操作系统版本不支持VSCode,还需要安装相关插件,可以按照提示安装相关VC++环境依赖。
在Extensions输入cline搜索:
安装即可。
3
VSCode配置cline
安装完成在左侧菜单会出现cline的图标。
我已经安装过,正常出现点击Get Started for Free进行登录授权。
要求使用账号登录:
建议使用GitHub,打开后会提示输入GitHub邮箱账号密码,没有可以就地注册GitHub。
输入GitHub账号后,会给你发一封邮件,找到校验码:
填入验证校验码,完成GitHub账号认证,并进行授权:
授权后可以看到Cline中支持MCP Servers的配置。
接着点击右上侧设置按钮:
在API Provider选择模型,选择DeepSeek:
APIKEY需要去DeepSeek开放平台申请:
打开DeepSeek开放平台:
https://platform.deepseek.com/usage
创建APIKEY并复制
将APIKEY复制的值填入
具体模型建议选择deepseek-ressoner,推理能力更强:
注意:开通DeepSeek KEY需要先充值,必须充值后才可用:
填写好你的指令角色,作为使用的角色:
然后保存:
4
搭建MCP服务端
打开电脑CMD窗口:
输入命令:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
开始安装uv:
安装完成后重启一下VS Code,保证uv环境生效。
用VS Code打开一个空白文件夹:
在空白文件夹下打开Terminal终端:
使用uv init weather来初始化一个名为 weather 的项目。
在终端进入weather项目:
cd weather
创建虚拟环境:
uv venv
使用uv add "mcp[cli]" httpx安装MCP依赖:
uv add "mcp[cli]" httpx
5
启动MCP服务
首先使用Python安装MCP依赖:
pip install fastmcp
在CMD终端安装依赖:
打开VS Code,在weather项目下新建selectInfo.py文件:
将以下代码拷入selectInfo.py文件:
from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("weather")
# Constants
NWS_API_BASE ="https://api.weather.gov"
USER_AGENT ="weather-app/1.0"
async def make_nws_request(url: str)-> dict[str, Any]| None:
"""Make a request to the NWS API with proper error handling."""
headers ={
"User-Agent": USER_AGENT,
"Accept":"application/geo+json"
}
async with httpx.AsyncClient() as client:
try:
response = await client.get(url, headers=headers, timeout=30.0)
response.raise_for_status()
return response.json()
except Exception:
return None
def format_alert(feature: dict)-> str:
"""Format an alert feature into a readable string."""
props = feature["properties"]
returnf"""
Event:{props.get('event','Unknown')}
Area:{props.get('areaDesc','Unknown')}
Severity:{props.get('severity','Unknown')}
Description:{props.get('description','No description available')}
Instructions:{props.get('instruction','No specific instructions provided')}
"""
@mcp.tool()
async def get_alerts(state: str) -> str:
"""Get weather alerts for a US state.
Args:
state: Two-letter US state code (e.g. CA, NY)
"""
url = f"{NWS_API_BASE}/alerts/active/area/{state}"
data = await make_nws_request(url)
if not data or "features" not in data:
return "Unable to fetch alerts or no alerts found."
if not data["features"]:
return "No active alerts for this state."
alerts = [format_alert(feature) for feature in data["features"]]
return "\n---\n".join(alerts)
@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
"""Get weather forecast for a location.
Args:
latitude: Latitude of the location
longitude: Longitude of the location
"""
# First get the forecast grid endpoint
points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
points_data = await make_nws_request(points_url)
if not points_data:
return "Unable to fetch forecast data for this location."
# Get the forecast URL from the points response
forecast_url = points_data["properties"]["forecast"]
forecast_data = await make_nws_request(forecast_url)
if not forecast_data:
return "Unable to fetch detailed forecast."
# Format the periods into a readable forecast
periods = forecast_data["properties"]["periods"]
forecasts = []
for period in periods[:5]: # Only show next 5 periods
forecast = f"""
{period['name']}:
Temperature:{period['temperature']}°{period['temperatureUnit']}
Wind:{period['windSpeed']}{period['windDirection']}
Forecast:{period['detailedForecast']}
"""
forecasts.append(forecast)
return"\n---\n".join(forecasts)
if __name__ =="__main__":
# Initialize and run the server
mcp.run(transport='stdio')
其中运行MCP服务器的命令:mcp.run(transport='stdio')
打开VS Code终端,在weather项目下执行:
uv run selectInfo.py
6
在cline中配置MCP Server
在VSCode左侧打开Cline,点击MCP Server进行配置。
点击配置MCP Servers:
在右侧的路径中根据你的真实目录改一下,我的是:
{
"mcpServers":{
"weather":{
"command":"uv",
"args":[
"--directory",
"E:\\代码前端分支Git\\consult\\weather",
"run",
"selectInfo.py"
]
}
}
}
连接成功后绿色表示成功:
7
使用MCP
前面配置好了MCP Server,并提供了查询天气的服务,现在可以尝试使用了。
在VS Code左侧打开Cline:
可以开始你的任务:
在思考:
因为当前采用的是国际天气函数,我们试试换一个任务:
选择任务后,提示我们修改代码:
Save,修改后再度查询:
提示申请新APIKEY指南,按照步骤查看申请指南:
一步步得按照我们的操作进行:
提示信息:
具体信息都给出了:
按照步骤AI Agent就能一步步去完成,具体信息大家可以自己去操作,本文只完成分享,帮你构建一个自己的Manus。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-05-27
2025年彻底改变我工作流程的10款AI工具
2025-05-27
AI的落地难题、应用案例和生产率悖论
2025-05-27
一句话生成教学视频?我用这个AI做了两节课,效果惊人!(附实操)
2025-05-27
AI领域基础概念(上)
2025-05-27
对话YouMind创始人玉伯:挑战抖音的男人|100 AI Creators
2025-05-27
在AI愈发强大的世界中,教师应该教什么,学生应该学什么?
2025-05-26
V0做不到、Bolt搞不定,Youware用MCP一键解决网页生成最大难题
2025-05-26
AI Agent迈向中央舞台:深度解析2025年进化新格局
2025-03-06
2024-09-04
2025-01-25
2024-10-30
2024-09-26
2024-09-03
2025-03-12
2024-12-11
2025-02-18
2024-12-25
2025-05-27
2025-05-24
2025-05-23
2025-05-22
2025-05-21
2025-05-21
2025-05-20
2025-05-20