MCPcopy
hub / github.com/simstudioai/sim / readToolResponseBody

Function readToolResponseBody

apps/sim/tools/index.ts:782–816  ·  view source on GitHub ↗
(
  response: {
    ok?: boolean
    headers?: { get(name: string): string | null }
    body?: ReadableStream<Uint8Array> | null
    arrayBuffer?: () => Promise<ArrayBuffer>
    text?: () => Promise<string>
  },
  options: {
    requestId: string
    toolId: string
    signal?: AbortSignal
  }
)

Source from the content-addressed store, hash-verified

780}
781
782async function readToolResponseBody(
783 response: {
784 ok?: boolean
785 headers?: { get(name: string): string | null }
786 body?: ReadableStream<Uint8Array> | null
787 arrayBuffer?: () => Promise<ArrayBuffer>
788 text?: () => Promise<string>
789 },
790 options: {
791 requestId: string
792 toolId: string
793 signal?: AbortSignal
794 }
795): Promise<Buffer> {
796 try {
797 return await readResponseToBufferWithLimit(response, {
798 maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES,
799 label: `${options.toolId} response body`,
800 signal: options.signal,
801 allowNoBodyFallback: true,
802 })
803 } catch (error) {
804 if (isPayloadSizeLimitError(error) || response.ok !== false) {
805 throw error
806 }
807
808 logger.warn(
809 `[${options.requestId}] Failed to read non-OK response body for ${options.toolId}`,
810 {
811 error: toError(error).message,
812 }
813 )
814 return Buffer.alloc(0)
815 }
816}
817
818/**
819 * System parameters that should be filtered out when extracting tool arguments

Callers 1

executeToolRequestFunction · 0.85

Calls 4

isPayloadSizeLimitErrorFunction · 0.90
toErrorFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected