Skip to content

Commit 9908919

Browse files
Merge pull request modelcontextprotocol#133 from kalvinnchau/client-instruction-support
feat: add mcp client instruction support
2 parents 28b0ac4 + 93b2440 commit 9908919

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/client/index.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test("should initialize with matching protocol version", async () => {
3636
name: "test",
3737
version: "1.0",
3838
},
39+
instructions: "test instructions",
3940
},
4041
});
4142
}
@@ -66,6 +67,9 @@ test("should initialize with matching protocol version", async () => {
6667
}),
6768
}),
6869
);
70+
71+
// Should have the instructions returned
72+
expect(client.getInstructions()).toEqual("test instructions");
6973
});
7074

7175
test("should initialize with supported older protocol version", async () => {
@@ -111,6 +115,9 @@ test("should initialize with supported older protocol version", async () => {
111115
name: "test",
112116
version: "1.0",
113117
});
118+
119+
// Expect no instructions
120+
expect(client.getInstructions()).toBeUndefined();
114121
});
115122

116123
test("should reject unsupported protocol version", async () => {

src/client/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class Client<
8585
private _serverCapabilities?: ServerCapabilities;
8686
private _serverVersion?: Implementation;
8787
private _capabilities: ClientCapabilities;
88+
private _instructions?: string;
8889

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

156+
this._instructions = result.instructions;
157+
155158
await this.notification({
156159
method: "notifications/initialized",
157160
});
@@ -176,6 +179,13 @@ export class Client<
176179
return this._serverVersion;
177180
}
178181

182+
/**
183+
* After initialization has completed, this may be populated with information about the server's instructions.
184+
*/
185+
getInstructions(): string | undefined {
186+
return this._instructions;
187+
}
188+
179189
protected assertCapabilityForMethod(method: RequestT["method"]): void {
180190
switch (method as ClientRequest["method"]) {
181191
case "logging/setLevel":

src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ export const InitializeResultSchema = ResultSchema.extend({
304304
protocolVersion: z.string(),
305305
capabilities: ServerCapabilitiesSchema,
306306
serverInfo: ImplementationSchema,
307+
/**
308+
* Instructions describing how to use the server and its features.
309+
*
310+
* 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.
311+
*/
312+
instructions: z.optional(z.string()),
307313
});
308314

309315
/**

0 commit comments

Comments
 (0)