Skip to content

Commit f82ecfb

Browse files
gophergogogophergogo
authored andcommitted
Add SSE/RPC path and external_url params to filter chain factory (#215)
Extend HttpSseFilterChainFactory's constructor with three optional server-side parameters so McpServer can propagate its configured endpoint paths down into the filter chain without the factory having to reach back into McpServerConfig: - sse_path: server-side SSE endpoint (matches McpServerConfig http_sse_path, default "/sse") - rpc_path: server-side JSON-RPC endpoint (default "/mcp") - external_url: absolute URL the server is reachable at from the client's perspective; used to build the endpoint-event callback URL advertised on GET /sse. Empty means derive the URL from the incoming Host header. Defaulted so existing callers (tests, client-mode construction, example apps that only care about http_path/http_host) keep compiling unchanged. The factory does not consume these fields yet — that wiring lands in a follow-up commit once the SSE server transport itself goes in on top of this stack.
1 parent 7d944f1 commit f82ecfb

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

include/mcp/filter/http_sse_filter_chain_factory.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,33 @@ class HttpSseFilterChainFactory : public network::FilterChainFactory {
6666
* @param http_host HTTP Host header value for client mode
6767
* @param use_sse True for SSE mode (GET /sse first), false for Streamable
6868
* HTTP (direct POST)
69+
* @param sse_path Server-side SSE endpoint path (e.g., "/sse"). Only
70+
* meaningful when is_server=true.
71+
* @param rpc_path Server-side JSON-RPC endpoint path (e.g., "/mcp"). Only
72+
* meaningful when is_server=true.
73+
* @param external_url Absolute URL the server is reachable at from the
74+
* client's perspective. Used to build the endpoint-event
75+
* callback URL advertised on GET /sse. Leave empty to
76+
* derive the URL from the incoming Host header.
6977
*/
7078
HttpSseFilterChainFactory(event::Dispatcher& dispatcher,
7179
McpProtocolCallbacks& message_callbacks,
7280
bool is_server = true,
7381
const std::string& http_path = "/rpc",
7482
const std::string& http_host = "localhost",
75-
bool use_sse = true)
83+
bool use_sse = true,
84+
const std::string& sse_path = "/sse",
85+
const std::string& rpc_path = "/mcp",
86+
const std::string& external_url = "")
7687
: dispatcher_(dispatcher),
7788
message_callbacks_(message_callbacks),
7889
is_server_(is_server),
7990
http_path_(http_path),
8091
http_host_(http_host),
81-
use_sse_(use_sse) {}
92+
use_sse_(use_sse),
93+
sse_path_(sse_path),
94+
rpc_path_(rpc_path),
95+
external_url_(external_url) {}
8296

8397
/**
8498
* Create filter chain for the connection
@@ -167,9 +181,12 @@ class HttpSseFilterChainFactory : public network::FilterChainFactory {
167181
event::Dispatcher& dispatcher_;
168182
McpProtocolCallbacks& message_callbacks_;
169183
bool is_server_;
170-
std::string http_path_; // HTTP request path for client mode
171-
std::string http_host_; // HTTP Host header for client mode
172-
bool use_sse_; // True for SSE mode, false for Streamable HTTP
184+
std::string http_path_; // HTTP request path for client mode
185+
std::string http_host_; // HTTP Host header for client mode
186+
bool use_sse_; // True for SSE mode, false for Streamable HTTP
187+
std::string sse_path_; // Server-side SSE endpoint path (e.g., "/sse")
188+
std::string rpc_path_; // Server-side JSON-RPC endpoint path (e.g., "/mcp")
189+
std::string external_url_; // External URL for absolute SSE callback URLs
173190
mutable bool enable_metrics_ = true; // Enable metrics by default
174191

175192
// Store filters for lifetime management

0 commit comments

Comments
 (0)