本篇笔记所对应的视频:颠覆MCP!Open WebUI新技术mcpo横空出世!支持ollama!轻松支持各种MCP Server!Cline+Claude3.7轻松开发MCP服务_哔哩哔哩_bilibili
Open WebUI 的 MCPo 项目:将 MCP 工具无缝集成到 OpenAPI 的创新解决方案
随着人工智能工具和模型的快速发展,如何高效、安全地将这些工具集成到标准化的 API 接口中成为了开发者面临的重要挑战。Open WebUI 的 MCPo 项目(Model Context Protocol-to-OpenAPI Proxy Server)正是为了解决这一问题而设计的。本文将带您深入了解 MCPo 的功能、优势及其对开发者生态的影响。
MCPo 是一个简单、可靠的代理服务器,能够将任何基于 MCP 协议的工具转换为兼容 OpenAPI 的 HTTP 服务器。它通过标准化 RESTful API 接口,让复杂的工具变得易于使用,并支持与大语言模型(LLM)代理和应用程序的无缝交互。
MCPo 的核心在于其代理功能,它能够动态发现 MCP 工具并生成 REST API 端点,同时提供人性化的 OpenAPI 文档。以下是其典型工作流程:
启动 MCPo 服务器,例如: 或通过 Python:
uvx mcpo --port 8000 -- your_mcp_server_command
pip install mcpo
mcpo --port 8000 -- your_mcp_server_command
自动生成 API 文档,访问地址为 http://localhost:8000/docs
。
用户可以直接调用生成的 API 端点,通过 HTTP 客户端或其他工具进行交互。
此外,MCPo 支持通过配置文件管理多个 MCP 工具,使不同工具可以通过唯一路由访问。例如:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
},
"time": {
"command": "uvx",
"args": ["mcp-server-time", "--local-timezone=America/New_York"]
}
}
}
根据项目最新发布的更新日志,MCPo 引入了以下新特性:
-api-key
参数轻松保护端点,适用于公共或多代理部署。-cors-allow-origins
参数,为前端应用和远程 UI 集成提供支持,同时保持安全性。相比原生 MCP 协议,MCPo 提供了显著优势:
MCPo 项目已在 GitHub 和 Reddit 社区中引发广泛讨论。开发者对其易用性和强大的功能表示认可,同时也提出了改进建议,例如增加 SSL 支持和更灵活的配置选项。
随着人工智能工具需求的增长,MCPo 有望成为连接 AI 工具与标准化接口的重要桥梁,为开发者提供更高效、更安全的解决方案。
Ollama
ollama run gemma3
# 安装mcpo
pip install mcpo
mcpo --port 8000 --api-key "top-secret" -- your_mcp_server_command
# 启动时间mcp server
uvx mcpo --port 8000 --api-key "top-secret" -- uvx mcp-server-time --local-timezone=America/New_York
# 启动fetch mcp server
uvx mcpo --port 8000 -- uvx mcp-server-fetch
# 查看文档:
# 使用配置文件启动
mcpo --config /path/to/config.json
# 配置文件示例:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
},
"time": {
"command": "uvx",
"args": ["mcp-server-time", "--local-timezone=America/New_York"]
}
}
}
# pip 安装
pip install -U open-webui
# 启动
open-webui serve
# 源代码安装
git clone -b v0.6.0
cd open-webui/
cp -RPp .env.example .env
npm i
npm run build
cd ./backend
pip install -r requirements.txt -U
# 启动
bash start.sh
import requests
import json
def fetch_webpage(url, max_length=10000, start_index=0, raw=False):
"""
Fetch content from a URL using the MCP Fetch server.
Args:
url (str): The URL to fetch
max_length (int): Maximum number of characters to return
start_index (int): Start content from this character index
raw (bool): Get raw HTML content without markdown conversion
Returns:
dict: The response from the server containing the fetched content
"""
try:
# Make a POST request to the fetch endpoint
response = requests.post(
"",
json={
"url": url,
"max_length": max_length,
"start_index": start_index,
"raw": raw
}
)
# Ensure the request was successful
response.raise_for_status()
# Parse the response
return response.json()
except Exception as e:
return {"error": str(e)}
# Example usage
if __name__ == "__main__":
# Fetch the specific URL you requested
target_url = ""
result = fetch_webpage(target_url)
print(result)