MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / sendPostRequest

Function sendPostRequest

test/server/streamableHttp.test.ts:99–121  ·  view source on GitHub ↗

* Helper to send JSON-RPC request

(
    baseUrl: URL,
    message: JSONRPCMessage | JSONRPCMessage[],
    sessionId?: string,
    extraHeaders?: Record<string, string>
)

Source from the content-addressed store, hash-verified

97 * Helper to send JSON-RPC request
98 */
99async function sendPostRequest(
100 baseUrl: URL,
101 message: JSONRPCMessage | JSONRPCMessage[],
102 sessionId?: string,
103 extraHeaders?: Record<string, string>
104): Promise<Response> {
105 const headers: Record<string, string> = {
106 'Content-Type': 'application/json',
107 Accept: 'application/json, text/event-stream',
108 ...extraHeaders
109 };
110
111 if (sessionId) {
112 headers['mcp-session-id'] = sessionId;
113 headers['mcp-protocol-version'] = '2025-11-25';
114 }
115
116 return fetch(baseUrl, {
117 method: 'POST',
118 headers,
119 body: JSON.stringify(message)
120 });
121}
122
123function expectErrorResponse(
124 data: unknown,

Callers 2

initializeServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…