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

Function parseMirroredUpstreamJson

client/src/lib/proxyFetch.ts:41–81  ·  view source on GitHub ↗

* Validates the JSON shape the proxy returns when it successfully forwarded * a request and is mirroring the upstream response.

(data: unknown)

Source from the content-addressed store, hash-verified

39 * a request and is mirroring the upstream response.
40 */
41function parseMirroredUpstreamJson(data: unknown): ProxyFetchResponse | null {
42 if (!isJsonObject(data)) {
43 return null;
44 }
45 const rec = data;
46
47 if (typeof rec.status !== "number") {
48 return null;
49 }
50 if (typeof rec.body !== "string") {
51 return null;
52 }
53 if (typeof rec.statusText !== "string") {
54 return null;
55 }
56 if (typeof rec.ok !== "boolean") {
57 return null;
58 }
59 if (rec.headers === null || typeof rec.headers !== "object") {
60 return null;
61 }
62 if (Array.isArray(rec.headers)) {
63 return null;
64 }
65
66 const headers: Record<string, string> = {};
67 for (const [key, val] of Object.entries(rec.headers)) {
68 if (typeof val !== "string") {
69 return null;
70 }
71 headers[key] = val;
72 }
73
74 return {
75 ok: rec.ok,
76 status: rec.status,
77 statusText: rec.statusText,
78 headers,
79 body: rec.body,
80 };
81}
82
83/**
84 * Creates a fetch function that routes requests through the proxy server

Callers 1

createProxyFetchFunction · 0.85

Calls 1

isJsonObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…