Repository navigation
Native MCP server at /client/mcp - #14761
Open
ewerton-silva00 wants to merge 5 commits into
Open
ewerton-silva00 wants to merge 5 commits into
ewerton-silva00 wants to merge 5 commits into
Conversation
Add the createMcpToken, listMcpTokens and revokeMcpToken APIs. A token belongs to the user that creates it, may have an expiration date and is returned only on creation: the mcp_token table stores its SHA-256 hash. Add the mcp.enabled and mcp.async.job.wait settings in their own MCP group of the global settings.
Add a servlet that implements the Streamable HTTP transport of the Model Context Protocol without streaming and without sessions, for the protocol revisions 2025-06-18 and 2025-11-25. Requests are authenticated with an MCP token and run as the user that owns it. Instead of one tool per API, four tools search, describe and execute any API available to the user and query asynchronous jobs. APIs go through ApiServerService, so the role permissions, the allowed source CIDRs, the API rate limit and the project roles apply as in /client/api. The server is off by default (mcp.enabled).
Add an MCP Tokens tab to the user view to list and revoke the tokens of the user and, for the logged in user, to create one. The token is shown only once, right after it is created.
Accept the 2026-07-28 revision, which drops the initialize handshake: answer server/discover, validate the MCP-Protocol-Version, Mcp-Method and Mcp-Name headers against the request body, and return resultType and cache hints. The 2025-11-25 and 2025-06-18 revisions keep working through initialize.
Users are soft deleted, so the foreign key cascade never fires and the tokens stayed behind. Remove them when a user or its account is deleted, and when a user is moved to another account, since the token keeps the account and domain it was created in.
This branch has not been deployed
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.
Description
This PR adds a native MCP (Model Context Protocol) server to the management server, served at
/client/mcp, so MCP clients can use the CloudStack APIs the same way CloudMonkey does. There is no extra process and no new dependency: the JSON-RPC layer is written on top of the servlet API and Gson, both already in the classpath.Every call goes through the same path as the regular API (
ApiServerService.verifyRequestfollowed byhandleRequest), so CIDR restrictions, role permissions, rate limiting andapi.key.accessapply unchanged. The feature is disabled by default.Access tokens
createMcpToken,listMcpTokensandrevokeMcpToken, with the eventsMCP.TOKEN.CREATEandMCP.TOKEN.REVOKE.cloud.mcp_token. Only the SHA-256 hash is stored; the token (csmcp_…) is returned once, on creation, and never logged.Server
2025-06-18and2025-11-25(withinitialize) and2026-07-28(no handshake,server/discover, validation of theMCP-Protocol-Version,Mcp-MethodandMcp-Nameheaders).Originwhose host differs fromHostare rejected.cloudstack_search_apiscloudstack_describe_apicloudstack_execute_apimcp.async.job.waitcloudstack_query_async_jobConfiguration
New group MCP in Global Settings, both settings dynamic:
mcp.enabled(defaultfalse): when off,/client/mcpanswers 404.mcp.async.job.wait(default20seconds).UI
"MCP Tokens" tab in the user view, with a dialog that shows the token once. Labels in
enandpt_BR.Usage
Known limits
This change has not been discussed on the dev mailing list yet and has no functional specification; I am happy to start that discussion if the feature is of interest.
This work was developed with the assistance of an AI coding tool (Claude Code).
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?
McpServletTest,McpParamEncoderTestandMcpTokenManagerImplTest, plus the changedAccountManagerImplTest. Run together withApiServletTestandApiServerTest: 255 tests pass.mvn jetty:runwith the simulator, MySQL, nginx with TLS in front): 61 scripted checks pass, covering the toggle through the API, the token lifecycle, the three protocol revisions, synchronous and asynchronous calls (deployVirtualMachine,destroyVirtualMachine), LIST and MAP parameters, and the removal of tokens with the account and withmoveUser.2026-07-28and lists the tools.Not tested:
ServerDaemon), so its 30 s idle timeout and gzip handling were not exercised;mcp.async.job.waitdefaults to 20 s for that reason.How did you try to break this feature and the system with this change?
Authorizationheader, unknown token, revoked token, expired token and a user withapikeyaccessdisabled all get 401.Originfrom another host gets 403; GET gets 405; withmcp.enabled=falsethe endpoint answers 404.listHosts) gets a tool error, not data.command,response,apikey,signature,sessionkey, …) passed as tool arguments are rejected.