---
title: "Server file (index.ts)"
description: "Configure an MCP server's name, instructions, icons, OAuth, and access policy in server/mcp/index.ts with defineMcpServer, read at request time."
canonical_url: "https://mcp-toolkit.nuxt.dev/1.x/servers/server-file"
---
# Server file (index.ts)

> Configure an MCP server's name, instructions, icons, OAuth, and access policy in server/mcp/index.ts with defineMcpServer, read at request time.

Each server directory can contain an `index.ts` that default-exports `defineMcpServer()`. It holds what clients see about the server, such as its name and instructions, and how it authenticates requests. Unlike `nuxt.config.ts`, `index.ts` runs on the server at request time, so it can read private runtime config and use callbacks.

## Describe the server

```ts [server/mcp/index.ts]
import { defineMcpServer } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpServer({
  name: 'Acme',
  description: 'Search Acme docs, look up orders, and check service status.',
  websiteUrl: 'https://acme.com/docs/mcp',
  icons: [{ src: 'https://acme.com/icon.png', mimeType: 'image/png', sizes: ['64x64'] }],
  instructions: `The official source for Acme's docs and order data.

- Questions about the product: \`search-docs\`, then \`get-page\` for a full page.
- Orders: \`get-order\` with the order ID. Never guess IDs.

Paths and IDs come from the tools; don't invent them.`,
})
```

`instructions` is sent to the client when it connects and usually ends up in the model's context. State what the server is for, which tool fits each question, and any rules the model must follow. It's the most effective place to steer tool selection.

The install [deeplink](https://mcp-toolkit.nuxt.dev/1.x/getting-started/connection#install-buttons) and the [`llms.txt` section](https://mcp-toolkit.nuxt.dev/1.x/advanced/tooling/llms-txt) read each server's `name`, `description`, and `websiteUrl` from this file.

## Authenticate requests

```ts [server/mcp-admin/index.ts]
import { defineMcpServer } from '@nuxtjs/mcp-toolkit/server'
import { betterAuth } from '@nuxtjs/mcp-toolkit/oauth/better-auth'
import { isAdmin } from '../utils/admins'

export default defineMcpServer({
  name: 'admin',
  instructions: 'Team-only tools for feedback and analytics.',
  oauth: betterAuth(),
  authorize: ({ sub }) => isAdmin(sub),
})
```

- `oauth` takes OAuth options, written inline or returned by a [provider adapter](https://mcp-toolkit.nuxt.dev/1.x/authentication/providers). The module mounts its RFC 9728 discovery metadata automatically, advertises the scopes the server's definitions declare, and defaults `resource` to the server's route on the site's public origin.
- `auth` takes bearer-token or API-key options with a `validate` callback. See [authentication](https://mcp-toolkit.nuxt.dev/1.x/authentication/overview).
- `authorize(identity, event)` requires `oauth` and runs after token verification for a server-wide policy. Returning `false` answers `403`.

`oauth` lives only here; `nuxt.config.ts` refuses it. You can't combine `auth` and `oauth` on one server, and you can't set `auth` in both `index.ts` and `nuxt.config.ts` for the same server.

## All options

| Option | Description |
| --- | --- |
| `name`, `version`, `title` | Advertised to clients when they connect |
| `description` | What the server is, for people browsing a client's server list |
| `icons` | Icons shown next to the server name |
| `websiteUrl` | Where people can read more |
| `instructions` | Guidance the client gives the model |
| `oauth` | A prepared OAuth resource server |
| `auth` | Bearer token or API key options |
| `authorize` | Server-wide access policy after OAuth verification |
| `era` | `'dual'` (default), `'modern'`, or `'legacy'`. See [protocol](https://mcp-toolkit.nuxt.dev/1.x/advanced/protocol/runtimes). |
| `session` | Legacy protocol sessions. See [state and sessions](https://mcp-toolkit.nuxt.dev/1.x/advanced/runtime/state-sessions). |
| `logging` | Advertise client logging support |
| `limits` | Request body, batch, and content-type limits |
| `origin` | Browser origins allowed. See [security](https://mcp-toolkit.nuxt.dev/1.x/authentication/hardening). |
| `observers` | Observers that watch requests, calls, and authentication decisions. See [observability](https://mcp-toolkit.nuxt.dev/1.x/observability/hooks-observers). |

Values in `index.ts` override the same non-auth options from `nuxt.config.ts`. `route` and `dir` can only be set in `nuxt.config.ts`.

## Rules

- **One file per directory.** Use `index.ts`, `index.js`, `index.mts`, or `index.mjs`. Two index files in one directory fail the build.
- **First root wins.** With several [directories or layers](https://mcp-toolkit.nuxt.dev/1.x/servers/directories-layers), the first root containing an index file provides it. Your app comes before extended layers.
- **Invalid exports refuse requests.** A default export that isn't a valid server config, a mismatched OAuth resource path, or conflicting authentication makes the endpoint error rather than run unprotected.
- **Hot reload.** Adding or removing an index file in development triggers a rebuild.

## A separate auth file

Authentication can also live in its own file, referenced from `nuxt.config.ts`. The file default-exports `defineMcpAuth()` options:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['@nuxtjs/mcp-toolkit'],
  runtimeConfig: { mcpToken: '' },
  mcp: { auth: './server/mcp-auth.ts' },
})
```

```ts [server/mcp-auth.ts]
import { useRuntimeConfig } from 'nuxt/server'
import { defineMcpAuth } from '@nuxtjs/mcp-toolkit/server'

export default defineMcpAuth({
  validate: ({ token }) => {
    const expected = useRuntimeConfig().mcpToken
    return Boolean(expected) && token === expected
  },
})
```

The path is relative to the project root, and Nuxt aliases or absolute paths also work. A missing file fails the build, and an invalid export refuses requests. Prefer `index.ts` for new servers so metadata and authentication stay together.

## Next

- [Overlay directories and Nuxt layers](https://mcp-toolkit.nuxt.dev/1.x/servers/directories-layers).
- [Choose an authentication strategy](https://mcp-toolkit.nuxt.dev/1.x/authentication/overview) for your server.


## Sitemap

See the full [sitemap](https://mcp-toolkit.nuxt.dev/sitemap.md) for all pages.
