Skip to content

@ontrove/extend/toolkit

@ontrove/extend/toolkit — the thin standard library for authoring hosted Trove MCP servers. It owns the MCP protocol, JSON-RPC, schema validation, auth-context injection, secret access, and error envelopes, so authors write only the handlers (see the hosted-MCP SDK reference).

import { defineToolkit, z, ToolError } from "@ontrove/extend/toolkit";
export default defineToolkit({
tools: [
{
name: "lookup_order",
description: "Look up an internal order by ID.",
input: z.object({ orderId: z.string().describe("e.g. 'ORD-10423'.") }),
async handler({ orderId }, ctx) {
const token = await ctx.secret("ORDERS_API_TOKEN");
const res = await ctx.fetch(`https://orders.acme.internal/v1/${orderId}`, {
headers: { authorization: `Bearer ${token}` },
});
if (res.status === 404) throw new ToolError(`Order ${orderId} not found`);
return { text: `Order ${orderId}: ok`, structured: await res.json() };
},
},
],
});
ClassDescription
ToolErrorAn intentional, model-visible tool error.
InterfaceDescription
DefineOptionsOptions for defineToolkit — primarily injection points for tests.
FetchHandlerA minimal fetch handler shape, matching the fetch signature the hosted runtime exposes for each request.
FetchJsonOptsOptions for ToolContext.fetchJson. Supply schema (as part of the call, not this base type) to validate and type the result via z.infer.
JsonSchemaA JSON Schema object for a tool’s inputSchema, as surfaced in tools/list.
OAuth2ClientCredentialsDeclarative OAuth2 client-credentials auth. When set on ToolkitConfig, the SDK mints, caches, and attaches a Bearer token to egress automatically, so handlers never touch the token dance. The client id/secret are resolved from the vault by name (both must appear in the manifest secrets), and the tokenUrl host and apiHost must appear in the manifest egress.
ToolAnnotationsBehavioral hints for a tool (MCP annotations, spec 2025-06-18 / 2025-11-25).
ToolCallA normalized tool-call request as POSTed by the gateway into the hosted runtime. callbackBase is the Trove-provided origin the SDK’s ctx callbacks target; it is appended to the egress allowlist server-side.
ToolCallErrA normalized failed tool result, as returned to the gateway.
ToolCallOkA normalized successful tool result, as returned to the gateway.
ToolContextThe invocation context handed to every tool handler — a small capability object with no ambient authority.
ToolDefinitionA single tool definition. The input Zod schema is compiled to JSON Schema for tools/list and used to validate arguments before handler runs.
ToolErrorOptionsOptions for ToolError.
ToolkitConfigThe configuration passed to defineToolkit.
ToolkitDefinitionThe compiled server, produced by defineToolkit. It carries the tools/list descriptors and a normalized request handler the runtime entry wires to the hosted runtime’s fetch.
ToolListEntryThe tools/list-shaped descriptor of a single tool.
ToolResultThe object a handler returns. text is the model-visible body; structured is optional JSON-serializable data some clients display. When the tool declares an output schema, structured is surfaced to the host as the spec structuredContent object alongside the text mirror.
TroveClientA scoped client over the calling user’s own Trove knowledge base.
TroveDocumentA full document fetched by id.
TroveIngestDocA document to write into the knowledge base via TroveClient.ingest.
TroveIngestFallbackThe artifact to capture when the preferred one turns out not to exist. See TroveIngestDoc.fallback.
TroveIngestFeed-
TroveIngestResultThe result of an TroveClient.ingest call.
TroveSearchOptsParameters to TroveClient.search.
TroveSearchResultA single semantic-search hit from the user’s knowledge base.
Type AliasDescription
FetchLikeThe fetch implementation the SDK uses for callbacks and egress. Injectable so tests can supply a mock; defaults to the global fetch.
ToolCallResultThe discriminated union of normalized tool-call outcomes.
ToolErrorCodeStable machine-readable error codes the SDK emits.
FunctionDescription
compileInputSchemaCompile a Zod schema to a JSON Schema object suitable for inputSchema.
defineToolkit-
dispatchDispatch one normalized call against a server definition.
listToolsThe tools/list descriptors for a server.
toFetchHandlerWrap a server definition as a runtime fetch handler.
toolIdentity helper that keeps a tool’s schema type, so its handler’s arguments are typed for real.
toToolkitManifestThe manifest half of a toolkit, as the JSON a catalog commits.