MCPcopy Create free account
hub / github.com/MicrosoftDocs/mcp / parseDirectCallResponse

Function parseDirectCallResponse

cli/src/mcp/client.ts:456–480  ·  view source on GitHub ↗
(response: Response)

Source from the content-addressed store, hash-verified

454
455
456async function parseDirectCallResponse(response: Response): Promise<ToolCallResult> {
457 const contentType = response.headers.get('content-type')?.toLowerCase() ?? '';
458 const bodyText = await response.text();
459 const message = contentType.includes('text/event-stream')
460 ? parseSseJsonRpcPayload(bodyText)
461 : parseJsonRpcPayload(bodyText);
462
463 if (!response.ok) {
464 throw new OperationError(readJsonRpcErrorMessage(message, `HTTP ${response.status}`));
465 }
466
467 if (!message || typeof message !== 'object') {
468 throw new OperationError('Direct Learn MCP call returned an unexpected payload.');
469 }
470
471 if ('error' in message && message.error) {
472 throw new OperationError(readJsonRpcErrorMessage(message));
473 }
474
475 if (!('result' in message) || !message.result) {
476 throw new OperationError('Direct Learn MCP call did not include a tool result.');
477 }
478
479 return message.result as ToolCallResult;
480}
481
482function parseSseJsonRpcPayload(bodyText: string): JsonRpcResponsePayload {
483 const events = bodyText

Callers 1

Calls 3

parseSseJsonRpcPayloadFunction · 0.85
parseJsonRpcPayloadFunction · 0.85
readJsonRpcErrorMessageFunction · 0.85

Tested by

no test coverage detected