Skip to main content
Glama
CG-Labs

SillyTavern MCP Server

by CG-Labs

SillyTavern 的 MCP 扩展

此扩展为 SillyTavern 添加了基于 WebSocket 的工具执行支持,允许通过标准化接口注册和执行外部工具。

特征

  • 用于实时通信的 WebSocket 服务器

  • 工具注册和执行系统

  • 工具定义的 JSON Schema 验证

  • 实时执行状态更新

  • 可配置的日志记录和 WebSocket 设置

  • SillyTavern 集成了基于 Web 的设置 UI

Related MCP server: Modular MCP Server & Client

安装

方法 1:Web 界面(推荐)

请参阅INSTRUCTIONS.md以获取通过 SillyTavern 的 Web 界面进行安装的分步说明。

方法2:手动安装

  1. 将此存储库克隆到您的 SillyTavern 插件目录中:

    cd /path/to/SillyTavern/plugins
    git clone https://github.com/CG-Labs/SillyTavern-MCP-Extension.git mcp-extension
  2. 安装依赖项:

    cd mcp-extension
    npm install
  3. 重启 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

添加新工具

要添加新工具:

  1. 连接到 WebSocket 服务器

  2. 使用架构注册您的工具

  3. 监听执行请求

  4. 处理执行并返回结果

工具实现示例:

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
            }
        }));
    }
};

贡献

  1. 分叉存储库

  2. 创建功能分支

  3. 提交你的更改

  4. 推送到分支

  5. 创建拉取请求

支持

如果您遇到任何问题或有疑问:

  1. 检查GitHub Issues是否存在问题

  2. 如果您的问题尚未报告,请创建新问题

  3. 加入 SillyTavern Discord 社区获取支持

执照

MIT 许可证 - 详情请参阅许可证文件

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CG-Labs/SillyTavern-MCP-Extension'

If you have feedback or need assistance with the MCP directory API, please join our Discord server