This policy for Gravitee.io API Gateway enables proxying and forwarding of various data streams, including Server-Sent Events (SSE) and HTTP streams with multiple operating modes.
- SSE to SSE Forwarding: Proxy SSE events from a remote SSE server to clients
- STDIO to SSE Forwarding: Convert local process output to SSE events for clients
- SSE to STDIO Forwarding: Forward received SSE events to a local process
- HTTP Stream Proxying: Direct HTTP stream forwarding with minimal transformation
$ mvn clean installCopy the generated JAR file from the target directory to the Gravitee.io plugins directory:
$ cp target/mcp-proxy-policy-1.0.0-SNAPSHOT.zip /path/to/gravitee/plugins/{
"mcp-proxy": {
"proxyMode": "SSE_TO_SSE",
"remoteHost": "events.example.com",
"remotePort": 443,
"secureConnection": true,
"headers": [
{
"name": "Authorization",
"value": "Bearer TOKEN"
}
],
"keepAliveSeconds": 30
}
}{
"mcp-proxy": {
"proxyMode": "STDIO_TO_SSE",
"command": "python generate_events.py",
"environmentVars": [
{
"name": "EVENT_INTERVAL",
"value": "1000"
},
{
"name": "MAX_EVENTS",
"value": "100"
}
],
"keepAliveSeconds": 30
}
}{
"mcp-proxy": {
"proxyMode": "SSE_TO_STDIO",
"command": "node process_events.js",
"environmentVars": [
{
"name": "LOG_LEVEL",
"value": "info"
},
{
"name": "OUTPUT_DIR",
"value": "/tmp/events"
}
]
}
}{
"mcp-proxy": {
"proxyMode": "HTTP_STREAM",
"remoteHost": "stream.example.com",
"remotePort": 8080,
"secureConnection": false,
"headers": [
{
"name": "X-API-Key",
"value": "your-api-key"
}
]
}
}| Property | Description | Type | Default | Required |
|---|---|---|---|---|
| proxyMode | Proxy mode (SSE_TO_SSE, STDIO_TO_SSE, SSE_TO_STDIO, HTTP_STREAM) | enum | SSE_TO_SSE | Yes |
| remoteHost | Remote server hostname | string | - | Yes (for SSE_TO_SSE and HTTP_STREAM) |
| remotePort | Remote server port | integer | 8080 | No |
| command | Local command to execute | string | - | Yes (for STDIO modes) |
| headers | Custom HTTP headers | array | [] | No |
| environmentVars | Environment variables for local process | array | [] | No |
| keepAliveSeconds | Keep-alive timeout in seconds | integer | 15 | No |
| secureConnection | Use HTTPS | boolean | false | No |
The policy forwards requests to a remote SSE server and proxies the SSE events back to the client. It maintains proper SSE formatting and sends keep-alive messages when configured.
The policy executes a local process, captures its stdout, and converts each line to an SSE event that is sent to the client. This allows any command-line tool to become an SSE source.
The policy receives SSE events from clients, extracts the data, and forwards it to a local process via stdin. The process can then process the events as needed.
The policy directly forwards HTTP streams between client and remote server with minimal transformation. This is useful for streaming APIs that don't follow the SSE format.
- The SSE modes require proper SSE events in the standard format
- Local process execution requires appropriate permissions on the gateway host
- Large volumes of events may impact gateway performance
For troubleshooting, check the Gravitee Gateway logs. The policy uses the following logger names:
io.gravitee.policy.sse.MCPProxyPolicyio.gravitee.policy.sse.handlers.SSEToSSEHandlerio.gravitee.policy.sse.handlers.StdioToSSEHandlerio.gravitee.policy.sse.handlers.SSEToStdioHandlerio.gravitee.policy.sse.handlers.HttpStreamHandlerio.gravitee.policy.sse.utils.MCPUtils
Contributions are welcome! Please feel free to submit a Pull Request.