Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test("should initialize with matching protocol version", async () => {
name: "test",
version: "1.0",
},
instructions: "test instructions",
},
});
}
Expand Down Expand Up @@ -66,6 +67,9 @@ test("should initialize with matching protocol version", async () => {
}),
}),
);

// Should have the instructions returned
expect(client.getInstructions()).toEqual("test instructions");
});

test("should initialize with supported older protocol version", async () => {
Expand Down Expand Up @@ -111,6 +115,9 @@ test("should initialize with supported older protocol version", async () => {
name: "test",
version: "1.0",
});

// Expect no instructions
expect(client.getInstructions()).toBeUndefined();
});

test("should reject unsupported protocol version", async () => {
Expand Down
10 changes: 10 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class Client<
private _serverCapabilities?: ServerCapabilities;
private _serverVersion?: Implementation;
private _capabilities: ClientCapabilities;
private _instructions?: string;

/**
* Initializes this client with the given name and version information.
Expand Down Expand Up @@ -152,6 +153,8 @@ export class Client<
this._serverCapabilities = result.capabilities;
this._serverVersion = result.serverInfo;

this._instructions = result.instructions;

await this.notification({
method: "notifications/initialized",
});
Expand All @@ -176,6 +179,13 @@ export class Client<
return this._serverVersion;
}

/**
* After initialization has completed, this may be populated with information about the server's instructions.
*/
getInstructions(): string | undefined {
return this._instructions;
}

protected assertCapabilityForMethod(method: RequestT["method"]): void {
switch (method as ClientRequest["method"]) {
case "logging/setLevel":
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ export const InitializeResultSchema = ResultSchema.extend({
protocolVersion: z.string(),
capabilities: ServerCapabilitiesSchema,
serverInfo: ImplementationSchema,
/**
* Instructions describing how to use the server and its features.
*
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
*/
instructions: z.optional(z.string()),
});

/**
Expand Down
Loading