You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit dfdd4ef
Browse filesBrowse the repository at this point in the historyBrowse files
Resolves conflicts in lib/mcp/server/transports/streamable_http_transport.rb
between the DNS rebinding protection merged upstream (allowed_origins,
allowed_hosts, dns_rebinding_protection keywords) and this branch's session
retention hardening (session_idle_timeout default and max_sessions keyword)
by combining both sets of keyword arguments and constructor logic.
Copy file name to clipboardExpand all lines: README.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,6 +102,8 @@ transport = MCP::Server::Transports::StdioTransport.new(server)
102
102
transport.open
103
103
```
104
104
105
+
`StdioTransport.new` accepts an optional `max_line_bytes:` keyword that caps the byte length of a single newline-delimited request frame. A frame that reaches this limit without a newline is rejected and the connection is closed, preventing unbounded memory growth from a peer that never emits a newline. It defaults to `4 * 1024 * 1024` (4 MiB).
106
+
105
107
You can run this script and then type in requests to the server at the command line.
106
108
107
109
```console
@@ -128,6 +130,27 @@ The following examples show two common integration styles in Rails.
128
130
>
129
131
> Stateless mode (`stateless: true`) does not use sessions and works with any server configuration.
130
132
133
+
> [!IMPORTANT]
134
+
> Per MCP 2025-11-25, `StreamableHTTPTransport` validates the `Host` and `Origin` headers by default to
135
+
> prevent DNS rebinding attacks against locally bound servers, rejecting unauthorized values with HTTP 403.
136
+
> `Host` is allowed for the loopback defaults (`127.0.0.1`, `::1`, `localhost`), and an `Origin` header,
137
+
> when present, must be same-origin or explicitly allow-listed. Non-browser clients that send no `Origin`
138
+
> header are unaffected.
139
+
>
140
+
> Deployments behind a reverse proxy or bound to a non-loopback interface must widen the allow lists:
141
+
>
142
+
> ```ruby
143
+
> transport =MCP::Server::Transports::StreamableHTTPTransport.new(
144
+
> server,
145
+
>allowed_hosts: ["mcp.example.com"],
146
+
>allowed_origins: ["https://app.example.com"],
147
+
> )
148
+
>```
149
+
>
150
+
> An `allowed_hosts:` entry matches either the bare host name (any port) or the full `host:port` value,
151
+
> so both `"mcp.example.com"` and `"mcp.example.com:8443"` work. Pass `dns_rebinding_protection:false`
152
+
> to disable the check entirely (e.g., when an upstream proxy or middleware already validates `Host`/`Origin`).
153
+
131
154
##### Rails (mount)
132
155
133
156
`StreamableHTTPTransport` is a Rack app that can be mounted directly in Rails routes:
@@ -1967,6 +1990,7 @@ Use the `MCP::Client::Stdio` transport to interact with MCP servers running as s
1967
1990
|`args:`| No | An array of arguments passed to the command. Defaults to `[]`. |
1968
1991
|`env:`| No | A hash of environment variables to set for the server process. Defaults to `nil`. |
1969
1992
|`read_timeout:`| No | Timeout in seconds for waiting for a server response. Defaults to `nil` (no timeout). |
1993
+
|`max_line_bytes:`| No | Maximum byte length of a single newline-delimited response frame. A frame that reaches this limit without a newline is rejected as a transport error, preventing unbounded memory growth from a server that never emits a newline. Defaults to `4 * 1024 * 1024` (4 MiB). |
Copy file name to clipboardExpand all lines: docs/building-clients.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,7 @@ stdio_transport.close
65
65
|`args:`| No | An array of arguments passed to the command. Defaults to `[]`. |
66
66
|`env:`| No | A hash of environment variables for the server process. Defaults to `nil`. |
67
67
|`read_timeout:`| No | Timeout in seconds for waiting for a server response. Defaults to `nil`. |
68
+
|`max_line_bytes:`| No | Maximum byte length of a single newline-delimited response frame. A frame that reaches this limit without a newline is rejected as a transport error, preventing unbounded memory growth from a server that never emits a newline. Defaults to `4 * 1024 * 1024` (4 MiB). |
Copy file name to clipboardExpand all lines: docs/building-servers.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,8 @@ transport = MCP::Server::Transports::StdioTransport.new(server)
59
59
transport.open
60
60
```
61
61
62
+
`StdioTransport.new` accepts an optional `max_line_bytes:` keyword that caps the byte length of a single newline-delimited request frame. A frame that reaches this limit without a newline is rejected and the connection is closed, preventing unbounded memory growth from a peer that never emits a newline. It defaults to `4 * 1024 * 1024` (4 MiB).
63
+
62
64
## Streamable HTTP Transport
63
65
64
66
`MCP::Server::Transports::StreamableHTTPTransport` is a standard Rack app, so it can be mounted in any Rack-compatible framework.
0 commit comments