diff --git a/cmd/cmds.go b/cmd/cmds.go index 4c2d649..9830e0c 100644 --- a/cmd/cmds.go +++ b/cmd/cmds.go @@ -31,6 +31,7 @@ type StartCmd struct { InspectTraffic bool `default:"false" help:"Inspect MCP HTTP traffic"` ReadOnly bool `default:"false" help:"Run MCP in read-only mode. This disables all tool calls that modify ONTAP state."` Stateless bool `default:"false" help:"Run in stateless mode (no mcp-session-id header validation). Required when deploying behind proxies or gateways that don't preserve session headers, e.g. on-premises data gateways."` + JSONResponse bool `default:"false" help:"Respond with application/json instead of text/event-stream. Required when deploying behind proxies or gateways that do not relay SSE/chunked responses, e.g. on-premises data gateways."` } func (a *StartCmd) Run(cli *CLI) error { @@ -50,6 +51,7 @@ func (a *StartCmd) Run(cli *CLI) error { InspectTraffic: cli.Start.InspectTraffic, ReadOnly: cli.Start.ReadOnly, Stateless: cli.Start.Stateless, + JSONResponse: cli.Start.JSONResponse, } app := server.NewApp(cfg, opts, logger) diff --git a/docs/install.md b/docs/install.md index 9f30bb7..a7b8d69 100644 --- a/docs/install.md +++ b/docs/install.md @@ -135,6 +135,7 @@ Some commonly used flags: |---|---| | `--read-only` | Disable all mutating operations. Only read-only tools are registered. | | `--stateless` | Disable mcp-session-id header validation. Required when deploying behind proxies or gateways that do not preserve session headers, e.g. on-premises data gateways. | +| `--json-response` | Respond with application/json instead of text/event-stream. Required when deploying behind proxies or gateways that do not relay SSE/chunked responses, e.g. on-premises data gateways. | | `--inspect-traffic` | Log all MCP HTTP request and response bodies for debugging. | ## Next Steps diff --git a/docs/tools.md b/docs/tools.md index c3e52f6..41fbf40 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -10,6 +10,8 @@ If you want to run the ONTAP MCP server in read-only mode, you can start the ser To run without mcp-session-id header validation (e.g. behind proxies that strip session headers), use the `--stateless` flag. See the [configuration documentation](install.md#configuration) for more details. +To respond with `application/json` instead of `text/event-stream` (e.g. behind gateways that do not relay SSE/chunked responses), use the `--json-response` flag. See the [configuration documentation](install.md#configuration) for more details. + ## API Discovery - `list_ontap_endpoints` (available when the API catalog is loaded) diff --git a/server/server.go b/server/server.go index b5026ad..ece8e23 100644 --- a/server/server.go +++ b/server/server.go @@ -37,6 +37,7 @@ type Options struct { Port int ReadOnly bool Stateless bool + JSONResponse bool TestHTTPClient *http.Client // Optional HTTP client for testing } @@ -82,6 +83,9 @@ func (a *App) StartServer() { if a.options.Stateless { a.logger.Info("MCP server is running in stateless mode; mcp-session-id header validation is disabled") } + if a.options.JSONResponse { + a.logger.Info("MCP server is responding with application/json instead of text/event-stream") + } server := a.createMCPServer() a.runHTTPServer(server) } @@ -243,7 +247,7 @@ func (a *App) runHTTPServer(server *mcp.Server) { handler = mcp.NewStreamableHTTPHandler(func(*http.Request) *mcp.Server { return server - }, &mcp.StreamableHTTPOptions{Stateless: a.options.Stateless}) + }, &mcp.StreamableHTTPOptions{Stateless: a.options.Stateless, JSONResponse: a.options.JSONResponse}) if a.options.InspectTraffic { prevHandler := handler