# @askrjs/server/mcp

> Published API exports for @askrjs/server/mcp.

Source: [https://askrjs.com/docs/reference/api/server/mcp](https://askrjs.com/docs/reference/api/server/mcp)

Status: stable. Packages: @askrjs/server/mcp.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 17 exports from the declarations shipped by @askrjs/server.

### `createMcpServer`

```ts
createMcpServer: <Dependencies = undefined>(options: McpServerOptions) => McpServer<Dependencies>
```

Creates a transport-neutral Model Context Protocol server: register tools, resources,
resource templates, and prompts, then feed it JSON-RPC messages via `handle` (e.g. from
{@link registerMcpRoutes }). Manages session negotiation, protocol version selection, and
list-changed notifications to subscribed clients.

### `McpContent`

```ts
McpContent: any
```

A single piece of MCP content (text, image, resource link, etc.), keyed by `type`.

- `type`: type: string;

### `McpContext`

```ts
McpContext: any
```

The per-request context passed to tool/resource/prompt handlers, exposing client info,
negotiated protocol/transport details, and `progress`/`log` callbacks for sending
notifications back to the client.

- `dependencies`: readonly dependencies: Dependencies;

- `auth`: readonly auth: AuthContext;

- `client`: readonly client: {
    name: string;
    version: string;
    title?: string;
  } | null;

- `clientCapabilities`: readonly clientCapabilities: Readonly<Record<string, unknown>>;

- `protocolRevision`: readonly protocolRevision: McpProtocolRevision;

- `transport`: readonly transport: McpTransportKind;

- `sessionId`: readonly sessionId?: string;

- `signal`: readonly signal: AbortSignal;

- `progress`: progress(progress: number, total?: number, message?: string): void | Promise<void>;

- `log`: log(level: McpLogLevel, data: unknown, logger?: string): void | Promise<void>;

### `McpLogLevel`

```ts
McpLogLevel: "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
```

Severity level for {@link McpContext.log}, following syslog conventions.

### `McpPrimitiveOptions`

```ts
McpPrimitiveOptions: any
```

Metadata shared by tools, resources, and prompts.

- `title`: title?: string;

- `description`: description?: string;

- `auth`: auth?: AuthRequirement;

- `annotations`: annotations?: Readonly<Record<string, unknown>>;

### `McpPromptOptions`

```ts
McpPromptOptions: any
```

Options for registering a prompt via {@link McpServer.prompt}.

- `arguments`: arguments?: Arguments;

### `McpProtocolRevision`

```ts
McpProtocolRevision: "2025-11-25" | "2025-06-18"
```

MCP protocol version negotiated between client and server.

### `McpRequestEnvironment`

```ts
McpRequestEnvironment: any
```

Transport-provided context for a single inbound MCP message, passed to
{@link McpServer.handle}. `send` (if provided) delivers server-to-client notifications for
push-capable transports.

- `dependencies`: dependencies: Dependencies;

- `auth`: auth: AuthContext;

- `transport`: transport: McpTransportKind;

- `sessionId`: sessionId?: string;

- `signal`: signal?: AbortSignal;

- `send`: send?(message: unknown): void | Promise<void>;

- `supportsPush`: supportsPush?: boolean;

### `McpResourceOptions`

```ts
McpResourceOptions: any
```

Options for registering a resource via {@link McpServer.resource}.

- `name`: name?: string;

- `mimeType`: mimeType?: string;

### `McpServer`

```ts
McpServer: any
```

A Model Context Protocol server, as created by {@link createMcpServer }: register tools,
resources, resource templates, and prompts; push list-changed notifications; and dispatch
inbound JSON-RPC messages via `handle`.

- `tool`: tool<const Name extends string, Input extends ObjectSchema, Output extends Schema | undefined = undefined>(name: Name, options: McpToolOptions<Input, Output>, handler: (context: McpContext<Dependencies>, input: InferSchema<Input>) => McpToolResult<Output> | Promise<McpToolResult<Output>>): McpServer<Dependencies>;

- `resource`: resource(uri: string, options: McpResourceOptions, handler: (context: McpContext<Dependencies>, uri: URL) => McpContent | readonly McpContent[] | Promise<McpContent | readonly McpContent[]>): McpServer<Dependencies>;

- `resourceTemplate`: resourceTemplate(template: string, options: McpResourceOptions & {
    complete?: (argument: string, value: string) => readonly string[] | Promise<readonly string[]>;
  }, handler: (context: McpContext<Dependencies>, uri: URL, variables: Readonly<Record<string, string>>) => McpContent | readonly McpContent[] | Promise<McpContent | readonly McpContent[]>): McpServer<Dependencies>;

- `prompt`: prompt<const Name extends string, Arguments extends ObjectSchema>(name: Name, options: McpPromptOptions<Arguments>, handler: (context: McpContext<Dependencies>, args: InferSchema<Arguments>) => {
    description?: string;
    messages: readonly unknown[];
  } | Promise<{
    description?: string;
    messages: readonly unknown[];
  }>): McpServer<Dependencies>;

- `notifyToolsChanged`: notifyToolsChanged(): Promise<void>;

- `notifyResourcesChanged`: notifyResourcesChanged(): Promise<void>;

- `notifyPromptsChanged`: notifyPromptsChanged(): Promise<void>;

- `handle`: handle(message: unknown, environment: McpRequestEnvironment<Dependencies>): Promise<unknown | undefined>;

- `terminateSession`: terminateSession(sessionId: string): void;

### `McpServerOptions`

```ts
McpServerOptions: any
```

Options for {@link createMcpServer }.

- `name`: name: string;

- `version`: version: string;

- `title`: title?: string;

- `instructions`: instructions?: string;

- `pageSize`: pageSize?: number;

### `McpSessionStore`

```ts
McpSessionStore: any
```

Pluggable backing store for stateful MCP session IDs, used by the HTTP transport.

- `create`: create(id: string): void | Promise<void>;

- `has`: has(id: string): boolean | Promise<boolean>;

- `delete`: delete(id: string): boolean | Promise<boolean>;

### `McpToolOptions`

```ts
McpToolOptions: any
```

Options for registering a tool via {@link McpServer.tool}.

- `input`: input?: Input;

- `output`: output?: Output;

### `McpToolResult`

```ts
McpToolResult: {
  content?: readonly McpContent[];
  structuredContent?: Output extends Schema ? InferSchema<Output> : unknown;
  isError?: boolean;
}
```

The result returned by a tool handler: content blocks and/or a typed structured result.

### `McpTransportKind`

```ts
McpTransportKind: "http" | "stdio"
```

The transport an MCP session is communicating over.

### `protectedResourceMetadata`

```ts
protectedResourceMetadata: (resource: string, authorizationServers?: readonly string[]) => Readonly<Record<string, unknown>>
```

Builds an OAuth 2.0 Protected Resource Metadata document (RFC 9728) advertising `resource`
and its authorization servers, as served at `/.well-known/oauth-protected-resource` by
{@link registerMcpRoutes} when `options.resource` is configured.

### `registerMcpRoutes`

```ts
registerMcpRoutes: <Dependencies>(router: Router, path: string, mcp: McpServer<Dependencies>, options: McpHttpOptions<Dependencies>) => Router
```

Registers the streamable-HTTP transport for an {@link McpServer} on a router: `POST` for
JSON-RPC requests (with optional stateful session creation), `GET` for the Server-Sent
Events notification stream, and `DELETE` for session termination. Validates the `Origin` and
`Host` headers against allowlists, enforces a max request size, and optionally serves
OAuth protected-resource metadata.

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/server/openapi/index.md) | [Next](https://askrjs.com/docs/reference/api/server/testing/index.md)
