ServerConnection.fromStreamChannel constructor
ServerConnection.fromStreamChannel(
- StreamChannel<
String> channel, { - Sink<
String> ? protocolLogSink, - RootsSupport? rootsSupport,
- SamplingSupport? samplingSupport,
- @Deprecated('Use elicitationFormSupport instead') ElicitationSupport? elicitationSupport,
- ElicitationFormSupport? elicitationFormSupport,
- ElicitationUrlSupport? elicitationUrlSupport,
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,
@Deprecated('Use elicitationFormSupport instead')
ElicitationSupport? elicitationSupport,
ElicitationFormSupport? elicitationFormSupport,
ElicitationUrlSupport? elicitationUrlSupport,
}) : _elicitationUrlSupport = elicitationUrlSupport {
elicitationFormSupport ??= elicitationSupport;
if (rootsSupport != null) {
registerRequestHandler(
ListRootsRequest.methodName,
rootsSupport.handleListRoots,
);
}
if (samplingSupport != null) {
registerRequestHandler(
CreateMessageRequest.methodName,
(CreateMessageRequest request) =>
samplingSupport.handleCreateMessage(request, serverInfo!),
);
}
if (elicitationFormSupport != null || elicitationUrlSupport != null) {
registerRequestHandler(ElicitRequest.methodName, (ElicitRequest request) {
switch (request.mode) {
case ElicitationMode.form:
if (elicitationFormSupport != null) {
return elicitationFormSupport.handleElicitation(request, this);
} else {
return ElicitResult(action: ElicitationAction.decline);
}
case ElicitationMode.url:
if (elicitationUrlSupport != null) {
return elicitationUrlSupport.handleElicitation(request, this);
} else {
return ElicitResult(action: ElicitationAction.decline);
}
}
});
}
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,
);
registerNotificationHandler(
ElicitationCompleteNotification.methodName,
_elicitationCompleteController.sink.add,
);
}