
maximerivest/mcp2py 是从 https://github.com/maximerivest/mcp2py. 导入的 MCP 服务器候选
概览
maximerivest/mcp2py 是从 https://github.com/maximerivest/mcp2py. 导入的 MCP 服务器候选
概述(AI 翻译)
MCP(模型上下文协议)是人工智能工具的新兴标准, 资源。该标准与普通 REST API 服务器兼容,但 添加额外的元数据来描述工具、资源和提示词 机器可读的方式。这为我们提供了一个很好的机会 创建完全自动映射到这些MCP的Python模块 服务器。这种方法最大的优势是我们可以使用任何 MCP 服务器就像一个原生的 Python 库,零 配置。这对开发Python软件来说可能非常重要 映射到 REST API 的开发套件非常常见,而且相当 这是一个手动流程。现在,如果托管REST API的组织也 提供MCP接口,我们可以自动生成Python SDK 轻松完成!如果你不完全明白也别担心。 你仍然可以利用MCP2py的强大功能,而无需了解所有 MCP的详细信息。你只需要知道:如果你想用程序化的方式 与网站互动时,他们很可能拥有API,并且随着时间推移 而且很可能他们有针对该API的MCP接口。 如果他们会,你就不必学一整套网页编程
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
mcp2py: Turn any MCP server into a python module
MCP (Model Context Protocol) is an emerging standard for AI tools and resources. The standard is compatible with normal REST API servers, but adds extra metadata to describe tools, resources, and prompts in a machine-readable way. This provides us with a great opportunity to create Python modules that completely and automatically map to these MCP servers. The biggest advantage of this approach is that we can use any MCP server as if it were a native Python library, with zero configuration. This can be quite a big deal as creating Python software development kits that map to REST APIs is extremely common and was quite a manual process. Now, if the organization hosting the REST API also provides an MCP interface, we can automatically generate a Python SDK for it with zero effort! Don’t worry if this is not all clear to you. You can still leverage the power of mcp2py without knowing all the details of MCP. All you need to know is: if you want to programmatically interact with a website, it is likely that they have an API and as time goes on it is very likely that they have an MCP interface for that API. If they do, you don’t have to learn a whole set of web programming skills, you can just use mcp2py to load the MCP server and start calling functions right away as if it were a native Python library!
Another cool thing to note is that servers don’t have to be running remotely. You can (and have) a lot of servers running on your own personal computer right now. This is useful to have different programs, possibly in different programming languages, talking to each other. As apps that you install will more and more open up a small local server on your machine to let LLMs interact with them, you will also be able to leverage mcp2py to interact with these local servers. That could look like Slack opening a server that lets you query your messages. If so, you could then use mcp2py and have a Python module (a library in essence) that lets you query your Slack messages directly from Python. Super powerful!
Overview
Here is a very simple example of using mcp2py to interact with your local filesystem. That is not very useful as you could just use the built-in Python libraries to do that, but it serves as a very simple example to illustrate how mcp2py works. In this snippet of code we use load to both start the MCP server (which is a Node.js server in this case) and connect to it. Once connected we can call the list_directory tool as if it were a native Python function:
from mcp2py import load
fstools = load("npx -y @modelcontextprotocol/server-filesystem /home")
fstools.list_directory("/home")
[DIR] maxime
This is similar to using the os library in Python:
import os
os.listdir("/home")
['maxime']
The main difference is that instead of going directly from Python to the system, we send commands to a local Node (JavaScript) server and that
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →