NetScaler as an MCP Gateway
x-netscaler-mcp-server header. This architecture simplifies client integration, ensures consistent policy enforcement, and allows you to apply uniform operational controls, such as traffic monitoring, session persistence, and rate limiting, across all MCP traffic.
Understanding the MCP profile
| Parameter | Values | Default | Description |
|---|---|---|---|
-comment |
<string> |
-- | Optional description for the MCP profile. |
-insertHeaderInClientRequest |
ENABLED / DISABLED | DISABLED | Inserts an authorization header (token) into requests sent to the backend MCP server. |
-mcpProtocolVersion |
<string> |
-- | Specifies the MCP protocol version used in communication. |
-mcpTokenOrApi |
<token> |
-- | Token (PAT/API key) used for backend authentication. |
-proxyMode |
FORWARD / REVERSE | FORWARD | Defines the deployment model of the NetScaler MCP Gateway. |
-hostReplacement |
ENABLED / DISABLED | ENABLED | Rewrites the host header to match the backend MCP server FQDN. |
-urlReplacement |
ENABLED / DISABLED | ENABLED | Rewrites the request URL or path for backend compatibility. |
-mcpCounterStatistics |
ENABLED / DISABLED | ENABLED | Enables MCP-specific statistics counters. |
-mcpprofileType |
FRONTEND / BACKEND | BACKEND | Defines whether the profile is applied at the front end or the back end. |
Points to note
-
In forward-proxy mode, client requests are sent to a single gateway URL, and NetScaler routes traffic to different backend MCP servers based on a custom header.
-
Session stickiness is required for stateful MCP servers. Subsequent requests for a session must reach the same backend server to avoid session-not-found errors.
-
If backend MCP servers expect a specific host header and backend URL path, use MCP profile host or URL replacement, or equivalent rewrite policies.
Use case
Prerequisites
-
Deploy a content switching virtual server to act as the primary MCP Gateway entry point.
-
Create load balancing virtual servers or services for backend MCP servers and verify that their FQDNs and paths are reachable.
-
Configure clients to send the target backend identifier using the
x-netscaler-target-mcp-serverheader. -
Set up token insertion in the MCP profile, or ensure clients pass tokens using the
X-Netscaler-Backend-Auth-Tokenheader. -
Verify administrative privileges to create and bind content switching, load balancing, rewrite, responder, and authentication configurations.
Configure NetScaler as an MCP Gateway
A. Configure a content switching gateway virtual server
add cs vserver cs1 SSL <IP address> 80 -cltTimeout 180 -persistenceType NONE
add lb vserver lb_app1_mcp SSL 0.0.0.0 0
add lb vserver lb_app2_mcp SSL 0.0.0.0 0
add serviceGroup sg_app1 SSL
bind serviceGroup sg_app1 <server_ip> 443
bind lb vserver lb_app1_mcp sg_app1
add serviceGroup sg_app2 SSL
bind serviceGroup sg_app2 <server_ip> 443
bind lb vserver lb_app2_mcp sg_app2
add cs action cs_act_app1 -targetLBVserver lb_app1_mcp
add cs action cs_act_app2 -targetLBVserver lb_app2_mcp
add cs policy new-pol-app1 -rule "HTTP.REQ.HEADER(\"x-netscaler-target-mcp-server\").BEFORE_STR(\"/\").CONTAINS(\"app1.com\")" -action cs_act_app1
add cs policy new-pol-app2 -rule "HTTP.REQ.HEADER(\"x-netscaler-target-mcp-server\").BEFORE_STR(\"/\").CONTAINS(\"app2.com\")" -action cs_act_app2
bind cs vserver cs1 -policyName new-pol-app1 -priority 10
bind cs vserver cs1 -policyName new-pol-app2 -priority 15
B. Optional response-side rewrites for authentication flows
WWW-Authenticate challenge containing resource metadata, apply response-side rewrites so that the client continues to interact safely through the gateway.
add rewrite action resp_act1 replace q{http.res.header("www-authenticate").After_str("resource_metadata=\"").before_str(":/")} "\"http\""
add rewrite action resp_act replace q{http.res.header("www-authenticate").After_str("resource_metadata=\"https://").before_str("/")} http.req.hostname
add rewrite action rw_act1 replace_all "HTTP.RES.BODY(10000)" q{CLIENT.SSL.IS_SSL.IF(",\"resource\":\"https://" + http.req.hostname + "/mcp\"", ",\"resource\":\"http://" + http.req.hostname + "/mcp\"")} -search "xpath_json(xp%/resource%)"
add rewrite policy rw_pol2 "http.req.url.eq(\"/mcp\") && CLIENT.SSL.IS_SSL.NOT" resp_act1
add rewrite policy rw_pol1 true resp_act
add rewrite policy rw_pol3 true rw_act1
# Bind the response-side rewrite policies to the backend LB vserver (example shown for App1 vserver)
bind lb vserver lb_app1_mcp -policyName rw_pol2 -priority 6 -gotoPriorityExpression next -type RESPONSE
bind lb vserver lb_app1_mcp -policyName rw_pol1 -priority 7 -gotoPriorityExpression next -type RESPONSE
bind lb vserver lb_app1_mcp -policyName rw_pol3 -priority 8 -gotoPriorityExpression next -type RESPONSE
C. Use the MCP profile to reduce rewrite overhead
hostReplacement and urlReplacement in the MCP profile and bind it to the backend service or service group to eliminate complex manual rewrites.
add mcpprofile m1 -hostReplacement ENABLED -urlReplacement ENABLED
set service mcp -mcpProfileName m1
set servicegroup sg1 -mcpProfileName m1
D. Sample client configuration
{
"servers": {
"proxy-server": {
"url": "https://proxy.aaanetscaler.local/mcp",
"type": "http",
"headers": {
"x-netscaler-target-mcp-server": "api.githubcopilot.com/mcp/",
"X-MCP-TOOLSETS": "all"
}
}
},
"inputs": []
}
Troubleshooting
Routing goes to the wrong backend MCP server
x-netscaler-mcp-server) and content switching policy expressions.
Backend MCP server returns session errors
Authentication challenges redirect clients away from the gateway
WWW-Authenticate resource metadata points to backend URLs.