mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6956] feat(mcp): add built-in MCP server at /panel/api/mcp #6540
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6540
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6956
Author: @sepehr071
Created: 10/26/2026
Status: 🔄 Open
Base:
main← Head:feat/mcp-server📝 Commits (2)
9f5bd6cfeat(mcp): add built-in MCP server at /panel/api/mcp2d080b1fix(mcp): fence untrusted log text and surface redirects📊 Changes
22 files changed (+2576 additions, -4 deletions)
View changed files
📝
CLAUDE.md(+6 -0)➕
docs/content/docs/en/reference/api/mcp.mdx(+37 -0)📝
docs/content/docs/en/reference/api/meta.json(+1 -0)📝
docs/public/openapi.json(+60 -0)📝
frontend/public/openapi.json(+60 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+25 -0)📝
go.mod(+6 -0)📝
go.sum(+14 -0)📝
internal/web/controller/api.go(+6 -3)➕
internal/web/mcp/mcp.go(+218 -0)➕
internal/web/mcp/mcp_test.go(+404 -0)➕
internal/web/mcp/tools.go(+233 -0)➕
internal/web/mcp/tools_clients.go(+349 -0)➕
internal/web/mcp/tools_clients_test.go(+172 -0)➕
internal/web/mcp/tools_inbounds.go(+110 -0)➕
internal/web/mcp/tools_inbounds_test.go(+77 -0)➕
internal/web/mcp/tools_panel.go(+151 -0)➕
internal/web/mcp/tools_panel_test.go(+53 -0)➕
internal/web/mcp/tools_server.go(+269 -0)➕
internal/web/mcp/tools_server_test.go(+144 -0)...and 2 more files
📄 Description
Closes #6932. Closes #6658.
What
A built-in Model Context Protocol server at
POST /panel/api/mcp. MCP clients (Claude, Cursor, VS Code) can manage inbounds, clients, server/Xray, nodes, hosts and settings with an admin API token.How
internal/web/mcp, using the official Go SDK (github.com/modelcontextprotocol/go-sdkv1.8.0) in stateless streamable-HTTP mode./panel/apigroup, socheckAPIAuth,enforceTokenScopeand CSRF apply unchanged. Restricted scopes (monitor, node-sync, node-admin) get 403. A logged-in browser session must pass the usual CSRF check.dispatcher.call) and forwards the caller'sAuthorization,Cookie, CSRF and proxy headers. Validation, token scopes andruntime.Runtimedispatch therefore run exactly as they do for REST, and multi-node setups stay consistent.inbounds(6),clients(13),server(10) andpanel(13), plus 2 core tools. Each tool covers one user task, and arguments select the variant (for examplesave_clientcreates withoutemailand updates with it). Tools carry read-only / destructive annotations.?toolsets=clients,inboundsloads only some groups, for clients with tool limits (Cursor caps near 40). An unknown name returns 400.call_apireaches any other/panel/api/*route. It refuses..and recursion into/mcp.get_openapi_specgives agents a route index, or one prefix's operations plus the schemas they reference, instead of the 515 KB spec.call_api, exactly as an admin token can reach them over REST; nothing escalates.get_logsoutput is fenced as untrusted data and the tool is markedopenWorldHint, because failed-login usernames and client traffic put text written by unauthenticated parties into the logs. Every other tool is marked closed-world.MCP tool request: METHOD path -> status (from ip)), so agent-driven changes can be told apart from REST calls (#6658 audit-trail request).Endpoint chain
endpoints.tsentry (with thetoolsetsparam),make gen,docs/public/openapi.jsoncopied,pnpm gen:api(newreference/api/mcp.mdx, added tometa.json).CLAUDE.mdrepo map updated.Tests
TestToolsHitDocumentedRoutes: drives every tool through a real MCP client. It asserts the exact method, path, query and body each tool sends, and checks that the route exists inendpoints.ts(whichTestRouteRegistryContractpins to the real router). A tool without a case fails the test.TestMCPEndpointUsesPanelAuth(real router, real DB): anonymous gets 404, a monitor token gets 403, and an admin token'scall_apireaches the real handler. Verified red when Authorization forwarding is removed.TestToolsetsFilterTools,TestCallAPIRejectsPathsOutsideAPI,TestToolResultMapsPanelReplies,TestDescribeOpenAPI.make verifypasses locally (Docker, Linux): gen-check, lint, format, typecheck, Go and frontend tests, build, Storybook build, docs OpenAPI check. Not run locally: Postgres, node-e2e and race jobs.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.