MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / jsonRpcErrorBody

Function jsonRpcErrorBody

packages/hosts/mcp/src/envelope.ts:102–129  ·  view source on GitHub ↗
(
  status: number,
  code: number,
  message: string,
  opts?: {
    readonly cors?: boolean;
    readonly challenge?: string;
    readonly retryAfterSeconds?: number;
  },
)

Source from the content-addressed store, hash-verified

100 * local — the four hand-rolled copies are deleted in favor of this.
101 */
102export const jsonRpcErrorBody = (
103 status: number,
104 code: number,
105 message: string,
106 opts?: {
107 readonly cors?: boolean;
108 readonly challenge?: string;
109 readonly retryAfterSeconds?: number;
110 },
111): Response => {
112 const cors = opts?.cors ?? true;
113 const challenge = opts?.challenge;
114 const retryAfterSeconds = opts?.retryAfterSeconds;
115 return new Response(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: null }), {
116 status,
117 headers: {
118 "content-type": "application/json",
119 ...(cors ? { "access-control-allow-origin": "*" } : {}),
120 ...(challenge
121 ? {
122 "www-authenticate": challenge,
123 "access-control-expose-headers": "WWW-Authenticate",
124 }
125 : {}),
126 ...(retryAfterSeconds === undefined ? {} : { "retry-after": String(retryAfterSeconds) }),
127 },
128 });
129};
130
131/**
132 * Advertised on transient-auth 503s (`Unavailable` outcomes) so clients back

Callers 9

jsonRpcErrorFunction · 0.90
jsonRpcResponseFunction · 0.85
renderAuthErrorFunction · 0.85
jsonRpcResponseFunction · 0.85
renderAuthErrorFunction · 0.85
jsonRpcWebResponseFunction · 0.85
jsonRpcResponseFunction · 0.85
jsonErrorFunction · 0.85
selfHostHttpMiddlewareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected