The SuluMcpBundle offers an MCP server at /admin/mcp that works with the permissions of the logged-in user. allowed_hosts and the firewall order decide access, dangerous_tools decides publishing and deleting. When writing, check address, creator, smart_content fields and duplicate rows.
Series 5: Sulu for developers Chapter 15 of 16
Opening Sulu to AI assistants (MCP)
This needs the official Sulu extension “MCP bundle”. If it is missing from your administration, it is not installed.
In short
The SuluMcpBundle turns a Sulu installation into a server for the Model Context Protocol (MCP). An AI assistant can then create pages and articles and change media and snippets, using the same operations as the admin. The website bertrams-media uses it in version 1.0.0, for this handbook too.
Helpful first: 5.8 Writing content in code
Login and permissions
The server answers at /admin/mcp. Every request runs as the logged-in Sulu user. What the admin forbids them, MCP forbids too; there is no permission layer of its own. Login works by OAuth: the assistant registers itself as a client, you log in to the admin and confirm the scopes mcp:tools and mcp:resources. With Claude Code, one command is enough:
claude mcp add --transport http sulu https://your-sulu-host.example.com/admin/mcp
The configuration
The example website has everything in config/packages/sulu_mcp.yaml. Only server_url is required, the public address of the installation, from which Sulu forms the issuer and resource identifier of the OAuth flow. It comes from the variable SULU_MCP_SERVER_URL. Three things are easy to overlook:
- Allowed hosts. Without
allowed_hosts, the server only acceptslocalhost. A server on a domain of its own then answers every request after a successful login with “403 Forbidden: Invalid Host header”, without writing anything to the log. The hosts go in the list without a port. - Firewall. In
config/packages/security.yaml, the firewallmcpcomes before the firewalladmin, because both patterns match/admin/mcpand the first one wins. The pattern is anchored so that/admin/mcp/authorizeand/admin/mcp/consentend up at the admin firewall. - Default scopes. The project sets
league_oauth2_server.scopes.defaultitself; the example website usesmcp:toolsandmcp:resources.
The switches
Four switches under sulu_mcp.dangerous_tools release tools with consequences that are hard to undo. All default to false. A tool that is switched off is not just locked, it is removed from the container and does not appear in the list:
delete:sulu_content_delete,sulu_tag_delete,sulu_category_deletepublish:sulu_content_publish,sulu_content_unpublish,sulu_preview_link_revoke,sulu_page_move,sulu_page_reorderblock_remove:sulu_block_removemedia_upload:sulu_media_upload
The example website sets none of them. That is why there is no tool for publishing in its sessions, although other descriptions refer to it. Drafts are published there by the command app:content:publish page|article|snippet <uuid>. As an editorial setup, the bundle recommends activating only publish. After changes, clear the cache and have the tools listed:
bin/console cache:clear
bin/console debug:container --tag=mcp.tool
Tools of your own
A bundle that has content of its own brings tools of its own for the assistant. The SuluEventBundle does this for events and locations (sulu_event_*, sulu_location_*). A tool is a method with the attribute McpTool and a permission check with RequiresPermission:
#[McpTool(
name: 'sulu_event_create',
title: 'Create Event',
description: 'Create an event as a draft (publish it in the admin). Pass the template, the title and the template fields in "content" ...',
)]
#[RequiresPermission(requirements: [
new PermissionRequirement(Event::SECURITY_CONTEXT, PermissionTypes::ADD),
])]
public function createEvent(string $locale, string $title, string $template = 'event', ?array $content = null): array
{
try {
// ... create the content as a draft through the ContentManager ...
return ['success' => true, 'uuid' => $event->getUuid(), 'workflowPlace' => 'draft'];
} catch (\Throwable $e) {
return ['error' => \sprintf('Failed to create event: %s', $e->getMessage())];
}
}
The description is the text the assistant reads. Give an example of the content and the required fields in it. The services of the tools are only loaded if the MCP bundle is installed: for this, the SuluEventExtension checks class_exists on the attribute McpTool before it loads services-mcp.yaml. Standalone bundles thus stay runnable even without MCP.
Traps when writing
We came across these points while writing this handbook and the website through MCP:
- Pages need a
url. Without one,PageCreateToolbuilds'/' . mb_strtolower(str_replace(' ', '-', $title))from the title. Only spaces are replaced, colons and umlauts stay, and the parent page does not enter the address. Always give the address with the parent path, using onlya-z,0-9and hyphens. - Creator and editor are missing. For content created through MCP,
idUsersCreatorandidUsersChangerof the dimension row often stay empty. The name is then missing in the article list. After a round, check that the columns are filled. smart_contentstays empty. A field that was never saved has the valuenull. TheSmartContentPropertyResolverthen immediately returns an empty view, without falling back to “show everything”. On the first save, the admin sends a default value for every field, MCP does not. Save such fields once as an empty object{}.- Duplicate dimension rows. After several changes to the same article, two rows for the same stage sometimes appear. Check with the query from “Writing content in code”.
- One excerpt image per page. Pages and articles created through MCP only get one if you pass it along (
excerpt.image). - Send whole fields. The excerpt (
excerpt) is a block: always send title, description, image, categories and tags together.