Skip to content

Commit a9be6ba

Browse files
committed
fix(mcp): avoid conflicting preview schema descriptions
1 parent df78cda commit a9be6ba

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎apps/server/src/mcp/toolkits/preview/tools.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ const schemaHasDescription = (schema: unknown): boolean => {
1212
.some((members) => members.some(schemaHasDescription));
1313
};
1414

15+
const schemaHasMultipleAllOfDescriptions = (schema: unknown): boolean => {
16+
if (!schema || typeof schema !== "object") return false;
17+
const record = schema as Record<string, unknown>;
18+
const allOf = Array.isArray(record.allOf) ? record.allOf : [];
19+
const descriptionCount = allOf.filter(
20+
(member) =>
21+
member !== null &&
22+
typeof member === "object" &&
23+
typeof (member as Record<string, unknown>).description === "string",
24+
).length;
25+
return descriptionCount > 1 || Object.values(record).some(schemaHasMultipleAllOfDescriptions);
26+
};
27+
1528
it("exports provider-compatible object schemas with described parameters", () => {
1629
for (const tool of Object.values(PreviewToolkit.tools)) {
1730
const schema = Tool.getJsonSchema(tool) as {
@@ -27,6 +40,9 @@ it("exports provider-compatible object schemas with described parameters", () =>
2740
expect(schema.type, `${tool.name} must export a top-level object schema`).toBe("object");
2841
expect(schema.anyOf, `${tool.name} must not export a root anyOf`).toBeUndefined();
2942
expect(schema.oneOf, `${tool.name} must not export a root oneOf`).toBeUndefined();
43+
if (tool.name === "preview_navigate") {
44+
expect(schemaHasMultipleAllOfDescriptions(schema)).toBe(false);
45+
}
3046
expect(
3147
schema.properties?.tabId,
3248
`${tool.name} must allow an explicit collaborative browser tab target`,

‎packages/contracts/src/previewAutomation.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ import {
1212
import { ProviderInstanceId } from "./providerInstance.ts";
1313

1414
const BoundedUrl = Schema.String.check(Schema.isTrimmed())
15-
.check(
16-
Schema.isNonEmpty({
17-
description:
18-
"Absolute http(s) URL or a schemeless host such as t3.chat or localhost:5173. Schemeless public hosts use https; loopback hosts use http.",
19-
}),
20-
)
15+
.check(Schema.isNonEmpty())
2116
.check(Schema.isMaxLength(2048));
17+
const URL_GUIDANCE =
18+
"Absolute http(s) URL or a schemeless host such as t3.chat or localhost:5173. Schemeless public hosts use https; loopback hosts use http.";
2219
const OptionalTimeoutMs = Schema.optional(
2320
Schema.Int.check(Schema.isGreaterThan(0))
2421
.check(Schema.isLessThanOrEqualTo(60_000))
@@ -83,8 +80,7 @@ export type PreviewAutomationStatus = typeof PreviewAutomationStatus.Type;
8380
export const PreviewAutomationOpenInput = Schema.Struct({
8481
...PreviewAutomationTabTargetFields,
8582
url: Schema.optional(BoundedUrl).annotate({
86-
description:
87-
"Optional initial page URL, for example https://t3.chat or localhost:5173. Omit to open a blank tab.",
83+
description: `Optional initial page URL. ${URL_GUIDANCE} Omit to open a blank tab.`,
8884
}),
8985
open: Schema.optional(
9086
Schema.Boolean.annotate({
@@ -124,7 +120,7 @@ export const BrowserNavigationTarget = Schema.Union([
124120
description: "Selects direct URL navigation.",
125121
}),
126122
url: BoundedUrl.annotate({
127-
description: "Direct website URL.",
123+
description: `Direct website URL. ${URL_GUIDANCE}`,
128124
}),
129125
}),
130126
Schema.Struct({
@@ -151,8 +147,7 @@ export type BrowserNavigationTarget = typeof BrowserNavigationTarget.Type;
151147
export const PreviewAutomationNavigateInput = Schema.Struct({
152148
...PreviewAutomationTabTargetFields,
153149
url: Schema.optional(BoundedUrl).annotate({
154-
description:
155-
"Website URL, for example https://t3.chat. Use this for public pages and directly reachable URLs.",
150+
description: `Website URL. ${URL_GUIDANCE} Use this for public pages and directly reachable URLs.`,
156151
}),
157152
target: Schema.optional(
158153
BrowserNavigationTarget.annotate({

0 commit comments

Comments
 (0)