UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

65 lines • 2.57 kB
import { listMcpTools } from "./tool-client.js"; import { isModernMcpClient } from "./modern/request.js"; import { hasSupportedModernToolSchemas } from "./modern/tool-schema.js"; import { collectAllPages } from "./expose/pagination.js"; export async function collectToolCatalog(server, connection, config, options = {}) { const client = connection.client; const result = await collectAllPages((cursor) => listMcpTools(client, cursor === undefined ? {} : { cursor }, { timeout: config.requestTimeoutMs })); return result.items.map((tool) => ({ requestOrigin: options.requestOrigin, annotations: tool.annotations, agentDir: options.agentDir, artifacts: options.artifacts, connection, description: tool.description, ensureFresh: options.ensureFresh, invocation: options.invocation, outputGuard: options.outputGuard, requestTimeoutMs: config.requestTimeoutMs, schema: tool.inputSchema, outputSchema: tool.outputSchema, modern: isModernMcpClient(client), server, tool: tool.name, })); } /** What registering these tools with this catalog's resources and prompts exposes; * equal identities register identical definitions. */ export function mcpRegistrationIdentity(tools, catalog) { return JSON.stringify([ tools.map((entry) => [ entry.tool, entry.description, entry.schema, entry.outputSchema, entry.modern, entry.annotations, ]), catalog?.resources ?? [], catalog?.prompts ?? [], ]); } export function cachedToolsToCatalogEntries(server, catalog, connection, requestTimeoutMs, ensureConnected, options = {}) { const modern = connection.state === "connected" ? isModernMcpClient(connection.client) || undefined : catalog.modern; return catalog.tools .filter((tool) => !modern || hasSupportedModernToolSchemas(tool)) .map((tool) => ({ requestOrigin: options.requestOrigin, annotations: tool.annotations, agentDir: options.agentDir, artifacts: options.artifacts, connection, description: tool.description, ensureConnected, ensureFresh: options.ensureFresh, invocation: options.invocation, outputGuard: options.outputGuard, requestTimeoutMs, schema: tool.inputSchema, outputSchema: tool.outputSchema, modern, server, tool: tool.name, })); } //# sourceMappingURL=catalog.js.map