Skip to content
API reference

mycelium

Import
import * as api from "@fungi.computer/mycelium";
Kind Export Description
class MyceliumDefinitionError A capability declaration could not form one coherent installed surface.
class MyceliumClosedError An operation attempted to use a closed Mycelium runtime.
class MyceliumSourceError A capability source failed at its bounded host boundary.
class InvalidOperationInput Untrusted operation input failed the operation’s declared input schema.
class InvalidOperationOutput An operation’s result failed its declared output schema.
type alias Access What one operation does: read observes, write changes something.
type alias ToolPolicy An author’s labels for one operation or direct tool.
type alias Grant The access a host grants one module.
type alias Grants A host’s grants, keyed by module id. An unnamed module uses defaultGrant unless it is required, in which case missing authority is refused.
type alias AccessLabel The labels an operation or direct tool carries, as its author declared them.
type alias AccessContext The Session a runtime serves; null for a session-free host.
type alias ConfirmRequest One call the host is asked to approve before it runs.
type alias AccessRefusalReason Why a call was refused before it ran.
type alias AccessRefusal The ordinary result a refused call returns in place of running.
type alias AccessOptions Host-supplied access data and the one way to ask a person. Every field is optional: hosted defaults allow unnamed modules, and no confirm means an operation requiring approval is refused, never run unasked. MCP catalogs explicitly default unnamed modules to none. Native hosts own durable approval policy for admitted writes; explicit author confirmation still uses this port.
type alias LabelledTool A Mule tool that carries its author’s access labels outside execute.
type alias CapabilitySession Session on whose behalf one runtime acquires its capability projections.
type alias CapabilitySourceContext Context supplied while acquiring one current capability projection.
type alias CapabilitySourceSnapshot Bounded current projection returned by one capability source.
type alias CapabilitySourceAcquisition Acquired source projection and the cleanup that owns its live adapter.
type alias CapabilitySource Promise-shaped host boundary for one versioned capability projection.
type alias MyceliumSourcePhase Lifecycle phase in which a capability source failed.
type alias MyceliumError Closed failure vocabulary for the first Mycelium runtime slice.
type alias ExecutionOptions Host execution limits plus the reserved, host-only admission contract.
type alias CollectedImage A single image collected during an execute run.
type alias ExecutionImages The collector as one execution’s operations see it: push only.
type alias InvocationContext The only context an operation callback may observe.
type alias MyceliumOptions Inputs used to construct the Promise-facing runtime.
type alias AcquireOptions Cancellation options for one Promise-facing lease acquisition.
type alias Lease One immutable Promise-facing capability revision.
type alias Runtime Warm Promise-facing lifecycle for acquiring immutable run leases.
type alias OperationDefinition Declaration for one operation behind the execute door. input and output may be Effect schemas (encoded as JSON) or any Standard Schema with Standard JSON Schema, such as Zod 4.
type alias ModuleDefinition Declaration for one stable module and its related operations.
type alias MyceliumApi Public convenience namespace contract.
type alias OperationSchemaIssue One Standard Schema issue.
type alias OperationSchemaResult Standard Schema validation result.
type alias StandardOperationSchema Any Standard Schema that also implements Standard JSON Schema, such as a Zod 4 schema. Mycelium validates with validate and describes the operation to the model with jsonSchema.
type alias OperationSchema Schema for one operation’s input or output: an Effect schema (exchanged as its canonical JSON codec, Schema.toCodecJson), or any Standard Schema with Standard JSON Schema such as Zod 4.
type alias OperationRegistration Opaque handle for one schema-described operation.
type alias ModuleRegistration Opaque handle for one namespaced capability module.
type alias GateDecision A gate’s verdict for one call: run the operation, or return value instead.
type alias OperationGate Asked before every call of a gated module’s operations.
type alias SandboxAdmissionOptions Host-owned admission inputs; never part of guest execute arguments.
type alias SandboxAdmissionPolicy Captured once per runtime and shared across backing-work groups.
type alias SandboxFailureEvent Full operator diagnostics, excluded from model conversation and default reads.
constant ToolAccessSchema What one operation does, declared by its author as a fixed fact: read observes, write changes something. An unlabelled operation is write.
constant ToolConfirmSchema Whether the author asks that a person approve each call first.
constant ToolPolicySchema An author’s labels for one operation or direct tool: the one definition both the TypeScript type and the registration-time parse derive from.
constant GrantSchema The access a host grants one module: write allows every operation, read allows only read operations, none allows nothing.
constant MAX_EXECUTION_IMAGES Maximum number of out-of-band images retained for one execution.
constant Mycelium Schema-described authoring and Promise-facing runtime construction.
constant SandboxFailureEventSchema Shared structural grammar for durable operator facts and client inspection.
function normalizeSandboxAdmissionPolicy() Validate host policy and resolve defaults from a platform-owned core observation.

