Interface McpTransportCustomizer
StreamableHttpMcpTransport and WebSocketMcpTransport of an
application, whoever creates it, for example to route its traffic through a proxy. Other transports, such as the
stdio one, do not call it. It is an internal SPI: it can change or be removed in any release.
Implementations are discovered with the ServiceLoader: list them in a file in META-INF/services
named after the fully qualified name of this interface. They are looked up each time such a transport is created,
with its builder's build() or with its constructor, in the thread context class loader in use at that
time, or in the class loader of LangChain4j if that finds none. Each lookup creates new instances, so an
implementation needs a public no-argument constructor. Each method does nothing by default, so an implementation
only overrides the ones for the transports it cares about.
A customizer works on a copy of the builder: its changes apply only to the transport being created, never to the
builder that the application holds. Building from the same builder again starts from the application's settings.
The copy is shallow: an object set on the builder, such as an HTTP client builder, is shared with the application,
and a timeout set by a customizer is applied to that HTTP client builder, as a timeout set by the application is.
Customizers are called one after the other, highest priority first.
A customizer that does not implement PrioritizedFactory has PrioritizedFactory.DEFAULT_PRIORITY,
and customizers with the same priority are called in no fixed order. A customizer sees the changes made by the
customizers called before it, and the last one to change a setting decides its value.
An exception thrown by a customizer fails the creation of the transport.
A customizer can see and change where each of these transports connects to, and the transport then sends its requests, including their headers (for example an API key), there. Only put customizers you trust on the classpath.
- Since:
- 1.25.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled before aStreamableHttpMcpTransportis created.default voidcustomize(WebSocketMcpTransport.Builder builder) Called before aWebSocketMcpTransportis created.
-
Method Details
-
customize
Called before aStreamableHttpMcpTransportis created. The customizer can read the URL configured so far withStreamableHttpMcpTransport.Builder.getUrl(), which isnullif none was set, and the name of the transport withStreamableHttpMcpTransport.Builder.getName(), and change any setting through the builder.- Parameters:
builder- a copy of the builder of the transport being created
-
customize
Called before aWebSocketMcpTransportis created. The customizer can read the URL configured so far withWebSocketMcpTransport.Builder.getUrl(), which isnullif none was set, and the name of the transport withWebSocketMcpTransport.Builder.getName(), and change any setting through the builder.- Parameters:
builder- a copy of the builder of the transport being created
-