fix(server): report 2025-era client identity and features in binary_session
binary_session read the client's identity, protocol revision, and capabilities only from the 2026-era per-request envelope. A 2025-era connection sends none, so every such client was reported as `client: null` with no negotiated protocol and no features, although it declared them in `initialize`. When a request carries no envelope, read the values the SDK keeps from the connection's initialize handshake. An envelope still takes precedence. Fixes #1167 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b4927a0a4f
commit
b8312fa8d1
@@ -54,3 +54,91 @@ describe("per-request client capability reporting", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("initialize-scoped client metadata", () => {
|
||||
const statusFor = async (
|
||||
capabilities: Record<string, unknown>,
|
||||
meta?: Record<string, unknown>,
|
||||
) => {
|
||||
const session = createTestBinarySession(createCacheProvider([]));
|
||||
const server = createServer(session, session);
|
||||
const client = new Client(
|
||||
{ name: "initialize-test", version: "2" },
|
||||
{ capabilities },
|
||||
);
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
return (
|
||||
await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: {},
|
||||
...(meta === undefined ? {} : { _meta: meta }),
|
||||
})
|
||||
).structuredContent;
|
||||
} finally {
|
||||
await Promise.allSettled([
|
||||
client.close(),
|
||||
server.close(),
|
||||
session.close(),
|
||||
]);
|
||||
}
|
||||
};
|
||||
const allFeatures = {
|
||||
elicitation: { form: {}, url: {} },
|
||||
roots: {},
|
||||
sampling: {},
|
||||
};
|
||||
|
||||
it("reports a 2025-era client from its initialize handshake", async () => {
|
||||
expect(await statusFor(allFeatures)).toMatchObject({
|
||||
result: {
|
||||
server_identity: {
|
||||
client: { name: "initialize-test", version: "2" },
|
||||
negotiated_protocol_version: expect.any(String),
|
||||
},
|
||||
client_features: {
|
||||
elicitation_form: true,
|
||||
elicitation_url: true,
|
||||
roots: true,
|
||||
sampling: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(await statusFor({})).toMatchObject({
|
||||
result: {
|
||||
client_features: {
|
||||
elicitation_form: false,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers a per-request envelope over initialize values", async () => {
|
||||
expect(
|
||||
await statusFor(allFeatures, {
|
||||
[PROTOCOL_VERSION_META_KEY]: "2026-07-28",
|
||||
[CLIENT_INFO_META_KEY]: { name: "envelope-test", version: "3" },
|
||||
[CLIENT_CAPABILITIES_META_KEY]: {},
|
||||
}),
|
||||
).toMatchObject({
|
||||
result: {
|
||||
server_identity: {
|
||||
client: { name: "envelope-test", version: "3" },
|
||||
negotiated_protocol_version: "2026-07-28",
|
||||
},
|
||||
client_features: {
|
||||
elicitation_form: false,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -262,7 +262,8 @@ const assertLiveIdentity = async (client: Client): Promise<void> => {
|
||||
server: SDK_IDENTITY.server,
|
||||
client_test: PACKAGE_METADATA.clientSdkVersion,
|
||||
},
|
||||
client: null,
|
||||
client: { name: "identity-test", version: "9" },
|
||||
negotiated_protocol_version: expect.any(String),
|
||||
alignment: { state: "unknown" },
|
||||
},
|
||||
},
|
||||
@@ -316,7 +317,7 @@ const assertSessionIdentity = async (client: Client): Promise<void> => {
|
||||
}),
|
||||
]),
|
||||
client_features: {
|
||||
elicitation_form: false,
|
||||
elicitation_form: true,
|
||||
elicitation_url: false,
|
||||
roots: false,
|
||||
sampling: false,
|
||||
|
||||
Reference in New Issue
Block a user