内容
# Ollama-MCP Bridge WebUI
一个 TypeScript 实现,连接本地 LLM(通过 Ollama)与 Model Context Protocol (MCP) 服务器,并提供网页界面。这个桥接允许开源模型使用与 Claude 相同的工具和功能,使得强大的本地 AI 助手能够完全在您的硬件上运行。
## 特性
- **多 MCP 集成**:同时连接多个 MCP 服务器
- **工具检测**:根据查询自动识别使用的工具
- **网页界面**:干净的用户界面,带有可折叠的工具描述
- **全面的工具集**:文件系统、网页搜索和推理能力
## 设置
### 自动安装
设置桥接的最简单方法是使用附带的安装脚本:
```bash
./install.bat
```
该脚本将:
1. 检查并在需要时安装 Node.js
2. 检查并在需要时安装 Ollama
3. 安装所有依赖项
4. 创建工作区目录(../workspace)
5. 设置初始配置
6. 构建 TypeScript 项目
7. 下载 Ollama 的 Qwen 模型
运行脚本后,您只需:
1. 将您的 API 密钥添加到 `.env` 文件中(配置中的 `$VARIABLE_NAME` 引用将被实际值替换)
### 手动设置
如果您更喜欢手动设置:
1. 从 [ollama.com/download](https://ollama.com/download) 安装 Ollama
2. 拉取 Qwen 模型:`ollama pull qwen2.5-coder:7b-instruct-q4_K_M`
3. 安装依赖项:`npm install`
4. 创建工作区目录:`mkdir ../workspace`
5. 在 `.env` 中配置 API 密钥
6. 构建项目:`npm run build`
## 配置
桥接通过两个主要文件进行配置:
### 1. bridge_config.json
该文件定义了 MCP 服务器、LLM 设置和系统提示。环境变量使用 `$VARIABLE_NAME` 语法引用。
示例:
```json
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": [
"To/Your/Directory/Ollama-MCP-Bridge-WebUI/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js",
"To/Your/Directory/Ollama-MCP-Bridge-WebUI/../workspace"
],
"allowedDirectory": "To/Your/Directory/Ollama-MCP-Bridge-WebUI/../workspace"
},
"brave-search": {
"command": "node",
"args": [
"To/Your/Directory/Ollama-MCP-Bridge-WebUI/node_modules/@modelcontextprotocol/server-brave-search/dist/index.js"
],
"env": {
"BRAVE_API_KEY": "$BRAVE_API_KEY"
}
},
"sequential-thinking": {
"command": "node",
"args": [
"To/Your/Directory/Ollama-MCP-Bridge-WebUI/node_modules/@modelcontextprotocol/server-sequential-thinking/dist/index.js"
]
}
},
"llm": {
"model": "qwen2.5-coder:7b-instruct-q4_K_M",
"baseUrl": "http://localhost:11434",
"apiKey": "ollama",
"temperature": 0.7,
"maxTokens": 8000
},
"systemPrompt": "You are a helpful assistant that can use various tools to help answer questions. You have access to three main tool groups: 1) Filesystem operations - for working with files and directories, 2) Brave search - for finding information on the web, 3) Sequential thinking for complex problem-solving. When a user asks a question that requires external information, real-time data, or file manipulation, you should use a tool rather than guessing or using only your pre-trained knowledge."
}
```
### 2. .env 文件
该文件存储敏感信息,如 API 密钥:
```
# Brave Search API key
BRAVE_API_KEY=your_brave_key_here
```
桥接将自动用您 `.env` 文件中的实际值替换配置中的 `$BRAVE_API_KEY`。
## 使用
### 启动桥接
只需运行:
```bash
./start.bat
```
这将启动带有网页界面的桥接。
### 网页界面
在浏览器中打开 http://localhost:8080(或控制台中显示的端口)以访问网页界面。
## 许可证
MIT 许可证 - 详细信息请参见 LICENSE 文件。