// 15

插件开发

概述

本文面向开发者,介绍如何创建自定义 DeepSeno 插件。一个插件本质上是一段 JSON 配置,描述了提示词指令、MCP 工具服务或两者的组合。

完整规范

voicebrain-plugin.json 字段定义

字段类型必填约束说明
idstring只能包含字母、数字、-_,全局唯一插件唯一标识符
namestring界面显示名称
descriptionstring建议不超过 50 字插件卡片上的描述文本
versionstring语义化版本号格式(如 1.0.0用于更新检测
instructionsstring二选一支持 \n 换行注入 LLM 的系统提示词
mcpobject二选一见 MCP 配置MCP 工具服务配置
pageobject见 Page 配置侧边栏专属页面配置

instructionsmcp 至少要有一个。可以两个都有(混合插件)。

MCP 配置

字段类型必填说明
mcp.commandstring启动命令:npxnodepython
mcp.argsstring[]命令参数数组
mcp.envobject环境变量键值对,传给子进程。值为 "" 表示需要用户填写
mcp.autoStartboolean是否随应用自动启动(默认 true

Page 配置

字段类型必填说明
page.iconstringlucide-react 图标名
page.menuLabelstring侧边栏标签(默认使用 name
page.welcomeMessagestring进入页面时的欢迎语

Node.js MCP Server 示例

最小的 MCP Server 实现:

#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server(
  { name: "my-tool", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

server.setRequestHandler("tools/list", async () => ({
  tools: [{
    name: "hello",
    description: "Say hello to someone",
    inputSchema: {
      type: "object",
      properties: {
        name: { type: "string", description: "Person's name" }
      },
      required: ["name"]
    }
  }]
}));

server.setRequestHandler("tools/call", async (request) => {
  if (request.params.name === "hello") {
    const name = request.params.arguments?.name || "World";
    return {
      content: [{ type: "text", text: `Hello, ${name}!` }]
    };
  }
  throw new Error(`Unknown tool: ${request.params.name}`);
});

const transport = new StdioServerTransport();
await server.connect(transport);

对应的插件配置:

{
  "id": "my-tool",
  "name": "My Tool",
  "description": "A custom tool",
  "version": "1.0.0",
  "mcp": {
    "command": "node",
    "args": ["path/to/index.js"],
    "autoStart": true
  }
}

Python MCP Server 示例

使用 fastmcp 库快速创建 MCP Server:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("my-tool")

@mcp.tool()
def hello(name: str) -> str:
    """Say hello to someone"""
    return f"Hello, {name}!"

mcp.run()

对应的插件配置:

{
  "id": "my-python-tool",
  "name": "My Python Tool",
  "description": "A Python MCP tool",
  "version": "1.0.0",
  "mcp": {
    "command": "python",
    "args": ["path/to/server.py"],
    "autoStart": true
  }
}

发布为 npm 包

将 MCP Server 发布为 npm 包,用户可通过 npx 直接运行,无需手动下载。

1. 配置 package.json

{
  "name": "my-tool-package",
  "version": "1.0.0",
  "bin": {
    "my-tool": "./index.js"
  },
  "dependencies": {
    "@modelcontextprotocol/sdk": "^1.0.0"
  }
}

确保入口文件(index.js)顶部有 #!/usr/bin/env node

2. 发布

npm publish

3. 安装配置

用户粘贴以下 JSON 即可安装:

{
  "id": "my-tool",
  "name": "My Tool",
  "description": "A custom tool",
  "version": "1.0.0",
  "mcp": {
    "command": "npx",
    "args": ["-y", "my-tool-package"],
    "autoStart": true
  }
}

可用图标

page.icon 支持以下 lucide-react 图标名(直接填字符串):

mail calendar brain sparkles pen book chart code search clipboard hash message lightbulb wrench globe bot monitor cpu folder presentation

完整图标库参见:https://lucide.dev/icons/

MCP 协议参考