UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

75 lines • 4.08 kB
import type { ToolRegistry } from '../tool-registry.js'; import type { McpLogger, McpServerConfig } from './options.js'; /** One tool this importer currently has in the registry, and the server it came from. */ export interface McpRegisteredTool { /** The name in the shared registry — the server's name after namespacing and sanitizing. */ name: string; serverName: string; /** The name on the server, which namespacing and sanitizing may have changed. */ remoteName: string; /** The description the server supplied, which rides into the tool list of every turn. */ description: string; } /** * Connects to each configured MCP server and registers what it exports into the shared * {@link ToolRegistry} — the same registry `@aiTool` discovery writes to, so an imported tool goes * through every gate a hand-written one does. * * The provider calls {@link start} inside `app.booted()`, AFTER tool discovery has registered the * app's own tools, which is what lets the name-collision check below see them. * * The registry is keyed by name and nothing else, so a name is OWNED by whoever registered it * first: the application, or one named server. A second claimant is refused rather than allowed to * replace a live handler, because the substitution is invisible from everywhere else — the model * goes on calling `deploy`, and `deploy` now reaches somebody else's server. */ export declare class McpToolImporter { private readonly servers; private readonly registry; private readonly logger?; private readonly sources; /** Local tool name → what is registered under it, so ownership survives a {@link refresh}. */ private readonly owners; constructor(servers: McpServerConfig[], registry: ToolRegistry, logger?: McpLogger | undefined); /** Open each configured server and import from all of them. */ start(): Promise<number>; close(): Promise<void>; /** * Re-import from one server, or from all of them — the way back for a server that was down at * boot, or whose exports have changed since. * * A re-import is the server's CURRENT answer to `tools/list`, so it removes as well as adds: a * tool the server has dropped or renamed is unregistered, because going on offering the model a * tool whose next call fails remotely is worse than not offering it at all. Only names this * importer registered for THAT server are eligible — never the application's own, never another * server's. * * A server that could not be reached prunes nothing. Its tools are unknown, not gone, and a * network blip is not a reason to withdraw a working tool from the model. * * Returns how many tools the servers it re-imported from just claimed, which is not the * registry's total: a name skipped for a collision is not counted, and a scoped refresh says * nothing about what the other servers hold. */ refresh(serverName?: string): Promise<number>; /** Every tool currently imported, and where each came from — what the servers export NOW. */ importedTools(): McpRegisteredTool[]; /** * A server that is unreachable costs its own tools and nothing else: the model is simply never * offered them. Booting the whole application on the availability of a third-party process is the * wrong trade — until a server declares `required: true`, which says the app is not useful * without it and should fail loudly instead. * * `undefined` is a server that could not be reached, as distinct from one that exports no tools: * the first has already been reported here, the second is worth reporting on registration. */ private importFrom; /** * Drop what `serverName` used to export and no longer does. Keyed on ownership rather than on the * name's prefix: `namespace: false` imports under bare names, where a prefix says nothing about * who registered one. */ private prune; private register; } //# sourceMappingURL=importer.d.ts.map