From a9b6ae667923a181e5036e4864664a5f2285e649 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 4 Nov 2024 22:15:16 +0000 Subject: [PATCH] Convenience methods for Server --- src/server/index.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/server/index.ts b/src/server/index.ts index 71c22ccd..e4b5e1a5 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -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" }); + } }