[特殊字符]颠覆MCP!Open WebUI新技术mcpo横空出世!支持ollama!轻松支持各种MCP Server!Cline+Claude3.7轻松开发论文检索MCP Server!

🔥🔥🔥本篇笔记所对应的视频:🚀颠覆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?

MCPo 是一个简单、可靠的代理服务器,能够将任何基于 MCP 协议的工具转换为兼容 OpenAPI 的 HTTP 服务器。它通过标准化 RESTful API 接口,让复杂的工具变得易于使用,并支持与大语言模型(LLM)代理和应用程序的无缝交互。

核心功能:

  • 即时兼容性:支持 OpenAPI 工具、SDK 和用户界面,无需额外配置。
  • 安全性与稳定性:采用标准化的 HTTPS 传输协议,支持 JWT 和 API 密钥认证。
  • 自动生成文档:无需手动配置,自动生成交互式 Swagger UI 文档。
  • 纯 HTTP 支持:无需额外的套接字或胶合代码,简化开发流程。

MCPo 的工作原理

MCPo 的核心在于其代理功能,它能够动态发现 MCP 工具并生成 REST API 端点,同时提供人性化的 OpenAPI 文档。以下是其典型工作流程:

  1. 启动 MCPo 服务器,例如: 或通过 Python:

    uvx mcpo --port 8000 -- your_mcp_server_command
    
    
    pip install mcpo
    mcpo --port 8000 -- your_mcp_server_command
    
    
  2. 自动生成 API 文档,访问地址为 http://localhost:8000/docs

  3. 用户可以直接调用生成的 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 引入了以下新特性:

  • 图像内容支持:现在可以直接处理 MCP 工具生成的图像内容,并以二进制格式返回给用户,用于动态图表、AI艺术等场景。
  • CLI API 密钥认证:通过 -api-key 参数轻松保护端点,适用于公共或多代理部署。
  • 灵活的跨域访问控制(CORS):新增 -cors-allow-origins 参数,为前端应用和远程 UI 集成提供支持,同时保持安全性。

为什么选择 MCPo?

相比原生 MCP 协议,MCPo 提供了显著优势:

  • 用户友好的接口:不需要学习新的协议,仅需熟悉 HTTP REST 接口即可操作。
  • 即插即用的集成能力:兼容数千种现有工具和服务。
  • 强大的文档支持:自动维护准确且易用的文档。
  • 安全与稳定性保障:基于成熟框架(如 FastAPI),确保高性能和长久支持。

社区反馈与未来发展

MCPo 项目已在 GitHub 和 Reddit 社区中引发广泛讨论。开发者对其易用性和强大的功能表示认可,同时也提出了改进建议,例如增加 SSL 支持和更灵活的配置选项。

随着人工智能工具需求的增长,MCPo 有望成为连接 AI 工具与标准化接口的重要桥梁,为开发者提供更高效、更安全的解决方案。


🚀安装ollama

Ollama

🚀在ollama中安装模型

ollama run gemma3

🚀安装mcpo

# 安装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

# 查看文档:
<http://localhost:8000/docs>
<http://localhost:8000/openapi.json>

# 使用配置文件启动
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"]
    }
  }
}

🚀安装Open WebUI

# pip 安装
pip install -U open-webui

# 启动 
open-webui serve

# 源代码安装
git clone -b v0.6.0 <https://github.com/open-webui/open-webui.git>
cd open-webui/

cp -RPp .env.example .env

npm i
npm run build

cd ./backend
pip install -r requirements.txt -U

# 启动
bash start.sh

🚀测试通过MCPO调用MCP Fetch server

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(
            "<http://localhost:8000/fetch>",
            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 = "<https://www.aivi.fyi/aiagents/RooCode-Gemini2.5Pro-OpenAIAgentsSDK>"
    result = fetch_webpage(target_url)
    print(result)

<think>好的,用户想了解如何通过MCP调用Ollama模型,并且需要方法示例。首先,我需要明确MCP是什么,可能是指某个特定的中间件、平台或工具。结合用户提供的引用内容,尤其是引用[1]提到SpringAI调用本地Ollama模型,可能MCP是Spring框架中的一个模块,或者用户可能有拼写错误,比如应该是“Spring”而不是“MCP”。需要进一步确认。 查看引用内容,引用[1]提到在Spring中调用Ollama模型,通过API接口。引用[3]提到Ollama支持很多模型,比如deepseek-r1,安装命令是`ollama run deepseek-r1:7b`。可能用户的问题是关于如何在Spring项目中配置和使用Ollama模型,可能MCP是笔误,或者指某个特定的中间件服务。 假设用户确实是指Spring框架中的调用方法,那么需要参考Spring AI的文档。根据引用[1],Spring AI提供了AI Models和Chat Models的接口,因此调用Ollama可能需要配置相应的模型参数和API地址。 接下来需要考虑如何配置Spring项目,添加依赖,创建配置类,以及编写调用代码。同时,用户需要示例代码,所以需要提供具体的Java或Kotlin代码片段,展示如何初始化Ollama的客户端,发送请求,处理响应。 另外,用户可能遇到的问题包括模型服务的启动、端口配置是否正确,以及如何处理不同的模型版本。需要确保Ollama服务在本地运行,并且端口正确(如默认的11434)。同时,模型名称需要与安装的模型一致,比如`deepseek-r1:7b`。 可能还需要解释配置文件中的参数,如baseUrl和model,以及如何通过Spring的依赖注入来获取OllamaClient实例。此外,可能需要处理异常情况,比如连接失败或模型未找到的情况。 最后,生成的相关问题需要围绕调用Ollama模型的其他方面,比如参数调优、流式响应处理、集成到Web应用,以及模型选择建议。这些问题可以帮助用户进一步深入使用Ollama模型。</think>### 通过MCP调用Ollama模型的方法示例 根据您提供的引用内容,推测"MCP"可能指向中间件服务或框架(如Spring框架中的模块),以下以**Spring AI调用本地Ollama模型**为例说明具体实现步骤: --- #### 步骤1:启动Ollama模型服务 首先确保已通过Ollama安装并运行所需模型(以deepseek-r1:7b为例): ```bash ollama run deepseek-r1:7b ``` 服务默认运行在`http://localhost:11434`[^3] --- #### 步骤2:Spring项目配置 1. **添加依赖**:在`pom.xml`中引入Spring AI模块 ```xml <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-ollama-spring-boot-starter</artifactId> <version>0.8.1</version> </dependency> ``` 2. **配置文件**:`application.yml` ```yaml spring: ai: ollama: base-url: http://localhost:11434 chat: model: deepseek-r1:7b ``` --- #### 步骤3:代码实现 ```java import org.springframework.ai.ollama.OllamaClient; import org.springframework.ai.ollama.api.OllamaApi; import org.springframework.ai.ollama.api.OllamaOptions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController public class OllamaController { private final OllamaClient ollamaClient; @Autowired public OllamaController(OllamaApi ollamaApi) { this.ollamaClient = new OllamaClient(ollamaApi); } @GetMapping("/ask") public String askQuestion(@RequestParam String prompt) { OllamaOptions options = OllamaOptions.create() .withTemperature(0.7f); return ollamaClient.generate(prompt, options).getGeneration().getText(); } } ``` --- #### 关键参数说明 1. `temperature`:控制生成文本的随机性(0-1) 2. `top_p`:核采样概率阈值 3. `max_tokens`:最大输出长度[^2] ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值