@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
62 lines • 3.21 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import type { ProtocolAdapter } from '../spi/protocol-adapter.js';
import type { Actor } from '../types.js';
import type { OpenCodeTurns } from './turns.js';
/** What a tools token says: whose turns it may serve, on which OpenCode server, until when. */
export interface OpenCodeToolsClaims {
v: 1;
actor: Actor;
/** The OpenCode server key (`OpenCodeServer.key`) the token was registered on. */
server: string;
/** Epoch ms after which the token is refused. */
exp: number;
}
/**
* Signs and checks the bearer tokens the engine registers its tools endpoint with (`mcp.add`). A
* token names an actor and an OpenCode server, and expires; it is HMAC-SHA256 over its claims with
* a key derived from the configured secret (or the app's `APP_KEY`).
*
* A token on its own runs nothing: the endpoint also needs the call to come from a session that is
* running a turn of that actor right now (see `OpenCodeTurns.callContext`), and an `action` tool
* needs an approval the turn granted (see `OpenCodeTurns.spendApproval`).
*/
export declare class OpenCodeToolsTokens {
private readonly ttlMs;
private readonly key;
constructor(secret: string | undefined, ttlMs: number);
mint(actor: Actor, server: string, now?: number): string;
verify(token: string, now?: number): OpenCodeToolsClaims | null;
private sign;
}
/**
* The MCP endpoint OpenCode sessions reach the app's tools through — `POST <agent path>/opencode/mcp`,
* mounted by the engine when `tools` is set. Stateless Streamable HTTP (one server per request), so
* it answers from any process.
*
* - `tools/list`: the registry's tools the token's actor may reach (roles, `enabled`, `canUse`), the
* kinds only the loop serves left out; with `_meta` naming a running turn, its agent's allow-list
* too. Plus `remember`, when the agent's memory provider writes.
* - `tools/call`: only for a call `_meta` ties to a turn of the token's actor running on that
* session; the turn's allow-list and the registry's own checks apply, an `action` runs only against
* an approval the turn granted, and the tool's `ctx` is the turn's (thread, run, `emitUi` into its
* stream and message).
*/
export declare class OpenCodeMcpEndpoint {
private readonly turns;
private readonly tokens;
/** Genui telemetry of the UI calls OpenCode makes (its code mode calls tools here, not in the loop). */
private readonly genui;
constructor(turns: OpenCodeTurns, tokens: OpenCodeToolsTokens);
/** Mounts the endpoint next to the agent's routes. */
adapter(): ProtocolAdapter;
/** The claims of a request's bearer token, or `null`. */
authenticate(authorization: string | undefined): OpenCodeToolsClaims | null;
handle(ctx: HttpContext): Promise<void>;
/** One MCP server for one request, answering as the token's actor. */
server(claims: OpenCodeToolsClaims): Server;
private invoke;
/** `remember`: one fact, at the actor's own scope only — as the loop serves it. */
private remember;
}
//# sourceMappingURL=mcp.d.ts.map