// 15
插件开发
概述
本文面向开发者,介绍如何创建自定义 DeepSeno 插件。一个插件本质上是一段 JSON 配置,描述了提示词指令、MCP 工具服务或两者的组合。
完整规范
voicebrain-plugin.json 字段定义
| 字段 | 类型 | 必填 | 约束 | 说明 |
|---|---|---|---|---|
id | string | 是 | 只能包含字母、数字、-、_,全局唯一 | 插件唯一标识符 |
name | string | 是 | 无 | 界面显示名称 |
description | string | 否 | 建议不超过 50 字 | 插件卡片上的描述文本 |
version | string | 否 | 语义化版本号格式(如 1.0.0) | 用于更新检测 |
instructions | string | 二选一 | 支持 \n 换行 | 注入 LLM 的系统提示词 |
mcp | object | 二选一 | 见 MCP 配置 | MCP 工具服务配置 |
page | object | 否 | 见 Page 配置 | 侧边栏专属页面配置 |
instructions和mcp至少要有一个。可以两个都有(混合插件)。
MCP 配置
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
mcp.command | string | 是 | 启动命令:npx、node、python 等 |
mcp.args | string[] | 是 | 命令参数数组 |
mcp.env | object | 否 | 环境变量键值对,传给子进程。值为 "" 表示需要用户填写 |
mcp.autoStart | boolean | 否 | 是否随应用自动启动(默认 true) |
Page 配置
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
page.icon | string | 否 | lucide-react 图标名 |
page.menuLabel | string | 否 | 侧边栏标签(默认使用 name) |
page.welcomeMessage | string | 否 | 进入页面时的欢迎语 |
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 协议参考
- 官方文档:https://modelcontextprotocol.io
- SDK(npm):
@modelcontextprotocol/sdk - SDK(Python):
mcp - 现有 MCP Servers 列表:https://github.com/modelcontextprotocol/servers