Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions include/mcp/filter/http_sse_filter_chain_factory.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#include <functional>
Expand All @@ -18,6 +18,7 @@
namespace filter {
class HttpRoutingFilter;
class MetricsFilter;
class SseSessionRegistry;
} // namespace filter
} // namespace mcp

Expand Down Expand Up @@ -66,19 +67,28 @@
* @param http_host HTTP Host header value for client mode
* @param use_sse True for SSE mode (GET /sse first), false for Streamable
* HTTP (direct POST)
* @param sse_path Server-side SSE endpoint path (e.g., "/sse"). Only
* meaningful when is_server=true.
* @param rpc_path Server-side JSON-RPC endpoint path (e.g., "/mcp"). Only
* meaningful when is_server=true.
* @param 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. Leave empty to
* derive the URL from the incoming Host header.
*/
HttpSseFilterChainFactory(event::Dispatcher& dispatcher,
McpProtocolCallbacks& message_callbacks,
bool is_server = true,
const std::string& http_path = "/rpc",
const std::string& http_host = "localhost",
bool use_sse = true)
: dispatcher_(dispatcher),
message_callbacks_(message_callbacks),
is_server_(is_server),
http_path_(http_path),
http_host_(http_host),
use_sse_(use_sse) {}
bool use_sse = true,
const std::string& sse_path = "/sse",
const std::string& rpc_path = "/mcp",
const std::string& external_url = "");

// Destructor defined out-of-line so the unique_ptr<SseSessionRegistry>
// member can use the incomplete forward-declared type in this header.
~HttpSseFilterChainFactory();

/**
* Create filter chain for the connection
Expand Down Expand Up @@ -167,11 +177,24 @@
event::Dispatcher& dispatcher_;
McpProtocolCallbacks& message_callbacks_;
bool is_server_;
std::string http_path_; // HTTP request path for client mode
std::string http_host_; // HTTP Host header for client mode
bool use_sse_; // True for SSE mode, false for Streamable HTTP
std::string http_path_; // HTTP request path for client mode
std::string http_host_; // HTTP Host header for client mode
bool use_sse_; // True for SSE mode, false for Streamable HTTP
std::string sse_path_; // Server-side SSE endpoint path (e.g., "/sse")
std::string rpc_path_; // Server-side JSON-RPC endpoint path (e.g., "/mcp")
std::string external_url_; // External URL for absolute SSE callback URLs
mutable bool enable_metrics_ = true; // Enable metrics by default

// SSE session registry — maps session IDs to the connections that are
// streaming SSE to each client, so POST /callback/{id} handlers can
// route a JSON-RPC response back through the correct stream. Lazily
// constructed on the first server-side filter chain creation; stays
// null for client-mode factories. Owned here (not a global singleton)
// so each McpServer instance has an isolated registry and lifetime is
// bounded by the factory, not process lifetime. Mutable because
// createFilterChain is const on the base class.
mutable std::unique_ptr<SseSessionRegistry> sse_registry_;

// Store filters for lifetime management
mutable std::vector<network::FilterSharedPtr> filters_;

Expand Down
9 changes: 8 additions & 1 deletion include/mcp/server/mcp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,15 @@ struct McpServerConfig : public application::ApplicationBase::Config {

// HTTP/SSE specific configuration
std::string http_rpc_path = "/rpc"; // Path for JSON-RPC over HTTP
std::string http_sse_path = "/events"; // Path for SSE event stream
std::string http_sse_path = "/sse"; // Path for SSE event stream
std::string http_health_path = "/health"; // Path for health check endpoint
// Absolute URL the server is reachable at from the client's perspective
// (scheme + host + port + optional path prefix). Used to build the
// endpoint-event callback URL advertised on GET /sse. Leave empty to
// have the server derive a URL from the incoming Host header; set
// explicitly when the server sits behind a reverse proxy that rewrites
// scheme or path so clients don't try to POST back to an internal URL.
std::string external_url;

// Session management
size_t max_sessions = 100;
Expand Down
Loading
Loading