New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mastra/client-js

Package Overview
Dependencies
Maintainers
11
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mastra/client-js

The official TypeScript library for the Mastra Client API

  • 0.0.0-storage-20250225005900
  • storage
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.8K
decreased by-1.56%
Maintainers
11
Weekly downloads
 
Created
Source

Mastra Client

JavaScript/TypeScript client library for the Mastra AI framework. This client provides a simple interface to interact with Mastra AI's APIs for agents, vectors, memory, tools, and workflows.

Installation

npm install @mastra/client-js

Quick Start

import { MastraClient } from '@mastra/client';

// Initialize the client
const client = new MastraClient({
  baseUrl: 'http://localhost:4111', // Your Mastra API endpoint
});

// Example: Working with an Agent
async function main() {
  // Get an agent instance
  const agent = client.getAgent('your-agent-id');

  // Generate a response
  const response = await agent.generate({
    messages: [{ role: 'user', content: "What's the weather like today?" }],
  });

  console.log(response);
}

Client Configuration

The client can be configured with several options:

const client = new MastraClient({
    baseUrl: string;           // Base URL for the Mastra API
    retries?: number;          // Number of retry attempts (default: 3)
    backoffMs?: number;        // Initial backoff time in ms (default: 300)
    maxBackoffMs?: number;     // Maximum backoff time in ms (default: 5000)
    headers?: Record<string, string>; // Custom headers
});

Available Methods

Agents

  • getAgents(): Get all available agents
  • getAgent(agentId): Get a specific agent instance
    • agent.details(): Get agent details
    • agent.generate(params): Generate a response
    • agent.stream(params): Stream a response
    • agent.getTool(toolId): Get agent tool details
    • agent.evals(): Get agent evaluations
    • agent.liveEvals(): Get live evaluations

Memory

  • getMemoryThreads(params): Get memory threads
  • createMemoryThread(params): Create a new memory thread
  • getMemoryThread(threadId): Get a memory thread instance
  • saveMessageToMemory(params): Save messages to memory
  • getMemoryStatus(): Get memory system status

Tools

  • getTools(): Get all available tools
  • getTool(toolId): Get a tool instance
    • tool.details(): Get tool details
    • tool.execute(params): Execute the tool

Workflows

  • getWorkflows(): Get all workflows
  • getWorkflow(workflowId): Get a workflow instance
    • workflow.details(): Get workflow details
    • workflow.execute(params): Execute the workflow
    • workflow.watch(params): Watch the workflow
    • workflow.resume(params): Resume the workflow

Vectors

  • getVector(vectorName): Get a vector instance
    • vector.details(indexName): Get vector index details
    • vector.delete(indexName): Delete a vector index
    • vector.getIndexes(): Get all indexes
    • vector.createIndex(params): Create a new index
    • vector.upsert(params): Upsert vectors
    • vector.query(params): Query vectors

Logs

  • getLogs(params): Get system logs
  • getLog(params): Get specific log entry
  • getLogTransports(): Get configured Log transports

Telemetry

  • getTelemetry(params): Get telemetry data

Error Handling

The client includes built-in retry logic for failed requests:

  • Automatically retries failed requests with exponential backoff
  • Configurable retry count and backoff timing
  • Throws error after max retries reached

Internal Implementation

The client uses the native fetch API internally for making HTTP requests. All requests are automatically handled with:

  • JSON serialization/deserialization
  • Retry logic with exponential backoff
  • Custom header management
  • Error handling

License

MIT

FAQs

Package last updated on 25 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc