UNPKG

@adonis-agora/agent

Version:

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

77 lines • 3.81 kB
import type { ToolHandler } from '../spi/tool.js'; import type { ToolSpec } from '../types.js'; import type { McpLogger, McpServerConfig } from './options.js'; /** One remote tool, mapped onto what `ToolRegistry.register` takes, plus where it came from. */ export interface McpImportedTool { spec: ToolSpec; handler: ToolHandler; /** The name on the server, which namespacing and sanitizing may have changed in `spec.name`. */ remoteName: string; serverName: string; } /** A remote tool that answered with `isError` — a business failure of the tool, not of the transport. */ export declare class McpToolCallError extends Error { readonly serverName: string; readonly toolName: string; constructor(serverName: string, toolName: string, message: string); } /** * One MCP server, as a source of tools. * * Holds a single client and reconnects on demand. The connection is deliberately not treated as * durable state: a remote server may restart, be redeployed, or drop an idle connection, and the * first symptom is a failed tool call. So a call that fails transiently drops the client, and the * retry — core's `invokeWithTransientRetry`, the same one the agent loop wraps every tool with — * reconnects on its next attempt. * * Every timeout here is the SDK's own per-request timeout rather than a race of our own, so a * timed-out request is also CANCELLED on the wire instead of being abandoned. */ export declare class McpToolSource { private readonly config; private readonly logger?; private client; private connecting; constructor(config: McpServerConfig, logger?: McpLogger | undefined); get name(): string; /** Connect if needed, list the server's tools, and map the selected ones onto specs + handlers. */ import(): Promise<McpImportedTool[]>; close(): Promise<void>; /** Runs the configured screen; a refusal or a screen that throws both leave the tool out. */ private passesScreen; private isSelected; /** * A tool whose schema won't compile — or whose `pattern` can backtrack exponentially — is * dropped, not imported with a permissive stand-in: the model would then be free to send that * remote tool any arguments at all, and the call would still look validated from this side. */ private toImportedTool; private callTool; private callOnce; /** The wire call alone, so only a TRANSPORT failure can recycle the client — never a tool's own. */ private request; private errorText; private ensureClient; private connect; private createTransport; private dropClient; /** * The configured policy with a classifier filled in. The library's default classifier recognizes * local database lock contention, which is not how a remote server fails — leaving it in place * would mean the policy is on and never matches anything. * * WHICH CLASSIFIER, AND WHY IT DEPENDS ON THE KIND. An `action` is a tool whose effects happen on * somebody else's machine and are invisible from here, which is why one waits for a human at all. * Most of what {@link isTransientMcpError} accepts cannot tell "the request never arrived" from * "it ran and the answer was lost" — a timeout, a reset, a 503 — so retrying on it would spend one * approval on two remote effects. An `action` therefore retries only * {@link isPreExecutionMcpError}: failures that prove nothing ran. A `read` keeps the broader * policy, where a second identical call costs a round trip. * * A host that supplied its own `classify` has taken that judgement over, and it is honoured for * every kind. */ private retrySetting; private requestTimeoutMs; } //# sourceMappingURL=tool-source.d.ts.map