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

Function req

test/server/streamableHttp.test.ts:3123–3136  ·  view source on GitHub ↗

Shorthand to build a Web Standard Request for direct transport testing.

(method: string, opts?: { body?: unknown; headers?: Record<string, string> })

Source from the content-addressed store, hash-verified

3121
3122 /** Shorthand to build a Web Standard Request for direct transport testing. */
3123 function req(method: string, opts?: { body?: unknown; headers?: Record<string, string> }): Request {
3124 const headers: Record<string, string> = { ...opts?.headers };
3125 if (method === 'POST') {
3126 headers['Accept'] ??= 'application/json, text/event-stream';
3127 headers['Content-Type'] ??= 'application/json';
3128 } else if (method === 'GET') {
3129 headers['Accept'] ??= 'text/event-stream';
3130 }
3131 return new Request('http://localhost/mcp', {
3132 method,
3133 headers,
3134 body: opts?.body !== undefined ? (typeof opts.body === 'string' ? opts.body : JSON.stringify(opts.body)) : undefined
3135 });
3136 }
3137
3138 function withSession(sessionId: string, extra?: Record<string, string>): Record<string, string> {
3139 return { 'mcp-session-id': sessionId, 'mcp-protocol-version': '2025-11-25', ...extra };

Callers 2

initializeServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected