MCP Gateway is a reverse proxy and management layer for MCP servers, enabling scalable, session-aware stateful routing and lifecycle management of MCP servers i
MCP Gateway is a reverse proxy and management layer for MCP servers, enabling scalable, session-aware stateful routing and lifecycle management of MCP servers i
MCP Gateway is a reverse proxy and management layer for Model Context Protocol (MCP) servers, enabling scalable, session-aware routing, authorization and lifecycle management of MCP servers in Kubernetes environments.
This project provides:
/adapters scope. Designed to coexist with other resource types (e.g., /agents) in a unified AI development platform.session_id are consistently routed to the same MCP server instance.FoundrySettings:Endpoint is configured.…POST /adapters — Deploy and register a new MCP server.GET /adapters — List all MCP servers the user can access.GET /adapters/{name} — Retrieve metadata for a specific adapter.GET /adapters/{name}/status — Check the deployment status.GET /adapters/{name}/logs — Access the server's running logs.PUT /adapters/{name} — Update the deployment.DELETE /adapters/{name} — Remove the server.POST /tools — Register and deploy a tool with MCP tool definition metadata.GET /tools — List all registered tools the user can access.GET /tools/{name} — Retrieve metadata and tool definition for a specific tool.GET /tools/{name}/status — Check the tool deployment status.GET /tools/{name}/logs — Access the tool server's running logs.PUT /tools/{name} — Update a tool deployment and definition.DELETE /tools/{name} — Remove a registered tool.Available only when FoundrySettings:Endpoint is configured. See Agents and Sessions below for details.
POST /agents, GET /agents, GET|PUT|DELETE /agents/{name} — CRUD for agent definitions.POST /sessions, GET /sessions, GET|DELETE /sessions/{id} — CRUD for sessions.POST /sessions/run — Start a session and stream events (SSE).POST /sessions/{id}/messages — Continue an existing session with a new user message; streams events (SSE).POST /adapters/{name}/mcp — Establish a streamable HTTP connection.POST /mcp — Route requests to the tool gateway router, which dynamically routes to registered tools based on tool definitions. The router itself is an MCP server with multiple instances hosted behind the gateway for scalability.The gateway provides entra id authentication and basic application role authorization for mcp servers and tools:
requiredRoles values (for example mcp.engineer), and anyone holding the mandatory administrator role mcp.admin. When requiredRoles is empty or omitted, only the creator and mcp.admin principals can read the resource.mcp.admin role.For step-by-step guidance on configuring Azure Entra ID (creating mcp.admin and other role values, assigning them to users or service principals, and supplying those values in adapter/tool payloads), see docs/entra-app-roles.md.
/portal/ — list / create / edit / delete adapters and
tools, inspect status and pod logs, and exercise each MCP server with an
in-browser JSON-RPC test console. Authentication mirrors the API: anonymous
in dev mode (with an optional dev-identity switcher) and MSAL / Entra ID in
cloud mode, so every list call already filters down to the resources the
signed-in user is allowed to see.The MCP Gateway now supports tool registration with dynamic routing capabilities, enabling a scalable architecture for managing and executing MCP tools.
Tool Registration: Developers register tools via the /tools API endpoint, providing:
Tool Gateway Router: A specialized MCP server that acts as an intelligent router:
POST /mcp endpoint (without adapter name)Dynamic Routing: When clients send MCP requests to /mcp:
Preview / single-replica. This subsystem is opt-in and intended for evaluation and single-pod deployments. Built-in tools execute in-process inside the gateway pod, and per-session state (working directory, disk-quota counters) is local to that pod. Do not enable this in a multi-replica or multi-tenant production deployment without adding an out-of-process sandbox and shared session storage.
The gateway can optionally run LLM-driven agents that call registered MCP tools and a small set of built-in tools (builtin:bash, builtin:read_file, builtin:write_file). The agent CRUD endpoints (/agents, /sessions GET/DELETE/LIST) are always available, but streaming session execution (POST /sessions/run, POST /sessions/{id}/messages) is only enabled when FoundrySettings:Endpoint is configured. Without it, a streaming request fails fast with an error SSE event saying that Foundry must be configured.
Add a FoundrySettings section to appsettings.json (or supply via environment variables):
{
"FoundrySettings": {
"Endpoint": "https://.cognitiveservices.azure.com/",
"DeploymentName": "gpt-4o"
}
}Authentication uses DefaultAzureCredential; grant the gateway's identity (managed identity in AKS, or your local user via az login) the Cognitive Services User role on the target resource. Tool-emitting models are required for any agent with a non-empty tools array — gpt-4o-class deployments are recommended.
POST /agents
Authorization: Bearer
Content-Type: application/json{
"name": "weather-helper",
"model": "gpt-4o",
"system": "You answer weather questions concisely.",
"tools": ["mcp:weather"],
"description": "Demo agent backed by the weather MCP tool."
}tools entries are namespaced by prefix:
mcp: — routes to a tool registered via /tools.agent: — delegates to another agent (subagent / Task pattern).builtin:bash, builtin:read_file, builtin:write_file — in-process built-ins (see Built-in tools and limits below).Referenced mcp: and agent: resources are validated at agent create/update time: the call fails if the resource does not exist or the caller lacks read access, so an agent can never reference tools or peer agents the creator could not invoke directly.
POST /sessions/run
Authorization: Bearer
Content-Type: application/json
Accept: text/event-stream{ "agentName": "weather-helper", "input": "What's the weather in Seattle?" }The response is a Server-Sent Events stream; each event is event: \ndata: \n\n. Event types include Started, ToolCallStarted, ToolCallCompleted, TokenDelta, Completed, and Failed.
To continue an existing session with a follow-up message:
POST /sessions/{id}/messages
Content-Type: application/json
{ "input": "And in Portland?" }When an agent lists builtin:bash / builtin:read_file / builtin:write_file in its tools, those built-ins run in the gateway pod under a per-session working directory. They are guarded by:
builtin:bash: the spawned shell receives only a minimal allowlist (PATH, locale, TERM, TZ) with HOME / TMPDIR / PWD pinned to the session directory. The full gateway process environment is not inherited.sudo, network egress, mounts, package managers, etc.). This is defense-in-depth, not a sandbox... traversal.For multi-tenant or production use, replace these with a real per-session sandbox (e.g. ephemeral pod, gVisor, firejail) — see the inline comments in BuiltinToolExecutor.cs.
docker run -d -p 5000:5000 --name registry registry:2.7Build and push the MCP server images to your local registry (localhost:5000).
docker build -f sample-servers/mcp-example/Dockerfile sample-servers/mcp-example -t localhost:5000/mcp-example:1.0.0
docker push localhost:5000/mcp-example:1.0.0(Optional) Open dotnet/Microsoft.McpGateway.sln with Visual Studio.
Publish the M
No open issues yet, or sync has not completed.