MCP 服务器示例
此代码库包含一个用于教学目的的模型上下文协议 (MCP) 服务器实现。此代码演示了如何构建一个可与各种 LLM 客户端集成的功能性 MCP 服务器。
MCP 服务器示例
此代码库包含一个用于教学目的的模型上下文协议 (MCP) 服务器实现。此代码演示了如何构建一个可与各种 LLM 客户端集成的功能性 MCP 服务器。
参考:
什么是 MCP?
MCP(模型上下文协议)是一种开放协议,它规范了应用程序向 LLM 提供上下文的方式。MCP 就像 AI 应用程序的 USB-C 端口一样,它提供了一种标准化的方式,将 AI 模型连接到不同的数据源和工具。
主要优点
- 越来越多的预建集成可供您的 LLM 直接插入
- 灵活地在 LLM 提供商和供应商之间切换
- 保护基础架构内数据的最佳实践
架构概述
MCP 遵循客户端-服务器架构,其中主机应用程序可以连接到多个服务器:
- MCP 主机:像 Claude Desktop、IDE 或 AI 工具这样的程序,需要通过 MCP 访问数据
- MCP 客户端:与服务器保持 1:1 连接的协议客户端
- MCP 服务器:通过标准化模型上下文协议公开特定功能的轻量级程序
- 数据源:MCP 服务器可以访问的本地(文件、数据库)和远程服务(API)
核心 MCP 概念
MCP 服务器可以提供三种主要类型的功能:
- 资源:客户端可以读取的类似文件的数据(例如 API 响应或文件内容)
- 工具:可由 LLM 调用的函数(经用户批准)
- 提示:预先编写的模板,帮助用户完成特定任务
系统要求
- Python 3.10 或更高版本
- MCP SDK 1.2.0 或更高版本
uv
包管理器
安装
将 MCP 添加到您的 Python 项目我们建议使用 uv 来管理您的 Python 项目。
如果您尚未创建 uv 管理项目,请创建一个:
然后将 MCP 添加到您的项目依赖项中:
或者,对于使用 pip 作为依赖项的项目:
运行独立的 MCP 开发工具 要使用 uv 运行 mcp 命令:
快速入门
让我们创建一个简单的 MCP 服务器,它公开一个计算器工具和一些数据:
您可以在 Claude Desktop 中安装此服务器并通过运行以下命令立即与其交互:
或者,您可以使用 MCP 检查器进行测试:
由Antonio Scapellato用❤️制作
资源:
执照
本项目遵循 MIT 许可证。详情请参阅LICENSE文件。
This server cannot be installed
模型上下文协议服务器的教育实现,演示了如何构建与各种 LLM 客户端集成的功能性 MCP 服务器。
Related MCP Servers
- AsecurityAlicenseAqualityA beginner-friendly Model Context Protocol (MCP) server that helps users understand MCP concepts, provides interactive examples, and lists available MCP servers. This server is designed to be a helpful companion for developers working with MCP. Also comes with a huge list of servers you can install.Last updated -3936JavaScriptApache 2.0
- AsecurityAlicenseAqualityAn educational implementation of a Model Context Protocol server that demonstrates how to build a functional MCP server for integrating with various LLM clients like Claude Desktop.Last updated -188PythonMIT License
- -securityAlicense-qualityA Model Context Protocol (MCP) server that enables Claude or other LLMs to fetch content from URLs, supporting HTML, JSON, text, and images with configurable request parameters.Last updated -PythonMIT License
- -security-license-qualityA specialized server that helps users create new Model Context Protocol (MCP) servers by providing tools and templates for scaffolding projects with various capabilities.Last updated -1TypeScript