Skip to main content
Glama

Directus MCP 服务器

一个为 Directus CMS 实现模型上下文协议 (MCP) 的 Node.js 服务器。使 AI 客户端能够通过模型上下文协议 (MCP) 与 Directus API 进行交互。

ℹ 先决条件

Related MCP server: Directus MCP Server

▶️ 快速开始

  1. 获取您的 Directus API 凭据

    • 前往您的 Directus 实例

    • 创建一个静态访问令牌,或者获取您的电子邮件和密码

    • 请妥善保管这些凭据

  2. 添加到您的 AI 编辑器

    {
      "mcpServers": {
        "directus": {
          "command": "npx",
          "args": ["-y", "@pixelsock/directus-mcp@latest"],
          "env": {
            "DIRECTUS_URL": "https://your-directus-instance.com",
            "DIRECTUS_ACCESS_TOKEN": "YOUR_ACCESS_TOKEN"
          }
        }
      }
    }

    或者,您可以使用电子邮件/密码进行身份验证:

    {
      "mcpServers": {
        "directus": {
          "command": "npx",
          "args": ["-y", "@pixelsock/directus-mcp@latest"],
          "env": {
            "DIRECTUS_URL": "https://your-directus-instance.com",
            "DIRECTUS_EMAIL": "your-email@example.com",
            "DIRECTUS_PASSWORD": "your-password"
          }
        }
      }
    }

    对于 Cursor:

    1. 前往 Settings → Cursor Settings → MCP

    2. 点击 + Add New Global MCP Server

    3. 粘贴配置

    4. 将占位符值替换为您的 Directus 凭据

    5. 保存并重启 Cursor

    对于 Claude Desktop:

    1. 打开 Settings → Developer

    2. 点击 Edit Config

    3. 在代码编辑器中打开 claude_desktop_config.json 并粘贴配置

    4. 将占位符值替换为您的 Directus 凭据

    5. 保存并重启 Claude

❓ 故障排除

如果您在 MCP 客户端(例如 Cursor 或 Claude Desktop)中启动服务器时遇到问题,请尝试以下操作。

确保您拥有有效的 Directus 凭据

  1. 验证您的 Directus URL 是否正确且可访问

  2. 检查您的访问令牌或电子邮件/密码凭据是否有效

  3. 在您的 MCP 客户端配置中替换凭据

  4. 保存并重启您的 MCP 客户端

确保已安装 Node 和 NPM

运行以下命令以确认您已安装 Node 和 NPM:

node -v
npm -v

清除 NPM 缓存

有时清除 NPM 缓存 可以解决 npx 相关的问题。

npm cache clean --force

🛠️ 可用工具

集合与项目

getItems                // Get items from a collection
getItem                 // Get a single item from a collection by ID
createItem              // Create a new item in a collection
updateItem              // Update an existing item in a collection
deleteItem              // Delete an item from a collection
getCollections          // Get all collection schemas
getFields               // Get fields for a collection
getRelations            // Get relations for a collection

文件

getFiles                // Get files from Directus
uploadFile              // Upload a file to Directus

用户与权限

login                   // Login to Directus and get an access token
getUsers                // Get users from Directus
getCurrentUser          // Get the current user info
getRoles                // Get roles from Directus
getPermissions          // Get permissions from Directus

系统

getSystemInfo           // Get system information from Directus
getActivity             // Get activity logs from Directus
getConfig               // Get current configuration information

🚧 开发模式

如果您想在开发模式下运行服务器:

  1. 克隆并安装:

    git clone https://github.com/pixelsock/directus-mcp.git
    cd directus-mcp
    npm install
  2. 将您的凭据添加到 .env:

    # .env
    DIRECTUS_URL=https://your-directus-instance.com
    DIRECTUS_ACCESS_TOKEN=your_token_here
    # Or use email/password
    DIRECTUS_EMAIL=your-email@example.com
    DIRECTUS_PASSWORD=your-password
  3. 启动开发服务器:

    npm run dev

🌐 HTTP 传输(多用户 / 远程部署)

默认情况下,服务器使用 stdio 传输,这非常适合单用户本地 AI 编辑器(Cursor、Claude Desktop 等)。

