MCP Server
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Integrations
Enables retrieval of CrewAI documentation, helping AI assistants gather information about CrewAI's agent collaboration framework
Uses Google Search via the Serper API to retrieve targeted documentation from supported framework websites
Provides access to LangChain documentation, allowing AI assistants to retrieve specific information about the LangChain framework for building AI applications
Python 从0到1构建MCP Server & Client
中文 | English
简介
MCP Server 是实现模型上下文协议(MCP)的服务器,旨在为 AI 模型提供一个标准化接口,连接外部数据源和工具,例如文件系统、数据库或 API。
MCP 的优势
在 MCP 出现前,AI 调用工具基本通过 Function Call 完成,存在以下问题:
- 不同的大模型厂商 Function Call 格式不一致
- 大量 API 工具的输入和输出格式不一致,封装管理繁琐
MCP 相当于一个统一的 USB-C,不仅统一了不同大模型厂商的 Function Call 格式,也对相关工具的封装进行了统一。
MCP 传输协议
目前 MCP 支持两种主要的传输协议:
- Stdio 传输协议
- 针对本地使用
- 需要在用户本地安装命令行工具
- 对运行环境有特定要求
- SSE(Server-Sent Events)传输协议
- 针对云服务部署
- 基于 HTTP 长连接实现
项目结构
MCP Server
- Stdio 传输协议(本地)
- SSE 传输协议(远程)
MCP Client(客户端)
- 自建客户端(Python)
- Cursor
- Cline
环境配置
1. 安装 UV 包
MacOS/Linux:
Windows:
2. 初始化项目
构建工具函数
为了让大模型能访问市面上主流框架的技术文档,我们主要通过用户输入的 query,结合指定 site 特定域名的谷歌搜索进行搜索相关网页,并对相关网页进行解析提取网页文本并返回。
1. 构建相关文档映射字典
2. 构建 MCP 工具
封装 MCP Server (基于 Stdio 协议)
1. MCP Server (Stdio)
启动命令:
2. 客户端配置
2.1 基于 Cline
首先在 Visual Studio Code 安装 Cline 插件,然后进行配置 MCP
成功绑定如图(左侧绿灯):
2.2 基于 Cursor
项目根目录创建 .cursor 文件夹,并创建 mcp.json 文件,如:
然后粘贴以下内容到 mcp.json
成功配置如图:
在 Features 开启 MCP 服务
通过对话它便通过 MCP 获取相关文档信息进行回答:
构建 SSE MCP Server (基于 SSE 协议)
1. 封装 MCP Server
启动命令:
以上 MCP server 代码直接在你的云服务器跑即可。
2. 构建 MCP Client
启动命令:
Client 日志:
Server 日志:
以上便是 Python 从 0 到 1 搭建 MCP Server 以及 MCP Client 的完整教程。有不对的地方请多多指教。
参考相关资料:
This server cannot be installed
Implements the Model Context Protocol (MCP) to provide AI models with a standardized interface for connecting to external data sources and tools like file systems, databases, or APIs.