SillyAvon的MCP扩展
此扩展为SillyTavern添加了基于WebSocket的工具执行支持,允许通过标准化接口注册和执行外部工具。
特性
- 用于实时通信的WebSocket服务器
- 工具登记和执行系统
- 工具定义的JSON模式验证
- 实时执行状态更新
- 可配置的日志记录和WebSocket设置
- 基于Web的设置UI集成到SillyTavern中
安装
方法1:Web界面(推荐)
看 说明.md 有关通过SillyTavern的web界面安装的分步说明。
方法2:手动安装
- 将此存储库克隆到SillyTavern插件目录中:
cd /path/to/SillyTavern/plugins
git clone https://github.com/CG-Labs/SillyTavern-MCP-Extension.git mcp-extension- 安装依赖项:
cd mcp-extension
npm install- 重新启动SillyTavern
配置
该扩展可以通过SillyTavern UI在“设置”>“扩展”>“MCP扩展”下进行配置。
可用设置
- WebSocket端口:WebSocket服务器的端口号(默认值:5005)
- 日志级别:记录详细程度(调试、信息、警告、错误)
用法
注册工具
要注册工具,请发送以下格式的WebSocket消息:
{
"type": "register_tool",
"data": {
"name": "example_tool",
"schema": {
"type": "object",
"properties": {
"param1": {
"type": "string",
"description": "First parameter"
},
"param2": {
"type": "number",
"description": "Second parameter"
}
},
"required": ["param1"]
}
}
}执行工具
要执行已注册的工具,请发送以下格式的WebSocket消息:
{
"type": "execute_tool",
"data": {
"executionId": "unique_execution_id",
"name": "example_tool",
"args": {
"param1": "value1",
"param2": 42
}
}
}执行状态更新
该扩展向所有连接的客户端广播执行状态更新:
执行已开始
{
"type": "tool_execution_started",
"data": {
"executionId": "unique_execution_id",
"name": "example_tool",
"args": {
"param1": "value1",
"param2": 42
}
}
}执行已完成
{
"type": "tool_execution_completed",
"data": {
"executionId": "unique_execution_id",
"result": {
// Tool-specific result data
}
}
}执行失败
{
"type": "tool_execution_failed",
"data": {
"executionId": "unique_execution_id",
"error": {
"code": "ERROR_CODE",
"message": "Error message"
}
}
}错误代码
INVALID_NAME:工具名称无效INVALID_SCHEMA:工具架构无效INVALID_URI:资源URI无效INVALID_HANDLER:处理程序实现无效INVALID_ARGUMENTS:工具参数无效TOOL_EXISTS:工具已注册TOOL_NOT_FOUND:未找到工具TOOL_EXECUTION_FAILED:工具执行失败SERVER_ERROR:内部服务器错误
发展
项目结构
mcp-extension/
├── index.js # Main plugin entry point
├── manifest.json # Plugin manifest
├── package.json # Dependencies and scripts
├── public/ # Public assets
│ ├── script.js # Client-side JavaScript
│ ├── style.css # Client-side styles
│ └── templates/ # HTML templates
├── utils/ # Utility modules
│ ├── errors.js # Error handling
│ ├── logger.js # Logging utility
│ └── validation.js # Input validation
└── README.md # This documentation添加新工具
要添加新工具,请执行以下操作:
- 连接到WebSocket服务器
- 使用模式注册您的工具
- 监听执行请求
- 处理执行并返回结果
工具实现示例:
const ws = new WebSocket('ws://localhost:5005');
ws.onopen = () => {
// Register tool
ws.send(JSON.stringify({
type: 'register_tool',
data: {
name: 'example_tool',
schema: {
type: 'object',
properties: {
input: {
type: 'string'
}
},
required: ['input']
}
}
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
if (message.type === 'execute_tool' &&
message.data.name === 'example_tool') {
// Handle execution
const result = doSomething(message.data.args.input);
// Send result
ws.send(JSON.stringify({
type: 'tool_execution_completed',
data: {
executionId: message.data.executionId,
result
}
}));
}
};贡献
- 分叉存储库
- 创建要素分支
- 提交您的更改
- 推到分支
- 创建拉取请求
支持
如果您遇到任何问题或有疑问:
- 检查 针对存在的问题
- 如果您的问题尚未报告,则创建新问题
- 加入SillyAvern Discord社区以获得支持
许可证
MIT许可证-有关详细信息,请参阅许可证文件
