khodkar-cli
Version:
A TypeScript CLI application that extracts business rules and logic from codebases for customer support knowledge bases
78 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.McpManager = void 0;
const ai_1 = require("ai");
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
class McpManager {
mcpClients = new Map(); // Store initialized clients for cleanup
constructor() { }
async initializeServers() {
const fsMcpServer = new stdio_js_1.StdioClientTransport({
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '.'],
});
const fsMcpClient = await (0, ai_1.experimental_createMCPClient)({
transport: fsMcpServer,
onUncaughtError(error) {
console.error('Uncaught error in filesystem MCP server:', error);
},
});
this.mcpClients.set('filesystem', fsMcpClient);
// const memoryMcpServer = new StdioClientTransport({
// command: 'npx',
// args: ['-y', '@modelcontextprotocol/server-memory'],
// });
// const memoryMcpClient = await experimental_createMCPClient({
// transport: memoryMcpServer,
// onUncaughtError(error) {
// console.error('Uncaught error in memory MCP server:', error);
// },
// });
// this.mcpClients.set('memory', memoryMcpClient);
// const thinkingMcpServer = new StdioClientTransport({
// command: 'npx',
// args: ['-y', '@modelcontextprotocol/server-sequential-thinking'],
// });
// const thinkingMcpClient = await experimental_createMCPClient({
// transport: thinkingMcpServer,
// onUncaughtError(error) {
// console.error('Uncaught error in thinking MCP server:', error);
// },
// });
// this.mcpClients.set('thinking', thinkingMcpClient);
}
async getTools() {
const tools = {};
for (const [, client] of this.mcpClients.entries()) {
const clientTools = await client.tools();
for (const [toolName, tool] of Object.entries(clientTools)) {
tools[toolName] = tool;
}
}
return tools;
}
async shutdownServers() {
// Close MCP clients first
for (const client of this.mcpClients.values()) {
try {
await client.close();
}
catch (error) {
console.warn('Error closing MCP client:', error);
}
}
this.mcpClients.clear();
// Then close transports
for (const server of this.mcpClients.values()) {
try {
await server.close();
}
catch (error) {
console.warn('Error closing MCP transport:', error);
}
}
this.mcpClients.clear();
}
}
exports.McpManager = McpManager;
//# sourceMappingURL=manager.js.map