From 54472d2ae1cc167427e1b34f6a6f39a50eb7d1b9 Mon Sep 17 00:00:00 2001 From: Kalvin Chau Date: Mon, 13 Jan 2025 09:09:05 -0800 Subject: [PATCH 1/2] feat: add optional instructions field to server _oninitialize --- src/server/index.test.ts | 2 ++ src/server/index.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/server/index.test.ts b/src/server/index.test.ts index 0a23955a..34c2503d 100644 --- a/src/server/index.test.ts +++ b/src/server/index.test.ts @@ -38,6 +38,7 @@ test("should accept latest protocol version", async () => { name: "test server", version: "1.0", }, + instructions: "Test instructions", }); sendPromiseResolve(undefined); } @@ -57,6 +58,7 @@ test("should accept latest protocol version", async () => { tools: {}, logging: {}, }, + instructions: "Test instructions", }, ); diff --git a/src/server/index.ts b/src/server/index.ts index d15ad3c0..ae34d03d 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -33,6 +33,11 @@ export type ServerOptions = ProtocolOptions & { * Capabilities to advertise as being supported by this server. */ capabilities: ServerCapabilities; + + /** + * Optional instructions describing how to use the server and its features. + */ + instructions?: string; }; /** @@ -72,6 +77,7 @@ export class Server< private _clientCapabilities?: ClientCapabilities; private _clientVersion?: Implementation; private _capabilities: ServerCapabilities; + private _instructions?: string; /** * Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification). @@ -87,6 +93,7 @@ export class Server< ) { super(options); this._capabilities = options.capabilities; + this._instructions = options.instructions; this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request), @@ -234,6 +241,7 @@ export class Server< : LATEST_PROTOCOL_VERSION, capabilities: this.getCapabilities(), serverInfo: this._serverInfo, + ...(this.getInstructions() && { instructions: this.getInstructions() }), }; } @@ -255,6 +263,10 @@ export class Server< return this._capabilities; } + private getInstructions(): string | undefined { + return this._instructions; + } + async ping() { return this.request({ method: "ping" }, EmptyResultSchema); } From 1bb51d0fca026c5ff7a1b443dd61614ed8d54dc9 Mon Sep 17 00:00:00 2001 From: Kalvin Chau Date: Mon, 13 Jan 2025 09:50:02 -0800 Subject: [PATCH 2/2] style: remove private getter for getInstructions --- src/server/index.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/server/index.ts b/src/server/index.ts index ae34d03d..0333ad87 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -241,7 +241,7 @@ export class Server< : LATEST_PROTOCOL_VERSION, capabilities: this.getCapabilities(), serverInfo: this._serverInfo, - ...(this.getInstructions() && { instructions: this.getInstructions() }), + ...(this._instructions && { instructions: this._instructions }), }; } @@ -263,10 +263,6 @@ export class Server< return this._capabilities; } - private getInstructions(): string | undefined { - return this._instructions; - } - async ping() { return this.request({ method: "ping" }, EmptyResultSchema); }