Repository navigation
Backport MCP servers and OAuth to Craft 5.12 - #20145
Merged
Merged
Conversation
Backports ab0f627 from 6.x.
Backports 98708ff from 6.x.
Backports 951d30d from 6.x.
Backports 2d5aa64 from 6.x.
Backports 133a36f from 6.x.
Backports 10ee764 from 6.x.
Backports a79e33e from 6.x.
Backports 50c3e12 from 6.x.
Backports d08b306 from 6.x.
Backports dd3f574 from 6.x.
Backports 289b75e from 6.x.
Backports the edition part of aa19b0e from 6.x.
Covers the field layout filtering backported from 2d5aa64.
…ce MCP tools Backports 1964ab6 from 6.x.
Backports aa19b0e from 6.x.
Replace the single mcp:use scope with mcp:read, mcp:write, and mcp:admin, modeled as generic ordered scope levels on craft\oauth\Resource. Users choose the access level on the consent screen, defaulting to read only, and only administrators are offered full access. Discovery hides capabilities the token's scope doesn't cover, and clients that authorize again keep the earlier level without another prompt. Stdio stays unscoped. Backports e905d29 from 6.x.
OAuth metadata, client registration, token, and MCP preflight requests carry no Craft session, so they failed while the system was offline and clients couldn't refresh tokens. The MCP endpoint still requires the token's user to have access to the control panel while the system is offline.
Browser GET requests to the admin MCP endpoint, and to the public one while it's enabled, now render a page with the server URL and copyable setup snippets for common AI assistants. Other GET requests get a 405 without requiring a token. Backports 1bcc66a from 6.x.
MCP is now listed after Plugins in the System settings group, rather than first, and is hidden when admin changes are disallowed. Adapts 3ea2209 from 6.x.
Add the light robot icon that the MCP settings item references. Backports ada9a99 from 6.x.
Backports 6377e6b from 6.x.
Amp-Thread-ID: https://ampcode.com/threads/T-01a18252-9c08-75c3-9c6b-f581cf3dda42 Co-authored-by: Amp <amp@ampcode.com>
GraphQL requests with an OAuth access token for the new `graphql` resource now get a schema built from the components available to the token's user. Schema components opt in with an `authenticated` key, and built-in components map to user permissions. Entry and asset queries use the `editable` param, and mutations check the user's element permissions. Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Craft 6 uses Passport, so 5.12’s OAuth tables now use Passport’s column names and layout (plus resource_id), and clients record their grant types. Clients can only use the grant types they were registered with. Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
…ed-graphql # Conflicts: # docs/oauth.md
… client Personal tokens now share one client per resource with grant_types ["personal_access"], and store their name on the token row, as Laravel Passport does. Revoking a personal token revokes just that token.
…by scope like Passport Tokens belong to the resource that defines their scopes, scope IDs must be unique across resources, and registered clients store their resource's scopes in Passport's optional oauth_clients.scopes column. Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Passport 13 only matches a client with no provider when auth.guards.api.provider is the user's provider, which Craft 6 doesn't configure, so it wouldn't find a provider-less 5.12 client. Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com>
Use Laravel Passport's OAuth table layout and scope-bound clients
The authenticated server now has its own enable toggle, endpoint, and authorization endpoint, and any active user can use it. Endpoints in the control panel go through the usual control panel access check. The useCraftMcp permission is gone, and capabilities that only make sense in the control panel require accessCp. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
Scopes now sit in one field with a group per API. The Tokens table gains a Type column and an action menu with Edit and Revoke, and the edit modal shows only the scopes a token has, along with its expiration date. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
The page is titled "MCP Settings", and the public server's capabilities, content, and element states sit inside its pane. Labels, option wording, content order, and "Select all" buttons now match Craft 6. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
They're deprecated, so MCP no longer lists them as element types, resolves them in element tools or public queries, or moves categories within structures. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
…mcp-split-servers
Content groups are now Sites, Entries, Nested Entry Fields, Assets, Addresses, and Users. User group checkboxes live under Users. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
Without public registration, the authenticated endpoints default to
/{cpTrigger}/mcp and /{cpTrigger}/mcp/auth, leaving /mcp for the public
server.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
[5.12] Separate authenticated and public MCP servers
…authenticated-graphql Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f Co-authored-by: Amp <amp@ampcode.com> # Conflicts: # CHANGELOG.md
Authenticated GraphQL queries via OAuth
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f
Contributor
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backports the MCP servers and an OAuth authorization server to Craft 5.12, with authenticated GraphQL on top. This branch includes the work merged from:
useCraftMcppermission anymore. Any active user can authorize a client, and tools check permissions per record./{cpTrigger}/mcpand/{cpTrigger}/mcp/auth. With it, they default to/mcpand/mcp/auth. Endpoints in the control panel require control panel access.graphqlOAuth resource hasgraphql:readandgraphql:writelevels.authenticatedkey.currentUserquery returns the user that authenticated the request.The release notes are in
CHANGELOG-5.12.md.docs/mcp.mdanddocs/oauth.mdcover setup, configuration, and plugin extension points.Evidence
Before:
origin/5.12has nosrc/mcp/,src/oauth/, or MCP and OAuth controllers. After: a Craft/PostgreSQL install served OAuth discovery and the protected MCP endpoint. Browser consent issued a token only with the correct PKCE verifier. A wrong verifier and a replayed code returned 400.Read, write, and full-access tokens listed 19, 40, and 50 tools. A write token updated a user preference and restored it, and a read token saw the change but couldn't write. Missing or invalid credentials, another resource's token, and a suspended user were rejected. Refreshing rotated both the access and refresh tokens.
Stdio initialized, listed tools, and called
preferences.get. The public server returned 404 until enabled. With one approved tool, only that tool was listed.Split servers ([5.12] Separate authenticated and public MCP servers #20189), against a Pro install with real tokens:
accessCptools/listat/mcptools/listat/admin/mcpPOST /mcp/authwithout a tokenresource_metadataPOST /mcpwithout a token, shared endpointinitializeresultAuthenticated GraphQL (Authenticated GraphQL queries via OAuth #20147):
AuthenticatedSchemaTestandGraphqlOAuthCestcover permission-limited queries and mutations, drafts, per-user caching, and real OAuth and personal tokens throughGraphqlController. In a browser, a new personal token answered{ping}and got 401 after it was revoked.After the latest merges, these tests pass: OAuth unit (22), MCP unit (29), GraphQL unit (257), and functional (38). PHPStan and ECS pass in CI.
Screenshots of the settings, consent, and Tokens screens are in #20189 and #20147.
Related issues
Amp threads: https://ampcode.com/threads/T-01a18252-9c08-75c3-9c6b-f581cf3dda42, https://ampcode.com/threads/T-ae777030-d792-49ae-8853-87e83195c88f