Feature Request: Native MCP Server for AI-driven 3x-ui Management
I would like to suggest adding support for the Model Context Protocol (MCP) to 3x-ui.
The main idea is to make it possible for MCP-compatible AI assistants such as Claude, ChatGPT, Gemini, and other AI agents to securely interact with 3x-ui through its existing API.
This could make 3x-ui much easier to automate and manage with AI. For example, instead of manually creating an inbound and configuring a client, a user could simply tell an AI assistant:
"Create a VLESS Reality client for Alice with 100 GB of traffic and 30 days expiration."
The AI could then inspect the available configuration, choose a suitable inbound, create the client, validate the result, and return the connection information to the user.
Describe the solution you'd like
3x-ui already has a REST API, so most of the functionality needed for this is already available.
MCP could provide a standard interface between AI assistants and 3x-ui, rather than requiring every AI application to build its own custom integration.
The architecture could look something like this:
AI Assistant │ │ MCP ▼ 3x-ui MCP Server │ │ 3x-ui REST API ▼ 3x-ui │ ▼ Xray-core
Ideally, the MCP layer would use the existing 3x-ui API instead of directly modifying the Xray configuration or database.
Possible MCP Tools
A first version could expose simple read-only tools such as:
get_server_status
get_xray_status
list_inbounds
get_inbound
list_clients
get_client
get_client_traffic
get_online_clients
get_xray_logs
get_server_statistics
And management tools such as:
create_client
update_client
delete_client
reset_client_traffic
set_client_expiry
set_client_traffic_limit
For inbound management:
create_inbound
update_inbound
delete_inbound
enable_inbound
disable_inbound
And some useful utility operations:
generate_uuid
generate_x25519_certificate
validate_configuration
restart_xray
Obviously, the exact tool list could be adjusted based on what makes the most sense for the existing 3x-ui API.
Security
Security would be especially important for an AI integration.
The MCP server should ideally:
Support read-only and administrative permissions.
Keep the 3x-ui API token and other credentials on the server side.
Never expose the API token directly to the AI model.
Require confirmation before destructive or high-impact operations.
Clearly separate read-only tools from tools that modify the server.
Keep an audit log of actions performed through MCP.
Validate tool inputs using strict schemas.
Rate-limit requests where appropriate.
Not allow arbitrary shell commands or arbitrary Xray configuration execution through MCP.
Redact sensitive information such as private keys by default.
For example, operations such as checking traffic or listing clients could be read-only, while deleting clients, changing inbounds, modifying routing, or restarting Xray could require explicit confirmation.
Example
A user could say:
"Create a VLESS Reality account for my iPhone with 50 GB traffic and an expiration date 30 days from now."
The AI could then:
- Check the available inbounds
- Find a compatible VLESS/Reality inbound
- Generate a UUID
- Create the client
- Validate the configuration
- Generate the connection/subscription information
- Return it to the user
The AI would not need direct access to the database, filesystem, or SSH.
MCP Resources
It could also be useful to expose some read-only information through MCP resources, for example:
Server status
Xray status
Inbound information
Client information
Traffic statistics
Xray logs
Sensitive information should be hidden or redacted unless it is explicitly required.
One Important Point
I don't think MCP should be treated as another VPN/Xray protocol.
Instead, MCP would act as an AI management interface for 3x-ui.
Xray would continue to handle the actual network protocols such as VLESS, VMess, Trojan, Shadowsocks, WireGuard, Hysteria2, etc.
This keeps the architecture clean and makes the feature useful without changing how Xray itself works.
Future Possibility
A particularly interesting use case would be AI-assisted VPN provisioning.
For example:
"Create a VLESS Reality client called iPhone, give it 100 GB of traffic for 60 days, and generate a QR code."
The AI could translate that request into a series of validated 3x-ui API operations through MCP.
This could make 3x-ui much easier to use for people who don't want to manually deal with UUIDs, inbounds, ports, traffic limits, expiration dates, and other configuration details.
Implementation Suggestion
I think it would be better to implement MCP as a separate component/package that sits on top of the existing 3x-ui API, rather than coupling MCP directly to Xray-core.
That would make it easier to:
Maintain MCP independently
Audit the security of the integration
Reuse the existing 3x-ui API
Support different MCP clients
Disable AI access when needed
Keep the existing 3x-ui/Xray architecture unchanged
The implementation could follow the official MCP specification and use strict schemas for all tool inputs and outputs.
Expected Benefit
The main benefit would be giving 3x-ui a standardized and secure way to work with modern AI assistants and agents.
Instead of making Xray itself "AI-enabled", this would make 3x-ui AI-controllable in a controlled and secure way, while keeping the existing Xray architecture intact.
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
No response
Are you willing to help?
- I'd like to implement this feature myself and open a PR.
- I can help test once a PR is open.
Before submitting
- I searched existing issues and this feature has not been requested.
- This feature request is written in English.
Source: MHSanaei/3x-ui