ServerConnection.fromStreamChannel constructor
ServerConnection.fromStreamChannel(
- StreamChannel<
String> channel, { - Sink<
String> ? protocolLogSink, - RootsSupport? rootsSupport,
- SamplingSupport? samplingSupport,
- ElicitationSupport? elicitationSupport,
A 1:1 connection from a client to a server using channel
.
If the client supports "roots", then it should provide an implementation
through rootsSupport
.
If the client supports "sampling", then it should provide an
implementation through samplingSupport
.
Implementation
ServerConnection.fromStreamChannel(
super.channel, {
super.protocolLogSink,
RootsSupport? rootsSupport,
SamplingSupport? samplingSupport,
ElicitationSupport? elicitationSupport,
}) {
if (rootsSupport != null) {
registerRequestHandler(
ListRootsRequest.methodName,
rootsSupport.handleListRoots,
);
}
if (samplingSupport != null) {
registerRequestHandler(
CreateMessageRequest.methodName,
(CreateMessageRequest request) =>
samplingSupport.handleCreateMessage(request, serverInfo!),
);
}
if (elicitationSupport != null) {
registerRequestHandler(ElicitRequest.methodName, (ElicitRequest request) {
return elicitationSupport.handleElicitation(request);
});
}
registerNotificationHandler(
PromptListChangedNotification.methodName,
_promptListChangedController.sink.add,
);
registerNotificationHandler(
ToolListChangedNotification.methodName,
_toolListChangedController.sink.add,
);
registerNotificationHandler(
ResourceListChangedNotification.methodName,
_resourceListChangedController.sink.add,
);
registerNotificationHandler(
ResourceUpdatedNotification.methodName,
_resourceUpdatedController.sink.add,
);
registerNotificationHandler(
LoggingMessageNotification.methodName,
_logController.sink.add,
);
}