MCPcopy
hub / github.com/infinitered/reactotron / mcpRequest

Function mcpRequest

lib/reactotron-mcp/test/mcp-server.test.ts:8–36  ·  view source on GitHub ↗
(
  port: number,
  body: object
)

Source from the content-addressed store, hash-verified

6
7// Helper: make an MCP JSON-RPC request
8function mcpRequest(
9 port: number,
10 body: object
11): Promise<{ status: number; body: string }> {
12 return new Promise((resolve, reject) => {
13 const data = JSON.stringify(body)
14 const req = http.request(
15 {
16 hostname: "localhost",
17 port,
18 path: "/mcp",
19 method: "POST",
20 headers: {
21 "Content-Type": "application/json",
22 Accept: "application/json, text/event-stream",
23 "Content-Length": Buffer.byteLength(data),
24 },
25 },
26 (res) => {
27 let body = ""
28 res.on("data", (chunk) => (body += chunk))
29 res.on("end", () => resolve({ status: res.statusCode!, body }))
30 }
31 )
32 req.on("error", reject)
33 req.write(data)
34 req.end()
35 })
36}
37
38// Helper: parse SSE response to get the JSON-RPC result
39function parseSSE(body: string): any {

Callers 1

mcp-server.test.tsFile · 0.85

Calls 1

onMethod · 0.80

Tested by

no test coverage detected