Skip to content

Commit 135aa18

Browse files
t3dotggclaude
andcommitted
fix(mcp): note shortened snapshot fields in the omission notice
Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent c672c56 commit 135aa18

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎apps/server/src/mcp/McpHttpServer.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ it.effect("bounds the snapshot text even when nothing but logs and the title are
435435
};
436436
expect(parsed.title.length).toBe(2_049);
437437
expect(parsed.consoleEntries[0]?.text.length).toBe(501);
438+
const notice = snapshot.content[1];
439+
const noticeText = notice?.type === "text" ? notice.text : "";
440+
expect(noticeText).toContain("url or title after 2048 characters");
441+
expect(noticeText).toContain("console entries text after 500 characters");
438442
}),
439443
).pipe(Effect.provide(TestLayer)),
440444
);

‎apps/server/src/mcp/McpHttpServer.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ const cutEntryStrings = <A>(entry: A): A =>
130130
) as A)
131131
: entry;
132132

133+
const hasLongString = (entry: unknown, max: number) =>
134+
typeof entry === "object" &&
135+
entry !== null &&
136+
Object.values(entry).some((value) => typeof value === "string" && value.length > max);
137+
133138
type SnapshotMetadata = {
134139
readonly url: string;
135140
readonly title: string;
@@ -162,8 +167,18 @@ const boundSnapshotMetadata = (
162167
if (entries.length > MAX_SNAPSHOT_LOG_ENTRIES) {
163168
omitted.push(`${entries.length - MAX_SNAPSHOT_LOG_ENTRIES} older ${label}`);
164169
}
165-
return entries.slice(-MAX_SNAPSHOT_LOG_ENTRIES).map(cutEntryStrings);
170+
const kept = entries.slice(-MAX_SNAPSHOT_LOG_ENTRIES);
171+
if (kept.some((entry) => hasLongString(entry, MAX_SNAPSHOT_LOG_TEXT_CHARS))) {
172+
omitted.push(`${label} text after ${MAX_SNAPSHOT_LOG_TEXT_CHARS} characters`);
173+
}
174+
return kept.map(cutEntryStrings);
166175
};
176+
if (
177+
metadata.url.length > MAX_SNAPSHOT_IDENTIFIER_CHARS ||
178+
metadata.title.length > MAX_SNAPSHOT_IDENTIFIER_CHARS
179+
) {
180+
omitted.push(`url or title after ${MAX_SNAPSHOT_IDENTIFIER_CHARS} characters`);
181+
}
167182
if (
168183
metadata.interactiveElements.some(
169184
(element) => element.name.length > MAX_SNAPSHOT_ELEMENT_NAME_CHARS,

0 commit comments

Comments
 (0)