@mastra/core
Version:
Mastra is the Typescript framework for building AI agents and assistants. It’s used by some of the largest companies in the world to build internal AI automation tooling and customer-facing agents.
183 lines • 9.03 kB
TypeScript
import type { Agent } from '../agent/index.js';
import type { ObservabilityRegistryConfig } from '../ai-tracing/index.js';
import type { BundlerConfig } from '../bundler/types.js';
import type { MastraServerCache } from '../cache/index.js';
import type { MastraDeployer } from '../deployer/index.js';
import type { PubSub } from '../events/pubsub.js';
import type { Event } from '../events/types.js';
import { LogLevel } from '../logger/index.js';
import type { IMastraLogger } from '../logger/index.js';
import type { MCPServerBase } from '../mcp/index.js';
import type { MastraMemory } from '../memory/memory.js';
import type { NewAgentNetwork } from '../network/vNext/index.js';
import type { MastraScorer } from '../scores/index.js';
import type { Middleware, ServerConfig } from '../server/types.js';
import type { MastraStorage } from '../storage/index.js';
import { Telemetry } from '../telemetry/index.js';
import type { OtelConfig } from '../telemetry/index.js';
import type { MastraTTS } from '../tts/index.js';
import type { MastraIdGenerator } from '../types.js';
import type { MastraVector } from '../vector/index.js';
import type { Workflow } from '../workflows/index.js';
import type { LegacyWorkflow } from '../workflows/legacy/index.js';
export interface Config<TAgents extends Record<string, Agent<any>> = Record<string, Agent<any>>, TLegacyWorkflows extends Record<string, LegacyWorkflow> = Record<string, LegacyWorkflow>, TWorkflows extends Record<string, Workflow> = Record<string, Workflow>, TVectors extends Record<string, MastraVector> = Record<string, MastraVector>, TTTS extends Record<string, MastraTTS> = Record<string, MastraTTS>, TLogger extends IMastraLogger = IMastraLogger, TVNextNetworks extends Record<string, NewAgentNetwork> = Record<string, NewAgentNetwork>, TMCPServers extends Record<string, MCPServerBase> = Record<string, MCPServerBase>, TScorers extends Record<string, MastraScorer<any, any, any, any>> = Record<string, MastraScorer<any, any, any, any>>> {
agents?: TAgents;
vnext_networks?: TVNextNetworks;
storage?: MastraStorage;
vectors?: TVectors;
logger?: TLogger | false;
legacy_workflows?: TLegacyWorkflows;
workflows?: TWorkflows;
tts?: TTTS;
telemetry?: OtelConfig;
observability?: ObservabilityRegistryConfig;
idGenerator?: MastraIdGenerator;
deployer?: MastraDeployer;
server?: ServerConfig;
mcpServers?: TMCPServers;
bundler?: BundlerConfig;
pubsub?: PubSub;
scorers?: TScorers;
/**
* Server middleware functions to be applied to API routes
* Each middleware can specify a path pattern (defaults to '/api/*')
* @deprecated use server.middleware instead
*/
serverMiddleware?: Array<{
handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
path?: string;
}>;
memory?: never;
events?: {
[topic: string]: (event: Event, cb?: () => Promise<void>) => Promise<void> | ((event: Event, cb?: () => Promise<void>) => Promise<void>)[];
};
}
export declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<string, Agent<any>>, TLegacyWorkflows extends Record<string, LegacyWorkflow> = Record<string, LegacyWorkflow>, TWorkflows extends Record<string, Workflow> = Record<string, Workflow>, TVectors extends Record<string, MastraVector> = Record<string, MastraVector>, TTTS extends Record<string, MastraTTS> = Record<string, MastraTTS>, TLogger extends IMastraLogger = IMastraLogger, TVNextNetworks extends Record<string, NewAgentNetwork> = Record<string, NewAgentNetwork>, TMCPServers extends Record<string, MCPServerBase> = Record<string, MCPServerBase>, TScorers extends Record<string, MastraScorer<any, any, any, any>> = Record<string, MastraScorer<any, any, any, any>>> {
#private;
/**
* @deprecated use getTelemetry() instead
*/
get telemetry(): Telemetry | undefined;
/**
* @deprecated use getStorage() instead
*/
get storage(): MastraStorage | undefined;
/**
* @deprecated use getMemory() instead
*/
get memory(): MastraMemory | undefined;
get pubsub(): PubSub;
getIdGenerator(): MastraIdGenerator | undefined;
/**
* Generate a unique identifier using the configured generator or default to crypto.randomUUID()
* @returns A unique string ID
*/
generateId(): string;
setIdGenerator(idGenerator: MastraIdGenerator): void;
constructor(config?: Config<TAgents, TLegacyWorkflows, TWorkflows, TVectors, TTTS, TLogger, TVNextNetworks, TMCPServers, TScorers>);
/**
* Register this Mastra instance with AI tracing exporters that need it
*/
private registerAITracingExporters;
/**
* Initialize all AI tracing exporters after registration is complete
*/
private initAITracingExporters;
getAgent<TAgentName extends keyof TAgents>(name: TAgentName): TAgents[TAgentName];
getAgentById(id: string): Agent;
getAgents(): TAgents;
getVector<TVectorName extends keyof TVectors>(name: TVectorName): TVectors[TVectorName];
getVectors(): TVectors | undefined;
getDeployer(): MastraDeployer | undefined;
legacy_getWorkflow<TWorkflowId extends keyof TLegacyWorkflows>(id: TWorkflowId, { serialized }?: {
serialized?: boolean;
}): TLegacyWorkflows[TWorkflowId];
getWorkflow<TWorkflowId extends keyof TWorkflows>(id: TWorkflowId, { serialized }?: {
serialized?: boolean;
}): TWorkflows[TWorkflowId];
getWorkflowById(id: string): Workflow;
legacy_getWorkflows(props?: {
serialized?: boolean;
}): Record<string, LegacyWorkflow>;
getScorers(): TScorers | undefined;
getScorer<TScorerKey extends keyof TScorers>(key: TScorerKey): TScorers[TScorerKey];
getScorerByName(name: string): MastraScorer<any, any, any, any>;
getWorkflows(props?: {
serialized?: boolean;
}): Record<string, Workflow>;
setStorage(storage: MastraStorage): void;
setLogger({ logger }: {
logger: TLogger;
}): void;
setTelemetry(telemetry: OtelConfig): void;
getTTS(): TTTS | undefined;
getLogger(): TLogger;
getTelemetry(): Telemetry | undefined;
getMemory(): MastraMemory | undefined;
getStorage(): MastraStorage | undefined;
getServerMiddleware(): {
handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
path: string;
}[];
getServerCache(): MastraServerCache;
setServerMiddleware(serverMiddleware: Middleware | Middleware[]): void;
vnext_getNetworks(): NewAgentNetwork[];
getServer(): ServerConfig | undefined;
getBundlerConfig(): BundlerConfig | undefined;
vnext_getNetwork(networkId: string): NewAgentNetwork | undefined;
getLogsByRunId({ runId, transportId, fromDate, toDate, logLevel, filters, page, perPage, }: {
runId: string;
transportId: string;
fromDate?: Date;
toDate?: Date;
logLevel?: LogLevel;
filters?: Record<string, any>;
page?: number;
perPage?: number;
}): Promise<{
logs: import("../logger").BaseLogMessage[];
total: number;
page: number;
perPage: number;
hasMore: boolean;
}>;
getLogs(transportId: string, params?: {
fromDate?: Date;
toDate?: Date;
logLevel?: LogLevel;
filters?: Record<string, any>;
page?: number;
perPage?: number;
}): Promise<{
logs: import("../logger").BaseLogMessage[];
total: number;
page: number;
perPage: number;
hasMore: boolean;
}>;
/**
* Get all registered MCP server instances.
* @returns A record of MCP server ID to MCPServerBase instance, or undefined if none are registered.
*/
getMCPServers(): Record<string, MCPServerBase> | undefined;
/**
* Get a specific MCP server instance.
* If a version is provided, it attempts to find the server with that exact logical ID and version.
* If no version is provided, it returns the server with the specified logical ID that has the most recent releaseDate.
* The logical ID should match the `id` property of the MCPServer instance (typically set via MCPServerConfig.id).
* @param serverId - The logical ID of the MCP server to retrieve.
* @param version - Optional specific version of the MCP server to retrieve.
* @returns The MCP server instance, or undefined if not found or if the specific version is not found.
*/
getMCPServer(serverId: string, version?: string): MCPServerBase | undefined;
addTopicListener(topic: string, listener: (event: any) => Promise<void>): Promise<void>;
removeTopicListener(topic: string, listener: (event: any) => Promise<void>): Promise<void>;
startEventEngine(): Promise<void>;
stopEventEngine(): Promise<void>;
/**
* Shutdown Mastra and clean up all resources
*/
shutdown(): Promise<void>;
get serverCache(): MastraServerCache;
}
//# sourceMappingURL=index.d.ts.map