Skip to content

@codesoul-co/hypha-tools / adapter-factory

Using this module

Use the Adapter factory module for binding external or local providers to Hypha ports. It exports 2 classes, 3 constants, 3 functions, 8 interfaces, 1 type.

Import from the package entrypoint

ts
import {
  LoadedToolAdapterProfiles,
  ToolAdapterFactoryRegistry,
  toolAdapterKinds,
  toolAdapterProfileSchema,
  toolAdapterProfilesDocumentSchema,
  loadToolAdapterProfiles,
  parseToolAdapterProfilesDocument,
  registerConcreteToolAdapterFactories,
} from '@codesoul-co/hypha-tools';

import type {
  ConcreteToolAdapterFactoryDependencies,
  LoadedToolAdapterProfile,
  ToolAdapterFactory,
  ToolAdapterFactoryInput,
  ToolAdapterFactoryRegistryOptions,
  ToolAdapterProfile,
  ToolAdapterProfilesDocument,
  ToolSpecReference,
} from '@codesoul-co/hypha-tools';

// The complete export list is documented below.

Usage patterns

  • Use the 9 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 2 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 3 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.
  • The 3 constant/enum exports provide stable values, schemas, definitions, or defaults. Reuse these exports instead of copying internal values into an application.

Runtime validation example

ts
import { toolAdapterProfileSchema } from '@codesoul-co/hypha-tools';

declare function loadExternalInput(): unknown;
const input: unknown = loadExternalInput();
const parsed = toolAdapterProfileSchema.parse(input);

Parse untrusted configuration, network, or persisted input with the runtime schema before passing it to functions or classes that expect a validated contract.

Public exports

