Skip to content

Commit a9033c2

Browse files
t3dotggclaude
andcommitted
refactor(server): advertisedJsonSchema uses Predicate.isObject
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent bb0c2a9 commit a9033c2

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
import * as Predicate from "effect/Predicate";
12
import { Tool } from "effect/ai";
23

34
type Json = unknown;
45
type JsonObject = { [key: string]: Json };
56

6-
const isObject = (value: Json): value is JsonObject =>
7-
typeof value === "object" && value !== null && !Array.isArray(value);
8-
97
const isNullSchema = (value: Json) =>
10-
isObject(value) && value.type === "null" && Object.keys(value).length === 1;
8+
Predicate.isObject(value) && value.type === "null" && Object.keys(value).length === 1;
119

1210
const isBareAnyOf = (value: Json): value is { anyOf: Array<Json> } =>
13-
isObject(value) && Array.isArray(value.anyOf) && Object.keys(value).length === 1;
11+
Predicate.isObject(value) && Array.isArray(value.anyOf) && Object.keys(value).length === 1;
1412

1513
// A `Schema.fromJsonString` fallback. Advertised beside object shapes, it invites stringified input.
1614
const isJsonStringSchema = (value: Json) =>
17-
isObject(value) && value.type === "string" && value.contentMediaType === "application/json";
15+
Predicate.isObject(value) &&
16+
value.type === "string" &&
17+
value.contentMediaType === "application/json";
1818

1919
const SAFE_INTEGER_BOUNDS: Record<string, number> = {
2020
maximum: Number.MAX_SAFE_INTEGER,
@@ -23,14 +23,14 @@ const SAFE_INTEGER_BOUNDS: Record<string, number> = {
2323

2424
const compact = (schema: Json, optional: boolean): Json => {
2525
if (Array.isArray(schema)) return schema.map((item) => compact(item, false));
26-
if (!isObject(schema)) return schema;
26+
if (!Predicate.isObject(schema)) return schema;
2727
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
2828
let result: JsonObject = {};
2929
for (const [key, value] of Object.entries(schema)) {
3030
if (key === "additionalProperties" && value === true) continue;
3131
if (SAFE_INTEGER_BOUNDS[key] === value) continue;
3232
result[key] =
33-
key === "properties" && isObject(value)
33+
key === "properties" && Predicate.isObject(value)
3434
? Object.fromEntries(
3535
Object.entries(value).map(([name, property]) => [
3636
name,
@@ -45,7 +45,7 @@ const compact = (schema: Json, optional: boolean): Json => {
4545
.filter((branch) => !(optional && isNullSchema(branch)) && !isJsonStringSchema(branch));
4646
const { anyOf: _anyOf, ...rest } = result;
4747
const only = branches.length === 1 ? branches[0] : undefined;
48-
result = isObject(only) ? { ...only, ...rest } : { ...rest, anyOf: branches };
48+
result = Predicate.isObject(only) ? { ...only, ...rest } : { ...rest, anyOf: branches };
4949
}
5050
return result;
5151
};

0 commit comments

Comments
 (0)