Directus MCP评论扩展
Directus扩展,用于添加 comments 工具连接到MCP(模型上下文协议)接口,允许AI代理创建、读取、更新和删除Directus项目上的注释。
特性
- 创建 对任何收藏中的任何项目的评论
- 阅读 按集合和项目过滤的评论
- 更新 现有评论
- 删除 评论
- 与Directus用户系统和权限完全集成
- 自动时间戳跟踪
先决条件
此扩展需要 directus-extension-mcp-customization 要安装和启用的扩展。
安装
通过npm安装:
npm install directus-extension-mcp-comments或手动:
- 安装依赖项:
npm install- 构建扩展:
npm run build- 服务器启动时,Directus将自动加载扩展。
用法
这 comments 该工具支持四种操作:
创建评论
{
"action": "create",
"collection": "posts",
"item": "abc-123",
"comment": "This is a great post!"
}阅读评论
阅读收藏的所有评论:
{
"action": "read",
"collection": "posts",
"limit": 10
}阅读特定项目的评论:
{
"action": "read",
"collection": "posts",
"item": "abc-123",
"limit": 10
}更新评论
{
"action": "update",
"id": "comment-id-123",
"comment": "Updated comment text"
}删除评论
{
"action": "delete",
"id": "comment-id-123"
}技术细节
建筑
此扩展使用Directus挂钩系统来:
- 注册
comments通过MCP工具列表中的工具mcp.tools.list过滤器 - 通过以下方式处理工具执行
comments.mcp.tools.call过滤型事件 - 从以下方面接受用户责任
meta自定义扩展传递的参数 - 使用
CommentsService对具有权限意识的操作进行适当的问责
筛选器事件处理程序
emitter.onFilter("comments.mcp.tools.call", async (toolCall, meta) => {
// Extract accountability from meta parameter
const { accountability } = meta;
// Get input arguments from toolCall
const input = commentInputSchema.parse(toolCall.arguments);
// Create service with accountability for proper permissions
const commentsService = new CommentsService({
schema: await getSchema(),
accountability, // Ensures user context and permissions
});
// Perform operations with permission enforcement
// ...
});发展
开发观察模式:
npm run dev验证扩展名:
npm run validate许可证
麻省理工学院
