File size: 1,017 Bytes
3464008
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @ts-expect-error — JS module, no declaration file
import { jsonResponse } from '../_json-response.js';

// ---------------------------------------------------------------------------
// JSON-RPC helpers
// ---------------------------------------------------------------------------
export function withMcpNoStore(extraHeaders: Record<string, string> = {}): Record<string, string> {
  return { ...extraHeaders, 'Cache-Control': 'no-store' };
}

export function rpcOk(id: unknown, result: unknown, extraHeaders: Record<string, string> = {}): Response {
  return jsonResponse({ jsonrpc: '2.0', id: id ?? null, result }, 200, withMcpNoStore(extraHeaders));
}

export function rpcError(
  id: unknown,
  code: number,
  message: string,
  extraHeaders: Record<string, string> = {},
  data?: unknown,
): Response {
  return jsonResponse(
    {
      jsonrpc: '2.0',
      id: id ?? null,
      error: { code, message, ...(data === undefined ? {} : { data }) },
    },
    200,
    withMcpNoStore(extraHeaders),
  );
}