MCPcopy
hub / github.com/ZToolsCenter/ZTools / sendRawJson

Method sendRawJson

src/main/core/mcpServer.ts:183–191  ·  view source on GitHub ↗

* 发送 JSON 响应,并附带 MCP 所需的基础 CORS 头。

(res: ServerResponse, statusCode: number, body: unknown)

Source from the content-addressed store, hash-verified

181 * 发送 JSON 响应,并附带 MCP 所需的基础 CORS 头。
182 */
183 private sendRawJson(res: ServerResponse, statusCode: number, body: unknown): void {
184 res.writeHead(statusCode, {
185 'Content-Type': 'application/json; charset=utf-8',
186 'Access-Control-Allow-Origin': '*',
187 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
188 'Access-Control-Allow-Headers': 'Content-Type, Authorization'
189 })
190 res.end(JSON.stringify(body))
191 }
192
193 /**
194 * 返回空响应,主要用于 OPTIONS 和 JSON-RPC notification。

Callers 3

handleRequestMethod · 0.95
sendMcpResultMethod · 0.95
sendMcpErrorMethod · 0.95

Calls 1

stringifyMethod · 0.80

Tested by

no test coverage detected