SymbolKindSignatureDescription
LoadedToolAdapterProfilesclassnew LoadedToolAdapterProfiles(entries: Map<string, LoadedToolAdapterProfile>): LoadedToolAdapterProfilesLoaded Tool Adapter Profiles class with 5 public constructor or member entries; its exact declarations are listed below.
ToolAdapterFactoryRegistryclassnew ToolAdapterFactoryRegistry(options: ToolAdapterFactoryRegistryOptions): ToolAdapterFactoryRegistryCreates adapters from declarative profiles without allowing profiles to smuggle executable factories or plaintext credentials through configuration.
toolAdapterKindsconstantconst toolAdapterKinds: readonly ["local_function", "http", "plugin", "mcp_stdio", "mcp_streamable_http", "execution"]Tool Adapter Kinds constant exported by the adapter-factory module.
toolAdapterProfileSchemaconstantconst toolAdapterProfileSchema: z.ZodEffects<z.ZodObject<{ id: z.ZodString; kind: z.ZodEnum<["local_function", "http", "plugin", "mcp_stdio", "mcp_streamable_http", "execution"]>; required: z.ZodDefault<z.ZodBoolean>; toolSpecRef: z.ZodObject<{ id: z.ZodString; version: z.ZodOptional<z.ZodString>; revision: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { id: string; version?: string | undefined; revision?...Runtime schema for Tool Adapter Profile.
toolAdapterProfilesDocumentSchemaconstantconst toolAdapterProfilesDocumentSchema: z.ZodObject<{ profiles: z.ZodArray<z.ZodEffects<z.ZodObject<{ id: z.ZodString; kind: z.ZodEnum<["local_function", "http", "plugin", "mcp_stdio", "mcp_streamable_http", "execution"]>; required: z.ZodDefault<z.ZodBoolean>; toolSpecRef: z.ZodObject<{ id: z.ZodString; version: z.ZodOptional<z.ZodString>; revision: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { id: str...Runtime schema for Tool Adapter Profiles Document.
loadToolAdapterProfilesfunctionloadToolAdapterProfiles(input: unknown, registry: ToolAdapterFactoryRegistry): Promise<LoadedToolAdapterProfiles>Load Tool Adapter Profiles function with 1 public call signature; parameters and return types are listed below.
parseToolAdapterProfilesDocumentfunctionparseToolAdapterProfilesDocument(input: unknown): ToolAdapterProfilesDocumentParse Tool Adapter Profiles Document function with 1 public call signature; parameters and return types are listed below.
registerConcreteToolAdapterFactoriesfunctionregisterConcreteToolAdapterFactories(registry: ToolAdapterFactoryRegistry, dependencies?: ConcreteToolAdapterFactoryDependencies): voidRegisters the complete declarative factory surface used by server composition.
ConcreteToolAdapterFactoryDependenciesinterfaceinterface ConcreteToolAdapterFactoryDependenciesConcrete Tool Adapter Factory Dependencies interface with 6 public fields or methods.
LoadedToolAdapterProfileinterfaceinterface LoadedToolAdapterProfileLoaded Tool Adapter Profile interface with 5 public fields or methods.
ToolAdapterFactoryinterfaceinterface ToolAdapterFactoryTool Adapter Factory interface with 2 public fields or methods.
ToolAdapterFactoryInputinterfaceinterface ToolAdapterFactoryInputTool Adapter Factory Input interface with 4 public fields or methods.
ToolAdapterFactoryRegistryOptionsinterfaceinterface ToolAdapterFactoryRegistryOptionsTool Adapter Factory Registry Options interface with 2 public fields or methods.
ToolAdapterProfileinterfaceinterface ToolAdapterProfileTool Adapter Profile interface with 9 public fields or methods.
ToolAdapterProfilesDocumentinterfaceinterface ToolAdapterProfilesDocumentTool Adapter Profiles Document interface with 1 public fields or methods.
ToolSpecReferenceinterfaceinterface ToolSpecReferenceTool Spec Reference interface with 3 public fields or methods.
ToolAdapterKindtypetype ToolAdapterKind = (typeof toolAdapterKinds)[number]Public type alias for Tool Adapter Kind; the declaration contains its complete type expression.

LoadedToolAdapterProfiles

Loaded Tool Adapter Profiles class with 5 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { LoadedToolAdapterProfiles } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare class LoadedToolAdapterProfiles {
    constructor(entries: Map<string, LoadedToolAdapterProfile>);
    list(): LoadedToolAdapterProfile[];
    get(profileId: string): LoadedToolAdapterProfile | undefined;
    health(): Promise<Record<string, Awaited<ReturnType<ToolAdapter['health']>>>>;
    close(): Promise<void>;
}

Public members

MemberKindSignatureDescription
closemethodclose(): Promise<void>Public method; parameters and return type are shown in the signature.
constructorconstructor(entries: Map<string, LoadedToolAdapterProfile>): LoadedToolAdapterProfilesCreates an instance of this class.
getmethodget(profileId: string): LoadedToolAdapterProfile | undefinedPublic method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<Record<string, Awaited<ReturnType<ToolAdapter["health"]>>>>Public method; parameters and return type are shown in the signature.
listmethodlist(): LoadedToolAdapterProfile[]Public method; parameters and return type are shown in the signature.

ToolAdapterFactoryRegistry

Creates adapters from declarative profiles without allowing profiles to smuggle executable factories or plaintext credentials through configuration.

  • Kind: class
  • Import: import { ToolAdapterFactoryRegistry } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare class ToolAdapterFactoryRegistry {
    constructor(options: ToolAdapterFactoryRegistryOptions);
    register(factory: ToolAdapterFactory): void;
    create(untrustedProfile: ToolAdapterProfile): Promise<{
            profile: ToolAdapterProfile;
            toolSpec: ToolSpec;
            adapter: ToolAdapter;
        }>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: ToolAdapterFactoryRegistryOptions): ToolAdapterFactoryRegistryCreates an instance of this class.
createmethodcreate(untrustedProfile: ToolAdapterProfile): Promise<{ profile: ToolAdapterProfile; toolSpec: ToolSpec; adapter: ToolAdapter; }>Public method; parameters and return type are shown in the signature.
registermethodregister(factory: ToolAdapterFactory): voidPublic method; parameters and return type are shown in the signature.

toolAdapterKinds

Tool Adapter Kinds constant exported by the adapter-factory module.

  • Kind: constant
  • Import: import { toolAdapterKinds } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare const toolAdapterKinds: readonly ["local_function", "http", "plugin", "mcp_stdio", "mcp_streamable_http", "execution"];

toolAdapterProfileSchema

Runtime schema for Tool Adapter Profile.

  • Kind: constant
  • Import: import { toolAdapterProfileSchema } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
// Exact type resolved from the package entrypoint; see source for the compiler expansion.
export declare const toolAdapterProfileSchema: (typeof import('@codesoul-co/hypha-tools'))['toolAdapterProfileSchema'];

This compiler-expanded constant type is compacted. Its public name, top-level type, and source location remain here; use the module’s exported interfaces, types, or runtime schema for input/output fields.

toolAdapterProfilesDocumentSchema

Runtime schema for Tool Adapter Profiles Document.

  • Kind: constant
  • Import: import { toolAdapterProfilesDocumentSchema } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
// Exact type resolved from the package entrypoint; see source for the compiler expansion.
export declare const toolAdapterProfilesDocumentSchema: (typeof import('@codesoul-co/hypha-tools'))['toolAdapterProfilesDocumentSchema'];

This compiler-expanded constant type is compacted. Its public name, top-level type, and source location remain here; use the module’s exported interfaces, types, or runtime schema for input/output fields.

loadToolAdapterProfiles

Load Tool Adapter Profiles function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { loadToolAdapterProfiles } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare function loadToolAdapterProfiles(input: unknown, registry: ToolAdapterFactoryRegistry): Promise<LoadedToolAdapterProfiles>;

Call signature

text
loadToolAdapterProfiles(input: unknown, registry: ToolAdapterFactoryRegistry): Promise<LoadedToolAdapterProfiles>

Parameters

ParameterTypeRequiredDescription
inputunknownYesRequired parameter; accepted values are defined by the type column.
registryToolAdapterFactoryRegistryYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: Promise<LoadedToolAdapterProfiles>
  • Description: The return contract is defined by the type shown above.

parseToolAdapterProfilesDocument

Parse Tool Adapter Profiles Document function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { parseToolAdapterProfilesDocument } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare function parseToolAdapterProfilesDocument(input: unknown): ToolAdapterProfilesDocument;

Call signature

text
parseToolAdapterProfilesDocument(input: unknown): ToolAdapterProfilesDocument

Parameters

ParameterTypeRequiredDescription
inputunknownYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: ToolAdapterProfilesDocument
  • Description: The return contract is defined by the type shown above.

registerConcreteToolAdapterFactories

Registers the complete declarative factory surface used by server composition.

  • Kind: function
  • Import: import { registerConcreteToolAdapterFactories } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export declare function registerConcreteToolAdapterFactories(registry: ToolAdapterFactoryRegistry, dependencies?: ConcreteToolAdapterFactoryDependencies): void;

Call signature

text
registerConcreteToolAdapterFactories(registry: ToolAdapterFactoryRegistry, dependencies?: ConcreteToolAdapterFactoryDependencies): void

Registers the complete declarative factory surface used by server composition.

Parameters

ParameterTypeRequiredDescription
registryToolAdapterFactoryRegistryYesRequired parameter; accepted values are defined by the type column.
dependenciesConcreteToolAdapterFactoryDependenciesNoOptional parameter; accepted values are defined by the type column.

Returns

  • Type: void
  • Description: Returns no value.

ConcreteToolAdapterFactoryDependencies

Concrete Tool Adapter Factory Dependencies interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { ConcreteToolAdapterFactoryDependencies } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ConcreteToolAdapterFactoryDependencies {
    localFunctions?: Readonly<Record<string, ToolHandler>>;
    plugins?: Readonly<Record<string, ToolHandler>>;
    mcpPort?: MCPToolInvocationPort;
    prepareMCPConnection?(input: ToolAdapterFactoryInput): Promise<{
        port: MCPToolInvocationPort;
        close?(): Promise<void>;
    }>;
    createExecutionAdapter?(input: ToolAdapterFactoryInput): Promise<ToolAdapter>;
    fetch?: typeof fetch;
}

Contract members

MemberKindSignatureDescription
createExecutionAdaptermethodcreateExecutionAdapter?(input: ToolAdapterFactoryInput): Promise<ToolAdapter>Public method; parameters and return type are shown in the signature.
fetchmethodfetch?(input: RequestInfo | URL, init?: RequestInit): Promise<Response> | fetch?(input: string | URL | Request, init?: RequestInit): Promise<Response>Public method; parameters and return type are shown in the signature.
localFunctionspropertylocalFunctions?: Readonly<Record<string, ToolHandler>>Public property; its type, readonly modifier and optionality are shown in the signature.
mcpPortpropertymcpPort?: MCPToolInvocationPortPublic property; its type, readonly modifier and optionality are shown in the signature.
pluginspropertyplugins?: Readonly<Record<string, ToolHandler>>Public property; its type, readonly modifier and optionality are shown in the signature.
prepareMCPConnectionmethodprepareMCPConnection?(input: ToolAdapterFactoryInput): Promise<{ port: MCPToolInvocationPort; close?(): Promise<void>; }>Public method; parameters and return type are shown in the signature.

LoadedToolAdapterProfile

Loaded Tool Adapter Profile interface with 5 public fields or methods.

  • Kind: interface
  • Import: import type { LoadedToolAdapterProfile } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface LoadedToolAdapterProfile {
    profile: ToolAdapterProfile;
    toolSpec?: ToolSpec;
    adapter?: ToolAdapter;
    status: 'ready' | 'degraded';
    error?: string;
}

Contract members

MemberKindSignatureDescription
adapterpropertyadapter?: ToolAdapter<unknown, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
errorpropertyerror?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
profilepropertyprofile: ToolAdapterProfilePublic property; its type, readonly modifier and optionality are shown in the signature.
statuspropertystatus: "degraded" | "ready"Public property; its type, readonly modifier and optionality are shown in the signature.
toolSpecpropertytoolSpec?: ToolSpecPublic property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterFactory

Tool Adapter Factory interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ToolAdapterFactory } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolAdapterFactory {
    readonly kind: ToolAdapterKind;
    create(input: ToolAdapterFactoryInput): Promise<ToolAdapter>;
}

Contract members

MemberKindSignatureDescription
createmethodcreate(input: ToolAdapterFactoryInput): Promise<ToolAdapter>Public method; parameters and return type are shown in the signature.
kindpropertyreadonly kind: "http" | "execution" | "plugin" | "local_function" | "mcp_stdio" | "mcp_streamable_http"Public property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterFactoryInput

Tool Adapter Factory Input interface with 4 public fields or methods.

  • Kind: interface
  • Import: import type { ToolAdapterFactoryInput } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolAdapterFactoryInput {
    profile: ToolAdapterProfile;
    toolSpec: ToolSpec;
    resolveCredential(): Promise<string | null>;
    acquireCredential(): Promise<CredentialLease | null>;
}

Contract members

MemberKindSignatureDescription
acquireCredentialmethodacquireCredential(): Promise<CredentialLease | null>Public method; parameters and return type are shown in the signature.
profilepropertyprofile: ToolAdapterProfilePublic property; its type, readonly modifier and optionality are shown in the signature.
resolveCredentialmethodresolveCredential(): Promise<string | null>Public method; parameters and return type are shown in the signature.
toolSpecpropertytoolSpec: ToolSpecPublic property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterFactoryRegistryOptions

Tool Adapter Factory Registry Options interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ToolAdapterFactoryRegistryOptions } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolAdapterFactoryRegistryOptions {
    resolveToolSpec(reference: ToolSpecReference): Promise<ToolSpec | null>;
    secretResolver?: ToolSecretResolver;
}

Contract members

MemberKindSignatureDescription
resolveToolSpecmethodresolveToolSpec(reference: ToolSpecReference): Promise<ToolSpec | null>Public method; parameters and return type are shown in the signature.
secretResolverpropertysecretResolver?: ToolSecretResolverPublic property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterProfile

Tool Adapter Profile interface with 9 public fields or methods.

  • Kind: interface
  • Import: import type { ToolAdapterProfile } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolAdapterProfile {
    id: string;
    kind: ToolAdapterKind;
    required?: boolean;
    toolSpecRef: ToolSpecReference;
    endpoint?: string;
    credentialRef?: string;
    requiredCapabilities?: Array<keyof ToolAdapterCapabilities>;
    binding?: {
        localFunctionId?: string;
        pluginId?: string;
        executionPortRef?: string;
        mcpServerId?: string;
        mcpCapabilityId?: string;
        mcpConnectionProfileRef?: string;
    };
    /** @deprecated Use the typed binding object. */
    config?: Record<string, unknown>;
}

Contract members

MemberKindSignatureDescription
bindingpropertybinding?: { localFunctionId?: string; pluginId?: string; executionPortRef?: string; mcpServerId?: string; mcpCapabilityId?: string; mcpConnectionProfileRef?: string; }Public property; its type, readonly modifier and optionality are shown in the signature.
configpropertyconfig?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
credentialRefpropertycredentialRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
endpointpropertyendpoint?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
kindpropertykind: "http" | "execution" | "plugin" | "local_function" | "mcp_stdio" | "mcp_streamable_http"Public property; its type, readonly modifier and optionality are shown in the signature.
requiredpropertyrequired?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
requiredCapabilitiespropertyrequiredCapabilities?: (keyof ToolAdapterCapabilities)[]Public property; its type, readonly modifier and optionality are shown in the signature.
toolSpecRefpropertytoolSpecRef: ToolSpecReferencePublic property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterProfilesDocument

Tool Adapter Profiles Document interface with 1 public fields or methods.

  • Kind: interface
  • Import: import type { ToolAdapterProfilesDocument } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolAdapterProfilesDocument {
    profiles: ToolAdapterProfile[];
}

Contract members

MemberKindSignatureDescription
profilespropertyprofiles: ToolAdapterProfile[]Public property; its type, readonly modifier and optionality are shown in the signature.

ToolSpecReference

Tool Spec Reference interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { ToolSpecReference } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export interface ToolSpecReference {
    id: string;
    version?: string;
    revision?: string;
}

Contract members

MemberKindSignatureDescription
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
revisionpropertyrevision?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
versionpropertyversion?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ToolAdapterKind

Public type alias for Tool Adapter Kind; the declaration contains its complete type expression.

  • Kind: type
  • Import: import type { ToolAdapterKind } from '@codesoul-co/hypha-tools';
  • Source module: adapter-factory

Declaration

text
export type ToolAdapterKind = (typeof toolAdapterKinds)[number];