> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# FrontMcpServer

> FrontMcpServer manages the HTTP server interface for FrontMCP. It supports multiple host adapters (Express, Fastify, etc.) and both server and serverless deployments.

## Class Definition

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
export class FrontMcpServerInstance extends FrontMcpServer {
  config: HttpOptions;
  host: HostServerAdapter;
}
```

## Properties

| Property | Type                | Description                  |
| -------- | ------------------- | ---------------------------- |
| `config` | `HttpOptions`       | HTTP configuration           |
| `host`   | `HostServerAdapter` | Host adapter (Express, etc.) |

## Methods

### registerMiddleware(entryPath, handler)

Register middleware at a specific entry path.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
registerMiddleware(entryPath: string, handler: ServerRequestHandler): void
```

### registerRoute(method, path, handler)

Register an HTTP route.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
registerRoute(
  method: HttpMethod,
  path: string,
  handler: ServerRequestHandler
): void
```

### prepare()

Prepare routes without starting the server.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
prepare(): void
```

* Registers `/health` endpoint automatically
* Prepares all configured routes
* Call before `getHandler()` for serverless

### getHandler()

Get the underlying HTTP handler for serverless export.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
getHandler(): unknown
```

Returns the host adapter's handler (e.g., Express app).

### start()

Start the HTTP server on the configured port.

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
start(): void
```

## HttpOptions

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
interface HttpOptions {
  port?: number;                      // default 3001
  entryPath?: string;                 // MCP JSON-RPC entry path (default: '')
  hostFactory?: HostFactory;          // Custom host adapter
  socketPath?: string;                // Unix socket path (overrides port)
  cors?: CorsOptions | false;         // CORS config (default: permissive with built-in adapter)
}
```

## Host Adapters

### Default (Express)

Express is the default host adapter:

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
@FrontMcp({
  info: { name: 'Server', version: '1.0.0' },
  apps: [MyApp],
  http: { port: 3001 },
  // Uses ExpressHostAdapter by default
})
```

### Custom Host Factory

Provide a custom host adapter:

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { FastifyHostAdapter } from './adapters/fastify';

@FrontMcp({
  info: { name: 'Server', version: '1.0.0' },
  apps: [MyApp],
  http: {
    port: 3000,
    hostFactory: (config) => new FastifyHostAdapter(config),
  },
})
```

### Host Adapter Interface

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
export abstract class HostServerAdapter extends FrontMcpServer {
  abstract prepare(): void;
  abstract getHandler(): unknown;
  abstract start(port: number): Promise<void> | void;
}
```

## Usage Examples

### Standard Deployment

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { FrontMcpInstance } from '@frontmcp/sdk';
import config from './server';

// bootstrap() handles server creation and start
await FrontMcpInstance.bootstrap(config);
```

### Manual Server Access

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import { FrontMcpInstance, FrontMcpServer } from '@frontmcp/sdk';

const instance = await FrontMcpInstance.createForGraph(config);
await instance.ready;

// Access server from providers
const server = instance.providers.get(FrontMcpServer);

// Register additional routes
server.registerRoute('GET', '/custom', (req, res) => {
  res.json({ custom: true });
});

// Start server
server.start();
```

### Serverless Deployment

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// api/mcp.ts
import { FrontMcpInstance } from '@frontmcp/sdk';
import config from '../src/server';

// createHandler() prepares and returns the handler
export default FrontMcpInstance.createHandler(config);
```

### Custom CORS

```typescript theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
@FrontMcp({
  info: { name: 'Server', version: '1.0.0' },
  apps: [MyApp],
  http: {
    port: 3001,
    cors: {
      origin: ['https://app.example.com', 'http://localhost:3000'],
      credentials: true,
      maxAge: 86400,
    },
  },
})
```

## Health Endpoint

FrontMCP automatically registers a `/health` endpoint:

```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
curl http://localhost:3001/health
# {"status":"ok"}
```

This is useful for:

* Load balancer health checks
* Kubernetes liveness probes
* Monitoring systems

## Related

<CardGroup cols={2}>
  <Card title="FrontMcpInstance" icon="server" href="/frontmcp/sdk-reference/core/frontmcp-instance">
    Server bootstrap
  </Card>

  <Card title="@FrontMcp" icon="at" href="/frontmcp/sdk-reference/decorators/frontmcp">
    Server configuration
  </Card>

  <Card title="Serverless Deployment" icon="cloud" href="/frontmcp/deployment/serverless">
    Serverless guide
  </Card>

  <Card title="Production Build" icon="rocket" href="/frontmcp/deployment/production-build">
    Production deployment
  </Card>
</CardGroup>