对于多用户或远程环境,您可以通过设置 MCP_TRANSPORT 环境变量切换到 Streamable HTTP 传输。

配置

环境变量

默认值

描述

MCP_TRANSPORT

stdio

传输模式:stdio 或 http / streamable-http

MCP_PORT

3000

HTTP 服务器监听的 TCP 端口

MCP_HOST

127.0.0.1

要绑定的主机/接口。使用 0.0.0.0 绑定所有接口

您也可以传递 --transport=http 作为 CLI 参数,而不是设置环境变量。

运行 HTTP 服务器

# Via environment variable
MCP_TRANSPORT=http MCP_PORT=3000 MCP_HOST=0.0.0.0 node dist/index.js

# Via CLI argument
node dist/index.js --transport=http

Docker 示例

docker run -p 3000:3000 \
  -e DIRECTUS_URL=https://your-directus-instance.com \
  -e DIRECTUS_ACCESS_TOKEN=your_token_here \
  -e MCP_TRANSPORT=http \
  -e MCP_HOST=0.0.0.0 \
  ghcr.io/pixelsock/directus-mcp

将 MCP 客户端连接到 HTTP 服务器

服务器运行后,将您的 MCP 客户端配置为连接到:

http://<host>:<port>/mcp

例如,对于支持 Streamable HTTP 传输的客户端:

{
  "mcpServers": {
    "directus": {
      "url": "http://localhost:3000/mcp"
    }
  }
}

📄 Directus 开发者资源

Available Tools

18 tools
createItemC

Create a new item in a collection

Inputs: collection (required), data (required), token, url.

deleteItemC

Delete an item from a collection

Inputs: collection (required), id (required), token, url.

getActivityC

Get activity logs from Directus

Inputs: query, token, url.

getCollectionsC

Get all collection schemas from Directus

Inputs: token, url.

getConfigB

Get current configuration information (without secrets)

Inputs: no named parameters.

getCurrentUserC

Get the current user info

Inputs: token, url.

getFieldsC

Get fields for a collection

Inputs: collection (required), token, url.

getFilesC

Get files from Directus

Inputs: query, token, url.

getItemC

Get a single item from a collection by ID

Inputs: collection (required), id (required), query, token, +1 more.

getItemsC

Get items from a collection in Directus

Inputs: collection (required), query, token, url.

getPermissionsC

Get permissions from Directus

Inputs: query, token, url.

getRelationsC

Get relations for a collection

Inputs: collection, token, url.

getRolesC

Get roles from Directus

Inputs: query, token, url.

getSystemInfoC

Get system information from Directus

Inputs: endpoint (required), token, url.

getUsersC

Get users from Directus

Inputs: query, token, url.

loginC

Login to Directus and get an access token

Inputs: email, password, url.

updateItemC

Update an existing item in a collection

Inputs: collection (required), data (required), id (required), token, +1 more.

uploadFileC

Upload a file to Directus

Inputs: fileName (required), fileData, fileUrl, mimeType, +4 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 18 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose targeting specific resources and actions in the Directus ecosystem. There is no overlap between tools like getItem (single item retrieval), getItems (multiple items), and getCollections (schema information), making misselection unlikely.

    Naming Consistency5/5

    All tools follow a consistent verb_noun naming pattern (e.g., createItem, getItem, updateItem, deleteItem). The pattern is maintained across all 18 tools with no deviations in style or convention.

    Tool Count4/5

    With 18 tools, the count is slightly high but reasonable for a comprehensive CMS/backend server like Directus. It covers core operations without being overwhelming, though it borders on the upper limit of ideal scope.

    Completeness5/5

    The tool set provides complete CRUD coverage for items (create, get, update, delete), along with essential administrative functions (users, roles, permissions, files, activity, config). No obvious gaps exist for the Directus domain, enabling full agent workflows.

    Maintenance

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An extension that implements the Model Context Protocol for Directus, enabling AI tools and LLMs to interact with Directus content through natural language for content editing, data analysis, and asset management.
      5 npm
      8
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      The official Model Context Protocol server for Skema CMS, enabling AI clients to interact with and manage CMS data. It provides tools for reading, creating, updating, and searching collections and items through natural language.
      11
      9 npm
      MIT