clinicaltrialsgov-mcp-server
Version:
ClinicalTrials.gov Model Context Protocol (MCP) Server that provides a suite of tools for interacting with the official ClinicalTrials.gov v2 API. Enables AI agents and LLMs to programmatically search, retrieve, and analyze clinical trial data.
58 lines (57 loc) • 1.93 kB
JavaScript
/**
* @fileoverview Provides a bridge between the MCP SDK's Node.js-style
* streamable HTTP transport and Hono's Web Standards-based streaming response.
* @module src/mcp-server/transports/core/honoNodeBridge
*/
import { PassThrough } from "stream";
/**
* A mock ServerResponse that pipes writes to a PassThrough stream.
* This is the bridge between Model Context Protocol's SDK's Node.js-style response handling
* and Hono's stream-based body. It captures status and headers.
*/
export class HonoStreamResponse extends PassThrough {
constructor() {
super();
this.statusCode = 200;
this.headers = {};
}
writeHead(statusCode, headers) {
this.statusCode = statusCode;
if (headers) {
this.headers = { ...this.headers, ...headers };
}
return this;
}
setHeader(name, value) {
this.headers[name.toLowerCase()] = value;
return this;
}
getHeader(name) {
return this.headers[name.toLowerCase()];
}
getHeaders() {
return this.headers;
}
removeHeader(name) {
delete this.headers[name.toLowerCase()];
}
write(chunk, encodingOrCallback, callback) {
const encoding = typeof encodingOrCallback === "string" ? encodingOrCallback : undefined;
const cb = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
if (encoding) {
return super.write(chunk, encoding, cb);
}
return super.write(chunk, cb);
}
end(chunk, encodingOrCallback, callback) {
const encoding = typeof encodingOrCallback === "string" ? encodingOrCallback : undefined;
const cb = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
if (encoding) {
super.end(chunk, encoding, cb);
}
else {
super.end(chunk, cb);
}
return this;
}
}