検索は翻訳元へ

Grav MCP Server

Grav MCP Server は、Model Context Protocol (MCP) を通して、エージェント型 AI クライアントに Grav 2.0 サイトを公開します。 これは、 npm 上に grav-mcp パッケージとして配布されているスタンドアロンの Node.js アプリケーションです。 Grav プラグインでは ありません :それは、 AI クライアント(Cloaude Code, Claude Desktop, Cursor, その他の MCP 対応クライアント)内で実行し、ファーストパーティ製 Grav API プラグイン を通して HTTP 経由でサイトと通信します。

設計コンセプトは簡潔です: Admin2 は、人間向けクライアントであり、 MCP サーバーは AI 向けクライアントであり、その両方は同じ API を通る 。 MCP サーバーは、 Grav 内への特別なバックドアを持ちません。 そこで実行されるすべての操作は、他の API 利用者と全く同様に、 /api/v1 に対して認証され、パーミッションを確認される HTTP リクエストです。

Note

MCP サーバーは、インストールし、 Grav サイトに有効化するために API プラグイン が必要です。 MCP サーバーそのものは、コンテンツロジックを持ちません; それは、 MCP ツールの呼び出しと、 Grav REST API との翻訳層です。

アーキテクチャ

┌─────────────────┐   stdio / HTTP    ┌──────────────┐   HTTPS + X-API-Key   ┌──────────────────┐
│   AI Client     │ ◀──────────────▶  │  grav-mcp    │ ◀───────────────────▶ │  Grav API Plugin │
│ (Claude, etc.)  │   MCP protocol    │ (Node.js)    │   REST /api/v1        │  (PHP, on site)  │
└─────────────────┘                   └──────────────┘                       └──────────────────┘
  1. AI クライアントは、サブプロセスとして grav-mcp を起動する(stdio トランスポート)か、実行中のインスタンスに接続する(HTTP トランスポート)
  2. grav-mcp advertises its catalog of tools, resources, and prompts to the client.
  3. When the model calls a tool, grav-mcp translates it into an authenticated HTTP request to the Grav API.
  4. The API plugin authenticates the request, checks permissions, performs the operation against the filesystem, and returns structured JSON.

Because the API plugin is the single point of mutation, the MCP server inherits the API’s permission model, optimistic concurrency (ETags), rate limiting, and event/webhook system for free.

仕様

  • Node.js 18+ on the machine running the AI client.
  • A Grav 2.0 site with the API Plugin installed and enabled.
  • An API key generated for the user the AI should act as.

Installation and Configuration

There is nothing to install manually. The grav-mcp package is run on demand via npx, so configuration happens entirely in your AI client.

1. Generate an API key

On the Grav site, generate a key for an appropriate user (see Permissions and Security before choosing which user):

bin/plugin api keys:generate --user=admin --name="Claude MCP"

The key (prefixed grav_) is displayed once. Copy it immediately. Key management commands (keys:list, keys:revoke) are documented in the API Authentication reference.

2. Register the server with your AI client

The MCP server is configured through two environment variables: GRAV_API_URL (your site’s API base URL) and GRAV_API_KEY (the key you just generated).

Claude Code / Claude Desktop / Cursor and most MCP clients use the standard mcpServers config block:

{
  "mcpServers": {
    "grav": {
      "command": "npx",
      "args": ["-y", "grav-mcp"],
      "env": {
        "GRAV_API_URL": "https://mysite.com/api",
        "GRAV_API_KEY": "grav_your_api_key_here"
      }
    }
  }
}

Restart (or reconnect) the client and the full Grav toolset becomes available.

3. (Optional) Run directly for testing

The same configuration works on the command line:

GRAV_API_URL=https://mysite.com/api GRAV_API_KEY=grav_abc123 npx grav-mcp

Configuration Reference

Every option can be set as an environment variable or as a CLI flag. CLI flags take precedence.

