---
title: "Scopes"
description: "Require OAuth scopes on MCP tools, resources, and prompts, advertise them in the 401 challenge, and let clients step up with a 403 insufficient_scope."
canonical_url: "https://mcp-toolkit.nuxt.dev/1.x/authentication/scopes"
---
# Scopes

> Require OAuth scopes on MCP tools, resources, and prompts, advertise them in the 401 challenge, and let clients step up with a 403 insufficient_scope.

Add `scopes` to a tool, resource, or prompt to require that the caller's access token grants all of them. The check runs before your handler, and a refused call tells the client which scopes are missing so it can ask the user for more access. Scopes require [OAuth](https://mcp-toolkit.nuxt.dev/1.x/authentication/oauth) and fail closed: on a server with plain `auth` or no authentication, any definition declaring `scopes` refuses every call.

## Require a scope

```ts [server/mcp/tools/create-project.ts]
import { z } from 'zod'
import { defineMcpTool } from '@nuxtjs/mcp-toolkit/server'
import { createProject } from '../../services/projects'

export default defineMcpTool({
  description: 'Create a project for the signed-in user',
  scopes: ['projects:write'],
  inputSchema: z.object({ name: z.string().min(1) }),
  handler: ({ name }, event) => createProject(event.context.oauth!.sub!, name),
})
```

A token must carry every listed scope. The toolkit reads granted scopes from `scope` (space-delimited, RFC 6749) and `scp` (a string or array, as Okta and Microsoft Entra ID issue it).

## What scopes protect

| Definition | Checked before |
| --- | --- |
| Tool | Each call |
| Resource | Each read, plus template `list` and `complete` |
| Prompt | Each expansion, plus argument completion |

Scoped definitions still appear in `tools/list`, `resources/list`, and `prompts/list` for any authenticated client, with their required scopes exposed in `_meta.scopes` (and on `handler.definitions`). The listing is resolved before the token is checked, so to hide that a definition exists at all, move it to a [separate server](https://mcp-toolkit.nuxt.dev/1.x/servers/overview).

When template enumeration is refused for a missing scope, `resources/list` fails as a whole rather than returning a partial list.

Select the scopes a token grants to see what it can list and call:

<auth-scope-matrix>



</auth-scope-matrix>

## Advertise scopes

The server advertises every scope its tools, resources, and prompts declare, so there is no list to keep in sync. With the definitions above, these scopes appear in the RFC 9728 protected-resource metadata and in the `scope` parameter of the `401` challenge, so a client asks for them on initial sign-in:

```http [401 challenge]
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="mcp", resource_metadata="https://example.com/.well-known/oauth-protected-resource/mcp", scope="projects:read projects:write"
```

To advertise more, add them with `extraScopes`. To advertise fewer, set `scopes` on the `oauth` options; it replaces the derived list:

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

export default defineMcpServer({
  oauth: {
    resource: 'https://example.com/mcp',
    issuer: 'https://auth.example.com',
    extraScopes: ['projects:admin'],
  },
})
```

Leave `offline_access` out. The MCP specification asks servers not to advertise it, because refresh tokens aren't a resource requirement; clients request it when the authorization server's metadata lists it.

Advertising only tells clients what to request; `scopes` on each definition enforces them.

## Show what a scope unlocks

A consent page can tell people what each scope gives access to. `oauth.scopes` on the server maps every advertised or declared scope to the names of the definitions that require it:

```ts [server/api/mcp-scopes.get.ts]
import { defineEventHandler } from 'nuxt/server'
import { mcp } from 'nitro-mcp-toolkit/servers'

export default defineEventHandler(() => mcp.oauth?.scopes)
// { 'projects:read': ['list-projects'], 'projects:write': ['create-project'], 'projects:admin': [] }
```

Advertised scopes no definition requires map to an empty list. Read the map from the server, not from the object `createMcpOAuth()` returns: that object hasn't seen the definitions yet.

## Share the values with your authorization server

An authorization server in the same app, such as Better Auth, must issue tokens for the same resource, issuer, and scopes the MCP server checks. `oauth.metadata` is the protected-resource document the server advertises, already resolved: `resource`, `authorization_servers`, and `scopes_supported`. Pass those values to the authorization server instead of building them again:

```ts
import { mcp } from 'nitro-mcp-toolkit/servers'

const { resource, authorization_servers: [issuer], scopes_supported } = mcp.oauth!.metadata
```

Read it when the authorization server is created on first use, not while its module loads. See the [admin server guide](https://mcp-toolkit.nuxt.dev/1.x/guides/admin-mcp-server#better-auth-as-the-authorization-server).

## When a scope is missing

On the modern protocol revision, a call refused for a missing scope returns HTTP `403` with an `insufficient_scope` challenge naming the scopes the token already holds plus the ones this call needs:

```http [403 step-up challenge]
HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope", scope="projects:read projects:write", resource_metadata="https://example.com/.well-known/oauth-protected-resource/mcp"
```

The JSON-RPC error body carries code `-32003` and lists both the required and missing scopes:

```json [JSON-RPC error body]
{
  "jsonrpc": "2.0",
  "id": 4,
  "error": {
    "code": -32003,
    "message": "The tool \"create-project\" requires projects:write.",
    "data": {
      "requiredScopes": ["projects:write"],
      "missingScopes": ["projects:write"]
    }
  }
}
```

A client that supports step-up authorization prompts the user to approve the extra scope and retries. Unlike `authorize` (which returns `403` with no challenge), a missing scope sends `insufficient_scope` on the modern revision, unless `authorize` [leaves that scope out for this user](https://mcp-toolkit.nuxt.dev/1.x/authentication/oauth#limit-scopes-per-user).

On the 2025 revision, the same `-32003` JSON-RPC error arrives inside a `200` response stream with no challenge header. In tests, assert on error code `-32003` rather than the HTTP status unless the test pins a protocol revision.

## Scopes and service tokens

A [service token](https://mcp-toolkit.nuxt.dev/1.x/authentication/service-tokens) declares its scopes in `claims.scope`, so the exact same scope checks apply to it.

## Scopes do not replace ownership checks

A scope says what kind of action a token allows, such as writing projects. It doesn't say which projects belong to the caller. Always pass the verified `sub` (and tenant) from `event.context.oauth` to your services and filter records by it.


## Sitemap

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