Skip to content

Commit

Permalink
Convenience methods for Server
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Nov 4, 2024
1 parent 3d32ce6 commit a9b6ae6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import {
ListToolsRequestSchema,
ListPromptsRequestSchema,
SetLevelRequestSchema,
CreateMessageRequest,
CreateMessageResultSchema,
EmptyResultSchema,
LoggingMessageNotification,
ResourceUpdatedNotification,
} from "../types.js";

/**
Expand Down Expand Up @@ -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" });
}
}

0 comments on commit a9b6ae6

Please sign in to comment.