Skip to content

Commit 030d9a3

Browse files
committed
test(mcp): cover M.6 guard false path for ToolAnnotations
1 parent 558cdf7 commit 030d9a3

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/application/mcp-tool-annotations.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { describe, expect, it } from "bun:test";
33
import { MCP_TOOL_NAMES } from "./mcp-tool-allowlist";
44
import {
55
MCP_TOOL_ANNOTATIONS,
6+
_setSdkSupportsMcpToolAnnotationsForTests,
67
buildHttpToolCatalogEntry,
78
getMcpToolAnnotations,
89
sdkSupportsMcpToolAnnotations,
10+
withToolAnnotations,
911
} from "./mcp-tool-annotations";
1012

1113
describe("mcp-tool-annotations", () => {
@@ -46,6 +48,21 @@ describe("mcp-tool-annotations", () => {
4648
expect(sdkSupportsMcpToolAnnotations()).toBe(true);
4749
});
4850

51+
it("omits MCP annotations when M.6 guard is false", () => {
52+
_setSdkSupportsMcpToolAnnotationsForTests(false);
53+
try {
54+
expect(getMcpToolAnnotations("apply")).toBeUndefined();
55+
expect(
56+
withToolAnnotations("apply", {
57+
description: "test",
58+
inputSchema: {},
59+
}),
60+
).toEqual({ description: "test", inputSchema: {} });
61+
} finally {
62+
_setSdkSupportsMcpToolAnnotationsForTests(undefined);
63+
}
64+
});
65+
4966
it("index user-data mutators are not destructive", () => {
5067
for (const name of [
5168
"save_baseline",

src/application/mcp-tool-annotations.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@ import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
88

99
import type { McpToolName } from "./mcp-tool-allowlist";
1010

11+
let sdkSupportOverrideForTests: boolean | undefined;
12+
13+
/** Test hook — restore with `undefined` in `afterEach`. */
14+
export function _setSdkSupportsMcpToolAnnotationsForTests(
15+
value: boolean | undefined,
16+
): void {
17+
sdkSupportOverrideForTests = value;
18+
}
19+
1120
/** M.6 — skip MCP annotations when an older SDK lacks ToolAnnotations on registerTool. */
1221
export function sdkSupportsMcpToolAnnotations(): boolean {
22+
if (sdkSupportOverrideForTests !== undefined) {
23+
return sdkSupportOverrideForTests;
24+
}
1325
const shape = ToolAnnotationsSchema?.shape;
1426
return (
1527
typeof shape === "object" &&
@@ -101,7 +113,7 @@ export function buildHttpToolCatalogEntry(name: McpToolName): {
101113
return { name, ...MCP_TOOL_ANNOTATIONS[name] };
102114
}
103115

104-
export interface ToolRegisterConfig {
116+
interface ToolRegisterConfig {
105117
description: string;
106118
inputSchema: unknown;
107119
}

0 commit comments

Comments
 (0)