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

Function jsonRpcErrorBody

packages/hosts/mcp/src/envelope.ts:130–157  ·  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

128 * local — the four hand-rolled copies are deleted in favor of this.
129 */
130export const jsonRpcErrorBody = (
131 status: number,
132 code: number,
133 message: string,
134 opts?: {
135 readonly cors?: boolean;
136 readonly challenge?: string;
137 readonly retryAfterSeconds?: number;
138 },
139): Response => {
140 const cors = opts?.cors ?? true;
141 const challenge = opts?.challenge;
142 const retryAfterSeconds = opts?.retryAfterSeconds;
143 return new Response(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: null }), {
144 status,
145 headers: {
146 "content-type": "application/json",
147 ...(cors ? { "access-control-allow-origin": "*" } : {}),
148 ...(challenge
149 ? {
150 "www-authenticate": challenge,
151 "access-control-expose-headers": "WWW-Authenticate",
152 }
153 : {}),
154 ...(retryAfterSeconds === undefined ? {} : { "retry-after": String(retryAfterSeconds) }),
155 },
156 });
157};
158
159/** Graceful rollback response that lets auto-negotiating v2 clients try legacy. */
160export const mcpModernDisabledResponse = (opts?: { readonly cors?: boolean }): Response =>

Callers 14

jsonRpcErrorFunction · 0.90
jsonRpcResponseFunction · 0.85
renderAuthErrorFunction · 0.85
deadSessionDoResponseFunction · 0.85
fetchFunction · 0.85
serveModernMcpFunction · 0.85
jsonRpcResponseFunction · 0.85
renderAuthErrorFunction · 0.85
jsonRpcWebResponseFunction · 0.85
jsonRpcResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected