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

Function jsonRpcErrorBody

packages/hosts/mcp/src/envelope.ts:103–140  ·  view source on GitHub ↗
(
  status: number,
  code: number,
  message: string,
  opts?: {
    readonly cors?: boolean;
    readonly challenge?: string;
    readonly retryAfterSeconds?: number;
    /**
     * The id to echo. Envelope-level errors have no request to answer and stay
     * at the default `null`; only an error that answers ONE identified JSON-RPC
     * request (the pre-initialize guard below) sets it, since a client matches
     * the response to its pending request by id.
     */
    readonly id?: string | number | null;
  },
)

Source from the content-addressed store, hash-verified

101 * local — the four hand-rolled copies are deleted in favor of this.
102 */
103export const jsonRpcErrorBody = (
104 status: number,
105 code: number,
106 message: string,
107 opts?: {
108 readonly cors?: boolean;
109 readonly challenge?: string;
110 readonly retryAfterSeconds?: number;
111 /**
112 * The id to echo. Envelope-level errors have no request to answer and stay
113 * at the default `null`; only an error that answers ONE identified JSON-RPC
114 * request (the pre-initialize guard below) sets it, since a client matches
115 * the response to its pending request by id.
116 */
117 readonly id?: string | number | null;
118 },
119): Response => {
120 const cors = opts?.cors ?? true;
121 const challenge = opts?.challenge;
122 const retryAfterSeconds = opts?.retryAfterSeconds;
123 return new Response(
124 JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: opts?.id ?? null }),
125 {
126 status,
127 headers: {
128 "content-type": "application/json",
129 ...(cors ? { "access-control-allow-origin": "*" } : {}),
130 ...(challenge
131 ? {
132 "www-authenticate": challenge,
133 "access-control-expose-headers": "WWW-Authenticate",
134 }
135 : {}),
136 ...(retryAfterSeconds === undefined ? {} : { "retry-after": String(retryAfterSeconds) }),
137 },
138 },
139 );
140};
141
142/**
143 * Advertised on transient-auth 503s (`Unavailable` outcomes) so clients back

Callers 12

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

Calls

no outgoing calls

Tested by

no test coverage detected