Process ID file path for process management and reloading
reload_interval
Configuration reload interval, default 600s
reload_switch
Whether to enable automatic configuration reloading
A configuration can be treated as a namespace, recommended to distinguish by service or domain. A service contains many API interfaces, each API interface corresponds to a Tool.
name: Proxy service name, globally unique, used to identify different proxy services
tenant: Tenant identifier for data isolation and permission management in multi-tenant scenarios
Cross-Origin Resource Sharing (CORS) configuration is used to control access permissions for cross-origin requests:
Copy
cors: allowOrigins: # Development and test environments can be fully open, production should be opened as needed. (Most MCP Clients do not need to open cross-origin) - "*" allowMethods: # Allowed request methods, open as needed, for MCP (SSE and Streamable) usually only these 3 methods are needed - "GET" - "POST" - "OPTIONS" allowHeaders: - "Content-Type" # Must be allowed - "Authorization" # Required for authentication needs to support carrying this key in requests - "Mcp-Session-Id" # For MCP, must support carrying this key in requests, otherwise Streamable HTTP cannot be used normally exposeHeaders: - "Mcp-Session-Id" # For MCP, when cross-origin is enabled, this key must be exposed, otherwise Streamable HTTP cannot be used normally allowCredentials: true # Whether to add Access-Control-Allow-Credentials: true header
Usually, MCP Clients do not need to open cross-origin
Service configuration is used to define service metadata, associated tool lists, and service-level configuration:
Copy
servers: - name: "mock-server" # Service name, must match server in routers namespace: "user-service" # Service namespace for service grouping description: "Mock User Service" # Service description allowedTools: # List of allowed tools (subset of tools) - "register_user" - "get_user_by_email" - "update_user_preferences" config: # Service-level configuration, can be referenced in tools via {{.Config}} Cookie: 123 # Hardcoded configuration Authorization: 'Bearer {{ env "AUTH_TOKEN" }}' # Configuration from environment variables, usage is '{{ env "ENV_VAR_NAME" }}'
Service-level configuration can be referenced in tools via {{.Config}}. This can be hardcoded in the configuration file or obtained from environment variables. For environment variable injection, reference using {{ env "ENV_VAR_NAME" }}.
Tool configuration is used to define specific API call rules. Each parameter can set a default value (default), which will be automatically used when the parameter is not provided in the MCP request.
When using form-data as parameter position, no need to specify requestBody, the system will automatically assemble parameters into multipart/form-data format.
For JSON format request body, assembly is needed in requestBody, for example:
Including endpoint (target address) can also use the above sources to extract values, such as http://localhost:5236/users/{{.Args.email}}/preferences which extracts values from request parameters.
In addition to proxying HTTP services, MCP Gateway also supports proxying MCP services. Currently, stdio, SSE, and streamable-http three transport protocols are all supported.
mcpServers: - type: "stdio" name: "amap-maps" # Service name command: "npx" # Command to execute args: # Command arguments - "-y" - "@amap/amap-maps-mcp-server" env: # Environment variables AMAP_MAPS_API_KEY: "{{.Request.Headers.Apikey}}" # Extract value from request headers
Environment variables can be set via the env field, supporting value extraction from requests, for example {{.Request.Headers.Apikey}} means extract the Apikey value from request headers.
mcpServers: - type: "sse" name: "mock-user-sse" # Service name url: "http://localhost:3000/gateway/user/sse" # Upstream SSE service address, usually ends with /sse, actual depends on upstream service
streamable-http type MCP service configuration example:
Copy
mcpServers: - type: "streamable-http" name: "mock-user-mcp" # Service name url: "http://localhost:3000/gateway/user/mcp" # Upstream MCP service address, usually ends with /mcp, actual depends on upstream service
For MCP service proxy, routing configuration is similar to HTTP service proxy. CORS should be configured according to actual situation (usually production environments generally do not enable cross-origin):
Copy
routers: - server: "amap-maps" # Service name, must match name in mcpServers prefix: "/gateway/stdio-proxy" # Route prefix, globally unique cors: allowOrigins: - "*" allowMethods: - "GET" - "POST" - "OPTIONS" allowHeaders: - "Content-Type" - "Authorization" - "Mcp-Session-Id" # MCP service must include this header exposeHeaders: - "Mcp-Session-Id" # MCP service must expose this header allowCredentials: true
For MCP services, Mcp-Session-Id in request and response headers must be supported, otherwise clients cannot use it normally.
Environment variables can be used in configuration, supporting default values:
Copy
# Basic syntaxport: ${MCP_GATEWAY_PORT:5235} # Use environment variable, default value 5235# String formatlogger: level: "${LOGGER_LEVEL:info}" # Use environment variable, default value info# Use in service configurationconfig: ApiKey: '{{ env "API_KEY" }}' BaseUrl: '{{ env "API_BASE_URL" "http://localhost:8080" }}' # With default value
Using the toJSON function ensures complex objects and arrays are correctly serialized to JSON format, especially suitable for nested structures and data containing special characters.