Merge pull request #1179 from morluto/fix/session-client-metadata-2025
fix(server): report 2025-era client identity and features in binary_session
This commit is contained in:
@@ -2,25 +2,45 @@ import {
|
||||
CLIENT_CAPABILITIES_META_KEY,
|
||||
CLIENT_INFO_META_KEY,
|
||||
PROTOCOL_VERSION_META_KEY,
|
||||
type McpServer,
|
||||
type ServerContext,
|
||||
} from "@modelcontextprotocol/server";
|
||||
|
||||
import type { ClientFeatureAvailability } from "../contracts/toolOutputSchemaPrimitives.js";
|
||||
import type { ConnectedClientIdentity } from "../serverIdentity.js";
|
||||
|
||||
/** Client metadata bound to the current SDK request rather than server-global state. */
|
||||
export const mcpClientMetadata = (context: {
|
||||
readonly mcpReq: Pick<ServerContext["mcpReq"], "envelope">;
|
||||
}) => {
|
||||
/** Initialize-scoped client metadata the SDK keeps for a 2025-era connection. */
|
||||
export type McpConnectionClientMetadata = Pick<
|
||||
McpServer["server"],
|
||||
"getClientCapabilities" | "getClientVersion" | "getNegotiatedProtocolVersion"
|
||||
>;
|
||||
|
||||
/**
|
||||
* Client metadata for the current request. A 2026-era request carries it in
|
||||
* its per-request envelope; a 2025-era connection sends no envelope, so its
|
||||
* `initialize` handshake supplies the values.
|
||||
*/
|
||||
export const mcpClientMetadata = (
|
||||
context: { readonly mcpReq: Pick<ServerContext["mcpReq"], "envelope"> },
|
||||
connection: McpConnectionClientMetadata,
|
||||
) => {
|
||||
const envelope = context.mcpReq.envelope;
|
||||
// The SDK deprecates these accessors only in favor of the envelope, which
|
||||
// 2025-era requests do not carry; they still return initialize values.
|
||||
const value = (key: string, initialized: () => unknown): unknown =>
|
||||
envelope === undefined ? initialized() : mcpEnvelopeValue(envelope, key);
|
||||
const client = implementation(
|
||||
mcpEnvelopeValue(envelope, CLIENT_INFO_META_KEY),
|
||||
value(CLIENT_INFO_META_KEY, () => connection.getClientVersion()),
|
||||
);
|
||||
const protocolVersion = value(PROTOCOL_VERSION_META_KEY, () =>
|
||||
connection.getNegotiatedProtocolVersion(),
|
||||
);
|
||||
const protocolVersion = mcpEnvelopeValue(envelope, PROTOCOL_VERSION_META_KEY);
|
||||
return {
|
||||
...(client === undefined ? {} : { client }),
|
||||
clientFeatures: capabilityFeatures(
|
||||
mcpEnvelopeValue(envelope, CLIENT_CAPABILITIES_META_KEY),
|
||||
value(CLIENT_CAPABILITIES_META_KEY, () =>
|
||||
connection.getClientCapabilities(),
|
||||
),
|
||||
),
|
||||
...(typeof protocolVersion === "string" ? { protocolVersion } : {}),
|
||||
};
|
||||
|
||||
@@ -44,8 +44,10 @@ export const registerSessionStatusTool = (
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async (input, context) => {
|
||||
const { client, clientFeatures, protocolVersion } =
|
||||
mcpClientMetadata(context);
|
||||
const { client, clientFeatures, protocolVersion } = mcpClientMetadata(
|
||||
context,
|
||||
server.server,
|
||||
);
|
||||
let androidAvailability: ProviderAvailability;
|
||||
try {
|
||||
androidAvailability = await androidAnalysisAvailability(
|
||||
|
||||
Reference in New Issue
Block a user