mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-29 14:04:46 +03:00
feat(mcp): add a built-in MCP server at /panel/api/mcp (#6956)
AI agents (Claude, Cursor, VS Code) can manage the panel through a stateless streamable-HTTP MCP endpoint. Every tool re-enters the router with the caller's credentials, so authentication, token scopes, CSRF and runtime.Runtime dispatch apply exactly as for the REST API; a restricted token scope is refused, log text is fenced as untrusted data, and each tool call is written to the panel log. The endpoint hands an API token's whole reach to the agent that holds it, so it is off by default: a panel answers 404 until the MCP server is enabled under Settings -> Security -> API Token (the mcpEnable setting).
This commit is contained in:
@@ -39,6 +39,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"ldapUserAttr": "",
|
||||
"ldapUserFilter": "",
|
||||
"ldapVlessField": "",
|
||||
"mcpEnable": false,
|
||||
"networkTrafficInterface": "eth0",
|
||||
"networkTrafficMode": "legacy",
|
||||
"nodeDownThreshold": 1,
|
||||
@@ -250,6 +251,7 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"ldapUserAttr": "",
|
||||
"ldapUserFilter": "",
|
||||
"ldapVlessField": "",
|
||||
"mcpEnable": false,
|
||||
"networkTrafficInterface": "eth0",
|
||||
"networkTrafficMode": "legacy",
|
||||
"nodeDownThreshold": 1,
|
||||
|
||||
@@ -126,6 +126,9 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"ldapVlessField": {
|
||||
"type": "string"
|
||||
},
|
||||
"mcpEnable": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"networkTrafficInterface": {
|
||||
"example": "eth0",
|
||||
"type": "string"
|
||||
@@ -695,6 +698,7 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"ldapUserAttr",
|
||||
"ldapUserFilter",
|
||||
"ldapVlessField",
|
||||
"mcpEnable",
|
||||
"networkTrafficInterface",
|
||||
"networkTrafficMode",
|
||||
"nodeDownThreshold",
|
||||
@@ -1015,6 +1019,9 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"ldapVlessField": {
|
||||
"type": "string"
|
||||
},
|
||||
"mcpEnable": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"networkTrafficInterface": {
|
||||
"example": "eth0",
|
||||
"type": "string"
|
||||
@@ -1594,6 +1601,7 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"ldapUserAttr",
|
||||
"ldapUserFilter",
|
||||
"ldapVlessField",
|
||||
"mcpEnable",
|
||||
"networkTrafficInterface",
|
||||
"networkTrafficMode",
|
||||
"nodeDownThreshold",
|
||||
|
||||
@@ -44,6 +44,7 @@ export interface AllSetting {
|
||||
ldapUserAttr: string;
|
||||
ldapUserFilter: string;
|
||||
ldapVlessField: string;
|
||||
mcpEnable: boolean;
|
||||
networkTrafficInterface: string;
|
||||
networkTrafficMode: string;
|
||||
nodeDownThreshold: number;
|
||||
@@ -256,6 +257,7 @@ export interface AllSettingView {
|
||||
ldapUserAttr: string;
|
||||
ldapUserFilter: string;
|
||||
ldapVlessField: string;
|
||||
mcpEnable: boolean;
|
||||
networkTrafficInterface: string;
|
||||
networkTrafficMode: string;
|
||||
nodeDownThreshold: number;
|
||||
|
||||
@@ -54,6 +54,7 @@ export const AllSettingSchema = z.object({
|
||||
ldapUserAttr: z.string(),
|
||||
ldapUserFilter: z.string(),
|
||||
ldapVlessField: z.string(),
|
||||
mcpEnable: z.boolean(),
|
||||
networkTrafficInterface: z.string(),
|
||||
networkTrafficMode: z.enum(['legacy', 'auto', 'manual']),
|
||||
nodeDownThreshold: z.number().int().min(1).max(100),
|
||||
@@ -267,6 +268,7 @@ export const AllSettingViewSchema = z.object({
|
||||
ldapUserAttr: z.string(),
|
||||
ldapUserFilter: z.string(),
|
||||
ldapVlessField: z.string(),
|
||||
mcpEnable: z.boolean(),
|
||||
networkTrafficInterface: z.string(),
|
||||
networkTrafficMode: z.enum(['legacy', 'auto', 'manual']),
|
||||
nodeDownThreshold: z.number().int().min(1).max(100),
|
||||
|
||||
@@ -77,6 +77,7 @@ export class AllSetting {
|
||||
externalTrafficInformEnable = false;
|
||||
externalTrafficInformURI = '';
|
||||
restartXrayOnClientDisable = true;
|
||||
mcpEnable = false;
|
||||
subCertFile = '';
|
||||
subKeyFile = '';
|
||||
externalSubUserAgent = 'v2rayNG/1.8.5';
|
||||
|
||||
@@ -2164,6 +2164,31 @@ export const sections: readonly Section[] = [
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
id: 'mcp',
|
||||
title: 'MCP',
|
||||
description:
|
||||
'Model Context Protocol endpoint for AI agents (Claude, Cursor, VS Code). Point an MCP client at this URL with an admin Bearer token; restricted token scopes are refused.',
|
||||
endpoints: [
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/panel/api/mcp',
|
||||
summary:
|
||||
'Stateless streamable-HTTP MCP endpoint (JSON-RPC 2.0). Exposes panel tools for inbounds, clients, server, Xray, nodes, hosts and settings; each tool call runs the matching /panel/api route with the caller’s credentials. Off by default: answers 404 until the MCP server is enabled under Settings → Security → API Token.',
|
||||
params: [
|
||||
{
|
||||
name: 'toolsets',
|
||||
in: 'query',
|
||||
type: 'string',
|
||||
optional: true,
|
||||
desc: 'Comma-separated tool groups to expose: inbounds, clients, server, panel. Omit for all. call_api and get_openapi_spec are always included.',
|
||||
},
|
||||
],
|
||||
body: '{\n "jsonrpc": "2.0",\n "id": 1,\n "method": "tools/list"\n}',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
id: 'settings',
|
||||
title: 'Settings',
|
||||
|
||||
@@ -375,6 +375,16 @@ export default function SecurityTab({ allSetting, updateSetting, saveSetting }:
|
||||
label: catTabLabel(<ApiOutlined aria-hidden />, t('pages.nodes.apiToken'), isMobile),
|
||||
children: (
|
||||
<div className="api-token-section">
|
||||
<SettingListItem
|
||||
paddings="small"
|
||||
title={t('pages.settings.security.mcpEnable')}
|
||||
description={t('pages.settings.security.mcpEnableDesc')}
|
||||
>
|
||||
<Switch
|
||||
checked={allSetting.mcpEnable}
|
||||
onChange={(v) => updateSetting({ mcpEnable: v })}
|
||||
/>
|
||||
</SettingListItem>
|
||||
<div className="api-token-header">
|
||||
<p className="api-token-hint">{t('pages.nodes.apiTokenHint')}</p>
|
||||
<Button type="primary" size="small" onClick={openCreateModal}>
|
||||
|
||||
@@ -88,6 +88,7 @@ export const AllSettingFieldsSchema = z
|
||||
externalTrafficInformEnable: z.boolean().optional(),
|
||||
externalTrafficInformURI: z.string().optional(),
|
||||
restartXrayOnClientDisable: z.boolean().optional(),
|
||||
mcpEnable: z.boolean().optional(),
|
||||
subCertFile: z.string().optional(),
|
||||
subKeyFile: z.string().optional(),
|
||||
externalSubUserAgent: z.string().max(512).optional(),
|
||||
|
||||
Reference in New Issue
Block a user