llms-txt-generator
Version:
A powerful CLI tool and MCP server for generating standardized llms.txt and llms-full.txt documentation files to help AI models better understand project structures
86 lines • 2.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MCPClient = void 0;
// src/client.js;
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
const servers_1 = __importDefault(require("./config/servers"));
class MCPClient {
constructor() {
this.clients = {};
this.toolNameMap = {};
for (const [name, server] of Object.entries(servers_1.default)) {
this.clients[name] = createClient(name, server);
}
}
async listTools(toolsType) {
const tools = [];
for await (const [name, client] of Object.entries(this.clients)) {
const _client = await client;
const _tools = (await _client.listTools()).tools.map((tool) => {
this.toolNameMap[tool.name] = _client;
if (toolsType === 'function_call') {
const ret = {
type: "function",
function: {
name: tool.name,
description: tool.description,
parameters: tool.inputSchema,
}
};
return ret;
}
else {
return tool;
}
});
tools.push(..._tools);
}
return tools;
}
async callTool(tool_name, tool_args) {
const tool = await this.toolNameMap[tool_name];
if (!tool) {
console.warn(`Tool ${tool_name} not found`);
return {
role: 'tool',
name: tool_name,
content: "Tool not found",
};
}
const result = await (tool).callTool({
name: tool_name,
arguments: tool_args
});
return {
role: 'tool',
name: tool_name,
content: result.content[0].text,
};
}
}
exports.MCPClient = MCPClient;
async function createClient(name, server) {
const client = new index_js_1.Client({
name,
version: "1.0.0",
});
const transport = new stdio_js_1.StdioClientTransport({
command: server.command,
args: server.args,
});
try {
await client.connect(transport);
console.log(`Client ${name} connected successfully`);
}
catch (err) {
console.error("Client connection failed:", err);
throw err;
}
// 可选:添加客户端方法调用后的调试
return client;
}
//# sourceMappingURL=client.js.map