关于 🦙 ollama-mcpo-adapter
ollama-mcpo-adapter 是 Python 适配器,可将 MCPO 暴露的工具转换为 Ollama 兼容的函数格式。它可连接现有 MCPO 实例,也可通过可选服务组件启动 MCPO。
主要功能
- 01连接 MCPO 实例
- 02以 Ollama 函数格式列出工具
- 03通过 MCPOService 启动 MCPO
- 04分发 Ollama 响应中的工具调用
适用场景
- 01将 MCPO 工具提供给 Ollama 聊天请求
- 02从现有 MCPO 实例发现函数
- 03根据 MCP 配置启动本地 MCPO 服务
MCP 相关
它连接通过 OpenAPI 暴露 MCP 工具的 MCPO,并将工具描述转换为 Ollama 兼容函数。可选服务组件还能根据 MCP 配置启动 MCPO。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
🦙 ollama-mcpo-adapter
使用简单的 Python 适配器和可选的运行时服务,将 MCPO(MCP 到 OpenAPI 的代理服务)工具公开为兼容 Ollama 的函数。
✨ 功能
🚀 快速开始
1. 安装
pip install ollama-mcpo-adapter
使用现有的 MCPO 实例
假设你已像这样运行 MCPO:
uvx mcpo --port 5090 --config /path/to/mcp_config.json
你可以使用此适配器,以 Ollama ToolCall 格式获取所有可用函数:
from ollama_mcpo_adapter import OllamaMCPOAdapter
adapter = OllamaMCPOAdapter(host="localhost", port=5090, config_path="/path/to/mcp_config.json")
# Gets tool descriptions from MCPO FastAPI /docs
tools = adapter.list_tools_ollama()
可以省略配置路径。但提供配置时,发现 MCP 服务名称会更加可靠。 否则,服务名称将从 MCPO 提供的自动生成的 OpenAPI 文档中读取;这些文档将来可能会发生变化。
使用本地 MCPO 服务
你可以使用此扩展启动 MCPO 服务:
from ollama_mcpo_adapter import MCPOService
# Provide your mcp config as JSON file or dictionary
mcp_config = {
"mcpServers": {
"time": {"command": "uvx", "args": ["mcp-server-time", "--local-timezone=Europe/Berlin"]}
}
}
mcpo = MCPOService("127.0.0.1", 4090, config=mcp_config,
# -OR- from an existing mcp_config file
config_path="path/to/mcp_config.json")
# MCPOSService class handles MCPO server start-up and shutdown and in a subprocess
mcpo.start(wait=True)
...
mcpo.stop()
然后使用此适配器获取所有可用工具:
from ollama_mcpo_adapter import OllamaMCPOAdapter
adapter = OllamaMCPOAdapter("127.0.0.1", 4090)
tools = adapter.list_tools_ollama()
将其发送给 Ollama:
from ollama import Client
# Send a prompt to Ollama using discovered tools
client = Client(host="http://127.0.0.1:11434")
response = client.chat(
model="qwen2.5-coder:14b-instruct-q4_K_M",
messages=[{"role": "user", "content": "Write a file..."}],
tools=tools,
)
最后调用这些工具:
# Handle any tool calls
if response.message.tool_calls:
adapter.call_tools_from_response(response.message.tool_calls)
环境变量
-
MS Windows npx 路径;你可以在配置解析器中将 npx 覆盖为 npx 的路径
示例:
WIN_NODEJS_NPX_PATH=C:\Program Files\nodejs\npx.cmd
🧪 运行测试
pytest
📂 项目结构
ollama_mcpo_adapter/
├── adapter.py # Tool discovery + Ollama integration
├── service.py # Optional: launch MCPO programmatically
├── service_runner.py # MCPO subprocess control
├── config_parser.py # MCP config parsing helpers
├── dispatcher.py # Dispatch tool calls
📜 许可证
MIT。请参阅 LICENSE。
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。