directus-extension-mcp-comments
v1.0.1
Published
MCP tool for managing comments on Directus items
Maintainers
Readme
Directus MCP Comments Extension
A Directus extension that adds a comments tool to the MCP (Model Context Protocol) interface, allowing AI agents to create, read, update, and delete comments on Directus items.
Features
- Create comments on any item in any collection
- Read comments with filtering by collection and item
- Update existing comments
- Delete comments
- Full integration with Directus user system and permissions
- Automatic timestamp tracking
Prerequisites
This extension requires the directus-extension-mcp-customization extension to be installed and enabled.
Installation
Install via npm:
npm install directus-extension-mcp-commentsOr manually:
- Install dependencies:
npm install- Build the extension:
npm run build- The extension will be automatically loaded by Directus when the server starts.
Usage
The comments tool supports four operations:
Create a Comment
{
"action": "create",
"collection": "posts",
"item": "abc-123",
"comment": "This is a great post!"
}Read Comments
Read all comments for a collection:
{
"action": "read",
"collection": "posts",
"limit": 10
}Read comments for a specific item:
{
"action": "read",
"collection": "posts",
"item": "abc-123",
"limit": 10
}Update a Comment
{
"action": "update",
"id": "comment-id-123",
"comment": "Updated comment text"
}Delete a Comment
{
"action": "delete",
"id": "comment-id-123"
}Technical Details
Architecture
This extension uses the Directus hook system to:
- Register the
commentstool in the MCP tools list via themcp.tools.listfilter - Handle tool execution via the
comments.mcp.tools.callfilter event - Receive user accountability from the
metaparameter passed by the customization extension - Use
CommentsServicewith proper accountability for permission-aware operations
Filter Event Handler
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
// ...
});Development
Watch mode for development:
npm run devValidate the extension:
npm run validateRelated Extensions
directus-extension-mcp-customization- Core framework for custom MCP tools (required)directus-extension-mcp-activity- View activity log through MCPdirectus-extension-mcp-hello-world- Example custom MCP tooldirectus-extension-mcp-presets- Manage presets/bookmarks through MCPdirectus-extension-mcp-revisions- Manage revision history through MCP
License
MIT
