Convenience methods for Server

This commit is contained in:
Justin Spahr-Summers 2024-11-04 22:15:16 +00:00
commit a9b6ae6679
No known key found for this signature in database

View file

@ -18,6 +18,11 @@ import {
ListToolsRequestSchema,
ListPromptsRequestSchema,
SetLevelRequestSchema,
CreateMessageRequest,
CreateMessageResultSchema,
EmptyResultSchema,
LoggingMessageNotification,
ResourceUpdatedNotification,
} from "../types.js";
/**
@ -133,4 +138,40 @@ export class Server<
: undefined,
};
}
async ping() {
return this.request({ method: "ping" }, EmptyResultSchema);
}
async createMessage(params: CreateMessageRequest["params"]) {
return this.request(
{ method: "sampling/createMessage", params },
CreateMessageResultSchema,
);
}
async sendLoggingMessage(params: LoggingMessageNotification["params"]) {
return this.notification({ method: "notifications/message", params });
}
async sendResourceUpdated(params: ResourceUpdatedNotification["params"]) {
return this.notification({
method: "notifications/resources/updated",
params,
});
}
async sendResourceListChanged() {
return this.notification({
method: "notifications/resources/list_changed",
});
}
async sendToolListChanged() {
return this.notification({ method: "notifications/tools/list_changed" });
}
async sendPromptListChanged() {
return this.notification({ method: "notifications/prompts/list_changed" });
}
}