Environment variableCLI flagRequiredDescription
GRAV_API_URL--urlYesBase URL of the Grav API (for example https://mysite.com/api).
GRAV_API_KEY--keyYesAPI key for authentication. Must start with grav_.
GRAV_ENVIRONMENT--environmentNoTargets a specific user/env/* environment for configuration scopes (sent as the X-Config-Environment header).
--transportNostdio (default) or http.
--portNoPort for the HTTP transport. Default 3100.

Transports

stdio (default)

The default transport. The AI client spawns grav-mcp as a child process and communicates over standard input/output. This is the right choice for local, single-user clients such as Claude Code, Claude Desktop, and Cursor.

HTTP

For remote or multi-user deployments, run a long-lived server that clients connect to over HTTP:

npx grav-mcp --url https://mysite.com/api --key grav_abc123 --transport http --port 3100

Tools

The server exposes 70 semantic tools across 11 domains. These are named, typed operations (not raw REST endpoints), described in language the model can reason about.

Pages (10)

ToolPurpose
list_pagesList pages in the content tree.
get_pageRetrieve a single page (frontmatter + content).
create_pageCreate a new page.
update_pageUpdate a page’s frontmatter and/or content.
delete_pageDelete a page.
move_pageMove a page to a new route.
copy_pageCopy a page to a new route.
reorder_pagesReorder sibling pages.
batch_pagesApply multiple page operations atomically.
reorganize_pagesBulk-restructure a subtree in one operation.

Multilingual (5)

ToolPurpose
list_languagesList configured site languages.
get_page_translationsList the translations of a page.
create_translationCreate a translation for a page.
adopt_page_languageAdopt/assign a language for a page.
compare_translationsCompare two language versions of a page.

Media (8)

ToolPurpose
list_page_mediaList media attached to a page.
upload_page_mediaUpload media to a page.
delete_page_mediaDelete media from a page.
list_site_mediaList site-level media.
upload_site_mediaUpload site-level media.
delete_site_mediaDelete site-level media.
create_media_folderCreate a media folder.
manage_media_folderRename/move/delete a media folder.

Configuration (3)

ToolPurpose
list_config_scopesList available configuration scopes.
get_configRead a configuration scope (returns an ETag).
update_configUpdate a configuration scope (ETag-checked, per-environment aware).

Users (6)

ToolPurpose
list_usersList user accounts.
get_userRetrieve a single user.
create_userCreate a user.
update_userUpdate a user.
delete_userDelete a user.
manage_api_keysList/create/revoke a user’s API keys.

Package Manager (9)

ToolPurpose
list_packagesList installed plugins/themes.
get_package_infoGet details for a package.
search_packagesSearch the GPM repository.
check_updatesCheck for available updates.
install_packageInstall a plugin/theme (resolves blueprint dependencies).
update_packageUpdate a single package.
update_all_packagesUpdate all packages.
upgrade_gravUpgrade Grav core.
remove_packageRemove a package.

System (10)

ToolPurpose
get_system_infoRetrieve system/environment information.
clear_cacheClear Grav’s cache.
get_logsRead system logs.
create_backupCreate a backup.
list_backupsList backups.
get_schedulerInspect scheduler jobs/status.
run_schedulerRun the scheduler.
list_environmentsList configured environments.
create_environmentCreate a new environment.
get_password_policyRead the active password policy.

Dashboard and Reports (7)

ToolPurpose
get_dashboard_statsRetrieve dashboard statistics.
get_notificationsList dashboard notifications.
dismiss_notificationDismiss a notification.
run_reportsRun diagnostic reports.
get_dashboard_widgetsList dashboard widgets.
update_dashboard_layoutUpdate the current user’s dashboard layout.
update_site_dashboard_layoutUpdate the site-wide default dashboard layout.

Webhooks (4)

ToolPurpose
list_webhooksList configured webhooks.
manage_webhookCreate/update/delete a webhook.
get_webhook_deliveriesInspect a webhook’s delivery log.
test_webhookSend a test payload to a webhook.

Blueprints and Schema (6)

ToolPurpose
list_page_templatesList available page templates.
get_blueprintRetrieve a resolved blueprint schema.
get_permissionsRetrieve the permission catalog.
get_taxonomyRetrieve taxonomy types and values.
upload_blueprint_fileUpload a blueprint file.
delete_blueprint_fileDelete a blueprint file.

Plugin Discovery (2)

ToolPurpose
discover_pluginsDiscover admin features contributed by installed plugins.
plugin_actionTrigger a plugin-provided action.

Resources

In addition to tools, the server exposes 5 resources the model can read for context without performing an action:

Resource URIDescription
grav://system/infoSystem and environment information.
grav://user/permissionsThe authenticated API user’s effective permissions.
grav://languagesConfigured site languages.
grav://templatesAvailable page templates.
grav://taxonomyTaxonomy types and their values.

Prompts

The server ships 6 workflow prompts that package common multi-step jobs into a single guided flow:

PromptWorkflow
create_blog_postGuided creation of a blog post (template, frontmatter, media, taxonomy).
translate_pageTranslate a page into another configured language.
site_health_checkRun a comprehensive site health audit.
content_auditAudit content quality and metadata.
plugin_setupSearch, install, and configure a plugin.
bulk_updateApply bulk frontmatter updates across many pages.

Authentication

Every request the MCP server makes carries the API key in an X-API-Key header:

X-API-Key: grav_abc123...

This is the same API-key authentication described in the API Authentication reference. When GRAV_ENVIRONMENT is set, the server also sends an X-Config-Environment header so configuration reads and writes target the correct environment.

On startup the client validates its key against the API’s /me endpoint to read the user’s effective permissions, so unsupported operations can be reported cleanly rather than failing late.

Permissions and Security

The most important thing to understand about the MCP server’s security model is that it inherits the permissions of the user its API key belongs to, and nothing more. There is no separate “AI” permission set. The same api.pages.write, api.config.write, api.gpm.write (and so on) permissions that gate any API consumer gate the AI.

This means you control what an AI can do by controlling which user the key is issued to:

  • Issuing the key for a super-admin user gives the AI full access to the site.
  • Issuing the key for a user scoped to only page and media permissions confines the AI to content work, with no ability to change configuration, manage users, or install packages.

!!! Create a dedicated, least-privilege user for AI access rather than reusing your primary admin account. A key can never exceed the permissions of the user it belongs to, so the user account is your security boundary. Per-key permission scoping is not yet enforced independently of the user.

Concurrency safety

All configuration and page writes go through the API’s ETag-based optimistic concurrency. The server reads an ETag on GET and sends it back as If-Match on writes. If the resource changed in between (for example, a human edited the same page in Admin2), the API returns 409 Conflict instead of silently overwriting, and the agent must re-fetch and reconcile.

Observability

The MCP server does not add its own audit log. Instead, every write through the API fires a structured event (onApiPageCreated, onApiConfigUpdated, and the rest of the onApi* family), and those events drive the API’s webhook system. To record AI-initiated changes, point a webhook at your logging or notification endpoint. Webhook deliveries are HMAC-signed so you can verify their origin. See the API Events reference for the full event list.

Development and Maintenance

For contributors working on the server itself, the repository provides the usual scripts:

npm run typecheck        # Type-check the TypeScript sources
npm test                 # Run the unit test suite
npm run build            # Compile to dist/
npm run audit:api        # Verify tool coverage against the live API plugin
npm run changelog:since  # Report API plugin changes since the last reviewed version

The audit:api and changelog:since scripts exist to keep the tool catalog in sync with the API plugin as it evolves, by comparing the server’s @api METHOD /path annotations against the plugin’s actual routes.

See Also