---
title: "Server Overview | Server"
description: "Overview of the Mastra server, covering HTTP endpoints, middleware, authentication, and client integration."
packages:
  - "@mastra/core"
---

# Server Overview

Mastra runs as an HTTP server that exposes your agents, workflows, and other functionality as API endpoints. The server handles request routing, middleware execution, authentication, and streaming responses.

:::info

This page covers the [`server`](/reference/v1/configuration#server-options) configuration options passed to the `Mastra` constructor. For running Mastra with your own HTTP server (Hono, Express, etc.), visit [Server Adapters](/docs/v1/server/server-adapters).

:::

## Server architecture

Mastra uses [Hono](https://hono.dev) as its underlying HTTP server framework. When you build a Mastra application using `mastra build`, it generates a Hono-based HTTP server in the `.mastra` directory.

The server provides:

- API endpoints for all registered agents and workflows
- Custom API routes and middleware
- Authentication with multiple providers
- Request context for dynamic configuration
- Stream data redaction for secure responses

## Configuration

Configure the server by passing a `server` object to the `Mastra` constructor:

```typescript title="src/mastra/index.ts"
import { Mastra } from "@mastra/core";

export const mastra = new Mastra({
  server: {
    port: 3000, // Defaults to 4111
    host: "0.0.0.0", // Defaults to 'localhost'
  },
});
```

:::info

Visit the [configuration reference](/reference/v1/configuration#server-options) for a full list of available server options.

:::

## Server features

- **[Middleware](/docs/v1/server/middleware)**: Intercept requests for authentication, logging, CORS, or injecting request-specific context.
- **[Custom API Routes](/docs/v1/server/custom-api-routes)**: Extend the server with your own HTTP endpoints that have access to the Mastra instance.
- **[Request Context](/docs/v1/server/request-context)**: Pass request-specific values to agents, tools, and workflows based on runtime conditions.
- **[Server Adapters](/docs/v1/server/server-adapters)**: Run Mastra with Express, Hono, or your own HTTP server instead of the generated server.
- **[Custom Adapters](/docs/v1/server/custom-adapters)**: Build adapters for frameworks not officially supported.
- **[Mastra Client SDK](/docs/v1/server/mastra-client)**: Type-safe client for calling agents, workflows, and tools from browser or server environments.
- **[Authentication](/docs/v1/server/auth)**: Secure endpoints with JWT, Clerk, Supabase, Firebase, Auth0, or WorkOS.

## Stream data redaction

When streaming agent responses, the HTTP layer redacts system prompts, tool definitions, API keys, and similar data from each chunk before sending it to clients. This is enabled by default.

This behavior is only configurable by using [server adapters](/docs/v1/server/server-adapters#stream-data-redaction). For server adapters, stream data redaction is enabled by default, too.

## TypeScript configuration

Mastra requires `module` and `moduleResolution` settings compatible with modern Node.js. Legacy options like `CommonJS` or `node` are not supported.

```json {4-5} title="tsconfig.json"
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "noEmit": true,
    "outDir": "dist"
  },
  "include": ["src/**/*"]
}
```