A capability declaration could not form one coherent installed surface.

  • Error
Signature
new MyceliumDefinitionError(message): MyceliumDefinitionError;
Parameter Type
message string

MyceliumDefinitionError

Signature
Error.constructor;
Signature
readonly code: "invalid_definition" = invalidDefinitionCode;

Stable machine-readable failure code.


An operation attempted to use a closed Mycelium runtime.

  • Error
Signature
new MyceliumClosedError(message?): MyceliumClosedError;
Parameter Type Default value
message string "Mycelium runtime is closed"

MyceliumClosedError

Signature
Error.constructor;
Signature
readonly code: "runtime_closed" = runtimeClosedCode;

Stable machine-readable failure code.


A capability source failed at its bounded host boundary.

  • Error
Signature
new MyceliumSourceError(sourceId, phase): MyceliumSourceError;
Parameter Type Description
sourceId string | undefined Stable identity of the source, absent for whole-candidate failures.
phase MyceliumSourcePhase Lifecycle phase that could not settle.

MyceliumSourceError

Signature
Error.constructor;
Signature
readonly code: "source_failure" = sourceFailureCode;

Stable machine-readable failure code.

Signature
readonly sourceId: string | undefined;

Stable identity of the source, absent for whole-candidate failures.

Signature
readonly phase: MyceliumSourcePhase;

Lifecycle phase that could not settle.


Untrusted operation input failed the operation’s declared input schema.

  • Error
Signature
new InvalidOperationInput(issues): InvalidOperationInput;
Parameter Type Description
issues readonly Readonly<{ message: string; path?: readonly ( | PropertyKey | Readonly<{ key: PropertyKey; }>)[]; }>[] Schema issues, formatted for the model by the execute door.

InvalidOperationInput

Signature
Error.constructor;
Signature
readonly issues: readonly Readonly<{
message: string;
path?: readonly (
| PropertyKey
| Readonly<{
key: PropertyKey;
}>)[];
}>[];

Schema issues, formatted for the model by the execute door.


An operation’s result failed its declared output schema.

  • Error
Signature
new InvalidOperationOutput(issues): InvalidOperationOutput;
Parameter Type Description
issues readonly Readonly<{ message: string; path?: readonly ( | PropertyKey | Readonly<{ key: PropertyKey; }>)[]; }>[] Schema issues, kept for operators; never shown to the model.

InvalidOperationOutput

Signature
Error.constructor;
Signature
readonly issues: readonly Readonly<{
message: string;
path?: readonly (
| PropertyKey
| Readonly<{
key: PropertyKey;
}>)[];
}>[];

Schema issues, kept for operators; never shown to the model.

Signature
type Access = typeof ToolAccessSchema.Type;

What one operation does: read observes, write changes something.


ToolPolicytype alias

Section titled “ToolPolicy”
Signature
type ToolPolicy = typeof ToolPolicySchema.Type;

An author’s labels for one operation or direct tool.


Signature
type Grant = typeof GrantSchema.Type;

The access a host grants one module.


Signature
type Grants = Readonly<Record<string, Grant>>;

A host’s grants, keyed by module id. An unnamed module uses defaultGrant unless it is required, in which case missing authority is refused.


AccessLabeltype alias

Section titled “AccessLabel”
Signature
type AccessLabel = Readonly<{
module: string;
operation: string;
access: Access;
confirm: boolean;
}>;

The labels an operation or direct tool carries, as its author declared them.


AccessContexttype alias

Section titled “AccessContext”
Signature
type AccessContext = Readonly<{
sessionId: string | null;
}>;

The Session a runtime serves; null for a session-free host.


ConfirmRequesttype alias

Section titled “ConfirmRequest”
Signature
type ConfirmRequest = Readonly<
Omit<AccessLabel, "confirm"> & AccessContext & object
>;

One call the host is asked to approve before it runs.


AccessRefusalReasontype alias

Section titled “AccessRefusalReason”
Signature
type AccessRefusalReason =
"not-granted" | "read-only" | "confirmation-unavailable" | "declined";

Why a call was refused before it ran.


AccessRefusaltype alias

Section titled “AccessRefusal”
Signature
type AccessRefusal = Readonly<{
refused: true;
module: string;
operation: string;
reason: AccessRefusalReason;
message: string;
}>;

The ordinary result a refused call returns in place of running.


AccessOptionstype alias

Section titled “AccessOptions”
Signature
type AccessOptions = Readonly<{
defaultGrant?: Grant;
grants?: Grants;
required?: readonly string[];
sessionGrants?: (context) => Grants;
beforeCall?: (signal) => Promise<void>;
confirmWrites?: boolean;
confirm?: (request, signal) => Promise<boolean>;
onRefused?: (refusal, context) => void;
}>;

Host-supplied access data and the one way to ask a person. Every field is optional: hosted defaults allow unnamed modules, and no confirm means an operation requiring approval is refused, never run unasked. MCP catalogs explicitly default unnamed modules to none. Native hosts own durable approval policy for admitted writes; explicit author confirmation still uses this port.


LabelledTooltype alias

Section titled “LabelledTool”
Signature
type LabelledTool = MuleTool &
Readonly<{
module: string;
access?: Access;
confirm?: boolean;
}>;

A Mule tool that carries its author’s access labels outside execute.


CapabilitySessiontype alias

Section titled “CapabilitySession”
Signature
type CapabilitySession = Readonly<{
sessionId: string;
commandId?: string;
meta?: typeof Schema.Json.Type;
}>;

Session on whose behalf one runtime acquires its capability projections.


CapabilitySourceContexttype alias

Section titled “CapabilitySourceContext”
Signature
type CapabilitySourceContext = Readonly<{
session?: CapabilitySession;
signal: AbortSignal;
invalidate: () => void;
}>;

Context supplied while acquiring one current capability projection.


CapabilitySourceSnapshottype alias

Section titled “CapabilitySourceSnapshot”
Signature
type CapabilitySourceSnapshot = Readonly<{
version: string;
modules: readonly ModuleRegistration[];
}>;

Bounded current projection returned by one capability source.


CapabilitySourceAcquisitiontype alias

Section titled “CapabilitySourceAcquisition”
Signature
type CapabilitySourceAcquisition = Readonly<{
snapshot: CapabilitySourceSnapshot;
release: () => Promise<void>;
}>;

Acquired source projection and the cleanup that owns its live adapter.


CapabilitySourcetype alias

Section titled “CapabilitySource”
Signature
type CapabilitySource = Readonly<{
id: string;
acquire: (context) => Promise<CapabilitySourceAcquisition>;
}>;

Promise-shaped host boundary for one versioned capability projection.


MyceliumSourcePhasetype alias

Section titled “MyceliumSourcePhase”
Signature
type MyceliumSourcePhase = "acquire" | "release" | "stale";

Lifecycle phase in which a capability source failed.


MyceliumErrortype alias

Section titled “MyceliumError”
Signature
type MyceliumError =
| MyceliumClosedError
| MyceliumDefinitionError
| MyceliumSourceError
| SandboxFailure;

Closed failure vocabulary for the first Mycelium runtime slice.


ExecutionOptionstype alias

Section titled “ExecutionOptions”
Signature
type ExecutionOptions = Readonly<{
timeoutMs?: number;
abortGraceMs?: number;
}> &
SandboxAdmissionOptions;

Host execution limits plus the reserved, host-only admission contract.


CollectedImagetype alias

Section titled “CollectedImage”
Signature
type CollectedImage = Readonly<{
data: string;
mimeType: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
path: string;
bytes: number;
}>;

A single image collected during an execute run.


ExecutionImagestype alias

Section titled “ExecutionImages”
Signature
type ExecutionImages = Readonly<{
push: (image) => string;
}>;

The collector as one execution’s operations see it: push only.


InvocationContexttype alias

Section titled “InvocationContext”
Signature
type InvocationContext = Readonly<{
executionId: string;
toolCallId?: string;
operationOrdinal?: number;
toolCallCode?: string;
deadlineAt: number | null;
signal: AbortSignal;
images?: ExecutionImages;
output?: Readonly<{
write: (stream, bytes) => void;
}>;
}>;

The only context an operation callback may observe.


MyceliumOptionstype alias

Section titled “MyceliumOptions”
Signature
type MyceliumOptions = Readonly<{
modules?: readonly ModuleRegistration[];
sources?: readonly CapabilitySource[];
session?: CapabilitySession;
execution?: ExecutionOptions;
sandbox: Sandbox;
onSandboxFailure?: (event) => Promise<void>;
tools?: readonly LabelledTool[];
access?: AccessOptions;
}>;

Inputs used to construct the Promise-facing runtime.


AcquireOptionstype alias

Section titled “AcquireOptions”
Signature
type AcquireOptions = Readonly<{
signal?: AbortSignal;
}>;

Cancellation options for one Promise-facing lease acquisition.


Signature
type Lease = Readonly<{
revision: string;
catalog: ForageCatalog;
executeTool: MuleTool;
tools: readonly MuleTool[];
release: () => Promise<void>;
}>;

One immutable Promise-facing capability revision.


Signature
type Runtime = Readonly<{
acquire: (options?) => Promise<Lease>;
close: () => Promise<void>;
}>;

Warm Promise-facing lifecycle for acquiring immutable run leases.


OperationDefinitiontype alias

Section titled “OperationDefinition”
Signature
type OperationDefinition<I, O> = Readonly<{
replay?: "safe" | "unsafe";
access?: Access;
confirm?: boolean;
description?: string;
input: OperationSchema<I>;
output?: OperationSchema<O>;
execute: (input, context) => Promise<O>;
}>;

Declaration for one operation behind the execute door. input and output may be Effect schemas (encoded as JSON) or any Standard Schema with Standard JSON Schema, such as Zod 4.

Type Parameter
I
O

ModuleDefinitiontype alias

Section titled “ModuleDefinition”
Signature
type ModuleDefinition = Readonly<{
id: string;
name?: string;
namespace?: readonly string[];
description?: string;
operations: Readonly<
Record<string, OperationRegistration | ModuleRegistration>
>;
}>;

Declaration for one stable module and its related operations.


MyceliumApitype alias

Section titled “MyceliumApi”
Signature
type MyceliumApi = Readonly<{
module: (definition) => ModuleRegistration;
operation: {
<I, O>(definition): OperationRegistration<I, O>;
<I, O>(definition): OperationRegistration<I, O>;
};
make: (options) => Promise<Runtime>;
gate: (module, gate) => ModuleRegistration;
grantAs: (module, grantKey) => ModuleRegistration;
}>;

Public convenience namespace contract.


OperationSchemaIssuetype alias

Section titled “OperationSchemaIssue”
Signature
type OperationSchemaIssue = Readonly<{
message: string;
path?: readonly (
| PropertyKey
| Readonly<{
key: PropertyKey;
}>
)[];
}>;

One Standard Schema issue.


OperationSchemaResulttype alias

Section titled “OperationSchemaResult”
Signature
type OperationSchemaResult<T> =
| Readonly<{
value: T;
issues?: undefined;
}>
| Readonly<{
issues: readonly OperationSchemaIssue[];
}>;

Standard Schema validation result.

Type Parameter
T

StandardOperationSchematype alias

Section titled “StandardOperationSchema”
Signature
type StandardOperationSchema<T> = Readonly<{
~standard: Readonly<{
validate: (value) =>
| OperationSchemaResult<T>
| Promise<OperationSchemaResult<T>>;
jsonSchema: JsonSchemaSource["~standard"]["jsonSchema"];
}>;
}>;

Any Standard Schema that also implements Standard JSON Schema, such as a Zod 4 schema. Mycelium validates with validate and describes the operation to the model with jsonSchema.

Type Parameter
T

OperationSchematype alias

Section titled “OperationSchema”
Signature
type OperationSchema<T> = Schema.Codec<T, unknown> | StandardOperationSchema<T>;

Schema for one operation’s input or output: an Effect schema (exchanged as its canonical JSON codec, Schema.toCodecJson), or any Standard Schema with Standard JSON Schema such as Zod 4.

Type Parameter
T

OperationRegistrationtype alias

Section titled “OperationRegistration”
Signature
type OperationRegistration<I, O> = Readonly<{
[operationBrand]: true;
[operationTypes]?: Readonly<{
input: I;
output: O;
}>;
}>;

Opaque handle for one schema-described operation.

Type Parameter Default type
I unknown
O unknown

ModuleRegistrationtype alias

Section titled “ModuleRegistration”
Signature
type ModuleRegistration = Readonly<{
[moduleBrand]: true;
}>;

Opaque handle for one namespaced capability module.


GateDecisiontype alias

Section titled “GateDecision”
Signature
type GateDecision =
| Readonly<{
kind: "allow";
}>
| Readonly<{
kind: "refuse";
value: MyceliumJsonValue;
}>;

A gate’s verdict for one call: run the operation, or return value instead.


OperationGatetype alias

Section titled “OperationGate”
Signature
type OperationGate = (call) => GateDecision | Promise<GateDecision>;

Asked before every call of a gated module’s operations.

Parameter Type
call Readonly<{ operation: string; context: InvocationContext; }>

| GateDecision | Promise<GateDecision>


SandboxAdmissionOptionstype alias

Section titled “SandboxAdmissionOptions”
Signature
type SandboxAdmissionOptions = Readonly<{
sandboxCapacity?: number;
admissionWaitMs?: number;
}>;

Host-owned admission inputs; never part of guest execute arguments.


SandboxAdmissionPolicytype alias

Section titled “SandboxAdmissionPolicy”
Signature
type SandboxAdmissionPolicy = Readonly<{
capacity: number;
waitMs: number;
}>;

Captured once per runtime and shared across backing-work groups.


SandboxFailureEventtype alias

Section titled “SandboxFailureEvent”
Signature
type SandboxFailureEvent = typeof SandboxFailureEventSchema.Type;

Full operator diagnostics, excluded from model conversation and default reads.

ToolAccessSchemaconstant

Section titled “ToolAccessSchema”
Signature
const ToolAccessSchema: Literals<readonly ["read", "write"]>;

What one operation does, declared by its author as a fixed fact: read observes, write changes something. An unlabelled operation is write.


ToolConfirmSchemaconstant

Section titled “ToolConfirmSchema”
Signature
const ToolConfirmSchema: Boolean = Schema.Boolean;

Whether the author asks that a person approve each call first.


ToolPolicySchemaconstant

Section titled “ToolPolicySchema”
Signature
const ToolPolicySchema: Struct<{
access: optional<Literals<readonly ["read", "write"]>>;
confirm: optional<Boolean>;
}>;

An author’s labels for one operation or direct tool: the one definition both the TypeScript type and the registration-time parse derive from.


GrantSchemaconstant

Section titled “GrantSchema”
Signature
const GrantSchema: Literals<readonly ["none", "read", "write"]>;

The access a host grants one module: write allows every operation, read allows only read operations, none allows nothing.


MAX_EXECUTION_IMAGESconstant

Section titled “MAX_EXECUTION_IMAGES”
Signature
const MAX_EXECUTION_IMAGES: 8 = 8;

Maximum number of out-of-band images retained for one execution.


Myceliumconstant

Section titled “Mycelium”
Signature
const Mycelium: MyceliumApi;

Schema-described authoring and Promise-facing runtime construction.


SandboxFailureEventSchemaconstant

Section titled “SandboxFailureEventSchema”
Signature
const SandboxFailureEventSchema: Struct<{
kind: Literal<"sandbox_failure">;
ref: String;
executionId: String;
adapter: String;
buildSha: NullOr<String>;
tag: Literals<
readonly [
"SourceInvalid",
"GuestThrew",
"DeadlineExceeded",
"SandboxBusy",
"Cancelled",
"DispatchLost",
"SandboxCrashed",
"BadResponse",
"ResultTooLarge",
"ResultNotJson",
"CapabilityFailed",
"Unknown",
]
>;
fields: $Record<String, Codec<JSONType, JSONType, never, never>>;
healthAlert: Boolean;
}>;

Shared structural grammar for durable operator facts and client inspection.

normalizeSandboxAdmissionPolicy()function

Section titled “normalizeSandboxAdmissionPolicy()”
Signature
function normalizeSandboxAdmissionPolicy(
options,
availableCores?,
): SandboxAdmissionPolicy;

Validate host policy and resolve defaults from a platform-owned core observation.

Parameter Type
options | Readonly<{ sandboxCapacity?: number; admissionWaitMs?: number; }> | undefined
availableCores? number

SandboxAdmissionPolicy

Re-exports sandboxFailure


Re-exports isSandboxFailure


Re-exports sandboxOperatorValue


Re-exports MyceliumJsonValue


Re-exports SandboxValue


Re-exports SandboxBinding


Re-exports SandboxRequest


Re-exports Sandbox


Re-exports SourceInvalid


Re-exports GuestThrew


Re-exports DeadlineExceeded


Re-exports SandboxBusy


Re-exports Cancelled


Re-exports DispatchLost


Re-exports SandboxCrashed


Re-exports BadResponse


Re-exports ResultTooLarge


Re-exports ResultNotJson


Re-exports CapabilityFailed


Re-exports Unknown


Re-exports sandboxFailureMessage


Re-exports SandboxFailure


Re-exports CapabilityDiagnostic


Re-exports CapabilityFailureFields