该项目展示了模型上下文协议(MCP)服务器与Ollama之间的集成,允许AI模型通过统一接口与各种工具进行交互。
claude_desktop_config.json的mcp-config.json进行简单配置前置条件:
Node.js(版本18或更高)
已安装并运行Ollama
全局安装您想要使用的MCP工具:
# 文件系统操作
npm install -g @modelcontextprotocol/server-filesystem
# 网络研究
npm install -g @mzxrai/mcp-webresearch
克隆并安装:
git clone https://github.com/ausboss/mcp-ollama-agent.git
cd mcp-ollama-agent
npm install
在mcp-config.json中配置您的工具和受支持的Ollama模型:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "./"]
},
"webresearch": {
"command": "npx",
"args": ["-y", "@mzxrai/mcp-webresearch"]
}
},
"ollama": {
"host": "http://localhost:11434",
"model": "qwen2.5:latest"
}
}
运行演示以测试文件系统和网络研究工具(无需大型语言模型):
npx tsx ./src/demo.ts
或者启动带有Ollama的聊天界面:
npm start
mcpServers部分添加任何兼容MCP的服务器此示例使用了这个模型qwen2.5:latest
对话已开始。输入“exit”结束对话。
你:你能使用你的列表目录工具查看test-directory中的内容,然后使用你的读取文件工具读给我听吗?
模型正在使用工具帮助回答...
使用工具:list_directory
参数:{ path: 'test-directory' }
工具结果:[ { type: 'text', text: '[FILE] test.txt' } ]
助手:
模型正在使用工具帮助回答...
使用工具:read_file
参数:{ path: 'test-directory/test.txt' }
工具结果:[ { type: 'text', text: 'rosebud' } ]
助手:`test-directory`中的`test.txt`文件的内容是:
rosebud
你:谢谢
助手:不客气!如果您有其他请求或需要进一步的帮助,请随时提问。
某些本地模型可能需要帮助选择工具。自定义ChatManager.ts中的系统提示以改进工具使用。
欢迎贡献!请随意提交问题或拉取请求。