MCP 客户端功能

This commit is contained in:
2025-09-05 20:37:15 +08:00
parent 7eb22743d8
commit b2914be3c1
18 changed files with 978 additions and 123 deletions

View File

@ -149,3 +149,4 @@ Add options in the `.env` file from the diagram below in nonebot2 project.
| MARSHOAI_FIX_TOOLCALLS | `bool` | `true` | Fix tool calls or not |
| MARSHOAI_SEND_THINKING | `bool` | `true` | Send thinking chain or not |
| MARSHOAI_STREAM | `bool` | `false`| 是否通过流式方式请求 API **开启此项后暂无法使用函数调用,无法在 Bot 用户侧聊天界面呈现出流式效果** |
| MARSHOAI_ENABLE_MCP | `bool` | `false`| Enable MCP feature or not |

View File

@ -62,7 +62,8 @@ async def weather(location: str) -> str:
`on_function_call`装饰器用于标记一个函数为function call`description`参数用于描述这个函数的作用,`params`方法用于定义函数的参数,`String``Integer`等是OpenAI API接受的参数的类型`description`是参数的描述。这些都是给AI看的AI会根据这些信息来调用函数。
:::warning
参数名不得为`placeholder`。此参数名是Marsho内部保留的用于保证兼容性的占位参数。
参数名不得为`placeholder`。此参数名是Marsho内部保留的用于保证兼容性的占位参数。
部分函数名可能会与 MCP 工具名称冲突。
:::
```python

View File

@ -150,10 +150,5 @@ GitHub Models API 的限制较多,不建议使用,建议通过修改`MARSHOA
| MARSHOAI_FIX_TOOLCALLS | `bool` | `true` | 是否修复工具调用(部分模型须关闭,使用 vLLM 部署的模型时须关闭) |
| MARSHOAI_SEND_THINKING | `bool` | `true` | 是否发送思维链(部分模型不支持) |
| MARSHOAI_STREAM | `bool` | `false`| 是否通过流式方式请求 API **开启此项后暂无法使用函数调用,无法在 Bot 用户侧聊天界面呈现出流式效果** |
| MARSHOAI_ENABLE_MCP | `bool` | `false`| 是否启用 MCP 功能 |
#### 开发及调试选项
| 配置项 | 类型 | 默认值 | 说明 |
| ------------------------ | ------ | ------- | ---------------- |
| MARSHOAI_DEVMODE | `bool` | `false` | 是否启用开发者模式 |

View File

@ -32,6 +32,27 @@ title: 使用
MARSHOAI_ENABLE_SYSASUSER_PROMPT=true
MARSHOAI_SYSASUSER_PROMPT="好的喵~" # 假装是模型收到消息后的回答
```
### 使用 MCP
MarshoAI 内置了 MCPModel Context Protocol功能可使用兼容 Function Call 的 LLM 调用 MCP 兼容的工具。
1. 启用 MCP 功能
```dotenv
MARSHOAI_ENABLE_MCP=true
```
2. 配置 MCP 服务器
在 Bot 工作目录下的 `config/marshoai/mcp.json` 文件中写入标准 MCP 配置文件,例如:
```json
{
"mcpServers": {
"my-mcp": {
"type": "sse",
"url": "https://example.com/sse"
}
}
}
```
支持流式 HTTP(StreamableHttp)SSE以及 Stdio 三种类型的 MCP 服务器。
### 使用 DeepSeek-R1 模型
MarshoAI 兼容 DeepSeek-R1 模型,你可通过以下步骤来使用:
1. 获取 API Key