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

Function jsonRpcErrorBody

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

84 * local — the four hand-rolled copies are deleted in favor of this.
85 */
86export const jsonRpcErrorBody = (
87 status: number,
88 code: number,
89 message: string,
90 opts?: {
91 readonly cors?: boolean;
92 readonly challenge?: string;
93 readonly retryAfterSeconds?: number;
94 },
95): Response => {
96 const cors = opts?.cors ?? true;
97 const challenge = opts?.challenge;
98 const retryAfterSeconds = opts?.retryAfterSeconds;
99 return new Response(JSON.stringify({ jsonrpc: "2.0", error: { code, message }, id: null }), {
100 status,
101 headers: {
102 "content-type": "application/json",
103 ...(cors ? { "access-control-allow-origin": "*" } : {}),
104 ...(challenge
105 ? {
106 "www-authenticate": challenge,
107 "access-control-expose-headers": "WWW-Authenticate",
108 }
109 : {}),
110 ...(retryAfterSeconds === undefined ? {} : { "retry-after": String(retryAfterSeconds) }),
111 },
112 });
113};
114
115/**
116 * Advertised on transient-auth 503s (`Unavailable` outcomes) so clients back

Callers 8

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

Calls

no outgoing calls

Tested by

no test coverage detected