Auto-set server.transport in Transport#initialize

## Motivation and Context

Transport subclasses (StreamableHTTPTransport, StdioTransport) already
receive the server in their constructor, but users must manually call
`server.transport = transport` after creating a transport instance.
This is boilerplate that can be eliminated by setting the connection
automatically in `Transport#initialize`.

## How Has This Been Tested?

All existing tests pass. Redundant `server.transport = transport` lines
were removed from tests, examples, README.md, and conformance server.

## Breaking Changes

None. Existing code that manually sets `server.transport = transport`
continues to work (idempotent assignment).
This commit is contained in:
Koichi ITO 2026-04-08 22:25:50 +09:00
commit de38804ed7

View file

@ -394,7 +394,7 @@ module Conformance
def start
server = build_server
transport = build_transport(server)
transport = MCP::Server::Transports::StreamableHTTPTransport.new(server)
configure_handlers(server)
rack_app = build_rack_app(transport)
@ -480,12 +480,6 @@ module Conformance
]
end
def build_transport(server)
transport = MCP::Server::Transports::StreamableHTTPTransport.new(server)
server.transport = transport
transport
end
def configure_handlers(server)
server.logging_message_notification = MCP::LoggingMessageNotification.new(level: "debug")
server.server_context = server