@civic/hub-bridge
Version:
Stdio <-> HTTP/SSE MCP bridge with Civic auth handling
47 lines • 1.77 kB
JavaScript
import { AbstractHook } from "@civic/hook-common";
import { logger } from "../utils/index.js";
import { localToolHandlers, localTools } from "../tools/index.js";
export class LocalToolsHook extends AbstractHook {
get name() {
return "LocalToolsHook";
}
async processListToolsResult(response,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_originalRequest,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_originalRequestExtra) {
logger.debug(`[${this.name}] Processing tools/list result`);
const allTools = [...response.tools, ...localTools];
logger.debug(`[${this.name}] Returning ${allTools.length} tools (${response.tools.length} from remote server, ${localTools.length} from local tools)`);
// Respond with the list of tools
return {
resultType: "continue",
response: {
...response,
tools: allTools,
},
};
}
/**
* Process a tool call request and forward it to the hosted server
* @param request The incoming tool call request with context
* @param requestExtra The request extra information including requestId
* @returns The result from the hosted server
*/
async processCallToolRequest(request) {
// handle
if (request.params.name in localToolHandlers) {
const handler = localToolHandlers[(request.params.name)];
const response = await handler(request);
return {
resultType: "respond",
response
};
}
return {
resultType: "continue",
request
};
}
}
//# sourceMappingURL=local-tools-hook.js.map