> 技术文档 > vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp


文章目录

    • 1、前期准备
    • 2、配置blender和qgis
    • 3、自己写一个mcp服务
    • 4、一些现成的MCP服务

前天配置的windsurf免费额度太少了,还没试几下就用完了,在没有形成真正的生产力之前付费是不明智的,因此今天推荐一个免费额度更高的工作流:vscode+cline+Gemini。

1、前期准备

首先需要安装vscode,然后到插件市场安装cline。

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

这一步很重要,申请一个Gemini api,这个每天刷新免费额度,而且用起来也不错。首先我们导航到这个网址,点击Get API key,复制我们得到的apikey,Google很慷慨,每天提供1500的调用,但是刷新时间是在15:00,尝试下来是完全够用的(感谢Google)
vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp
最后打开我们安装好的cline,按照图示将key填进去保存即可

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

2、配置blender和qgis

在根据上一篇文章安装好这两个插件后,cline的配置就很简单,我们直接将mcp_config.json的内容复制到cline这里就好

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

你可能会看到红色警告,不需要担心,只要是右侧显示绿色就可

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

而后你就可以尝试连接mcp服务了,但是注意你要打开相应的软件,点击启动mcp服务才可以

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

3、自己写一个mcp服务

自己也可以写mcp服务,扩展AI的能力,这里我以Model Context Protocol官网提供的weather为例,大家也可以去这个官网详细了解下MCP,可以根据自己的工作场景配置专属自己的mcp(甚至可以使用ai让他自己写mcp给自己用)。
首先打开命令行工具,切换到一个你想保存此mcp的地方依次执行下列命令

// 创建weather文件夹uv init weathercd weather// 创建虚拟环境uv venv.venv\\Scripts\\activate// 安装必要的包uv add mcp[cli] httpx// 新建py文件echo. > weather.py

而后打开新建的weather.py文件夹,把下面的代码粘贴过去,这是一个查询美国天气的示例代码(可以换为高德查询国内的)

# -*- coding: utf-8 -*-\"\"\"Created on Thu Mar 20 14:17:48 2025@author: 13649\"\"\"from typing import Anyimport httpxfrom mcp.server.fastmcp import FastMCP# Initialize FastMCP servermcp = FastMCP(\"weather\")# ConstantsNWS_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 Nonedef format_alert(feature: dict) -> str: \"\"\"Format an alert feature into a readable string.\"\"\" props = feature[\"properties\"] return f\"\"\"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\')

完成之后保存,在终端运行此程序uv run weather.py,确定没有报错

vscode+cline+Gemini配置一个免费的mcp助手_vscode mcp

而后打开cline的mcp配置,添加上这个mcp

\"weather\": { \"command\": \"uv\", \"args\": [ \"--directory\", \"C:\\\\Users\\\\13649\\\\Desktop\\\\python\\\\weather\", \"run\", \"weather.py\" ]}

4、一些现成的MCP服务

最简单的就是cline的MCP市场提供的各种MCP服务了,可以直接选择自己喜欢的安装即可,还有一些其他的mcp-server网点,都是大同小异,整理如下:

smithery

pulse MCP

Awesome MCP Servers

MCP.so

Glama MCP

Cursor directory

portkey.ai

mcp官方开源工具

ps(相信未来越来越多的mcp服务会推出,之前的manus感觉就像是个大的mcp集合,以后的工作流将会巨变!)