Skip to content

Commit a9b6ae6

Browse files
committed
Convenience methods for Server
1 parent 3d32ce6 commit a9b6ae6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/server/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import {
1818
ListToolsRequestSchema,
1919
ListPromptsRequestSchema,
2020
SetLevelRequestSchema,
21+
CreateMessageRequest,
22+
CreateMessageResultSchema,
23+
EmptyResultSchema,
24+
LoggingMessageNotification,
25+
ResourceUpdatedNotification,
2126
} from "../types.js";
2227

2328
/**
@@ -133,4 +138,40 @@ export class Server<
133138
: undefined,
134139
};
135140
}
141+
142+
async ping() {
143+
return this.request({ method: "ping" }, EmptyResultSchema);
144+
}
145+
146+
async createMessage(params: CreateMessageRequest["params"]) {
147+
return this.request(
148+
{ method: "sampling/createMessage", params },
149+
CreateMessageResultSchema,
150+
);
151+
}
152+
153+
async sendLoggingMessage(params: LoggingMessageNotification["params"]) {
154+
return this.notification({ method: "notifications/message", params });
155+
}
156+
157+
async sendResourceUpdated(params: ResourceUpdatedNotification["params"]) {
158+
return this.notification({
159+
method: "notifications/resources/updated",
160+
params,
161+
});
162+
}
163+
164+
async sendResourceListChanged() {
165+
return this.notification({
166+
method: "notifications/resources/list_changed",
167+
});
168+
}
169+
170+
async sendToolListChanged() {
171+
return this.notification({ method: "notifications/tools/list_changed" });
172+
}
173+
174+
async sendPromptListChanged() {
175+
return this.notification({ method: "notifications/prompts/list_changed" });
176+
}
136177
}

0 commit comments

Comments
 (0)