MCPcopy Index your code
hub / github.com/modelcontextprotocol/inspector / updateValueAtPath

Function updateValueAtPath

client/src/utils/jsonUtils.ts:115–137  ·  view source on GitHub ↗
(
  obj: JsonValue,
  path: string[],
  value: JsonValue,
)

Source from the content-addressed store, hash-verified

113 * @returns A new JSON value with the updated path
114 */
115export function updateValueAtPath(
116 obj: JsonValue,
117 path: string[],
118 value: JsonValue,
119): JsonValue {
120 if (path.length === 0) return value;
121
122 if (obj === null || obj === undefined) {
123 obj = !isNaN(Number(path[0])) ? [] : {};
124 }
125
126 if (Array.isArray(obj)) {
127 return updateArray(obj, path, value);
128 } else if (typeof obj === "object" && obj !== null) {
129 return updateObject(obj as JsonObject, path, value);
130 } else {
131 console.error(
132 `Cannot update path ${path.join(".")} in non-object/array value:`,
133 obj,
134 );
135 return obj;
136 }
137}
138
139/**
140 * Updates an array at a specific path

Callers 4

handleFieldChangeFunction · 0.90
jsonUtils.test.tsFile · 0.90
updateArrayFunction · 0.85
updateObjectFunction · 0.85

Calls 2

updateArrayFunction · 0.85
updateObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…