Skip to content

Commit 0596240

Browse files
committed
remove casting in type check and protect against deepEqual fail
1 parent 2e9236c commit 0596240

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/ai-core/src/common/language-model.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export namespace ToolRequest {
5555
value &&
5656
typeof value === 'object' &&
5757
'type' in value &&
58-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59-
typeof (value as any).type === 'string' &&
58+
typeof value.type === 'string' &&
6059
Object.keys(value).every(k => typeof k === 'string')
6160
);
6261
}

packages/ai-mcp/src/browser/mcp-frontend-application-contribution.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,19 @@ export class McpFrontendApplicationContribution implements FrontendApplicationCo
9191

9292
for (const [name, description] of updatedServers) {
9393
const oldDescription = oldServers.get(name);
94-
// We know that that the descriptions are actual JSONObjects as we construct them ourselves
95-
if (!oldDescription || !PreferenceProvider.deepEqual(oldDescription as unknown as JSONObject, description as unknown as JSONObject)) {
94+
let diff = false;
95+
try {
96+
// We know that that the descriptions are actual JSONObjects as we construct them ourselves
97+
if (!oldDescription || !PreferenceProvider.deepEqual(oldDescription as unknown as JSONObject, description as unknown as JSONObject)) {
98+
diff = true;
99+
}
100+
} catch (e) {
101+
// In some cases the deepEqual function throws an error, so we fall back to assuming that there is a difference
102+
// This seems to happen in cases where the objects are structured differently, e.g. whole sub-objects are missing
103+
console.debug('Failed to compare MCP server descriptions, assuming a difference', e);
104+
diff = true;
105+
}
106+
if (diff) {
96107
this.manager.addOrUpdateServer(description);
97108
}
98109
}

0 commit comments

Comments
 (0)