Askr documentation
Generated API snapshot

@askrjs/server/mcp

Exports from the declarations published in @askrjs/server. Signatures reflect the published artifact.

Exports

This entrypoint publishes 17 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

createMcpServertype

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.

McpContenttype

McpContent: any

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

type
type: string;

McpContexttype

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>;

McpLogLeveltype

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

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

McpPrimitiveOptionstype

McpPrimitiveOptions: any

Metadata shared by tools, resources, and prompts.

title
title?: string;
description
description?: string;
auth
auth?: AuthRequirement;
annotations
annotations?: Readonly<Record<string, unknown>>;

McpPromptOptionstype

McpPromptOptions: any

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

arguments
arguments?: Arguments;

McpProtocolRevisiontype

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

MCP protocol version negotiated between client and server.

McpRequestEnvironmenttype

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;

McpResourceOptionstype

McpResourceOptions: any

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

name
name?: string;
mimeType
mimeType?: string;

McpServertype

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;

McpServerOptionstype

McpServerOptions: any

Options for {@link createMcpServer }.

name
name: string;
version
version: string;
title
title?: string;
instructions
instructions?: string;
pageSize
pageSize?: number;

McpSessionStoretype

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>;

McpToolOptionstype

McpToolOptions: any

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

input
input?: Input;
output
output?: Output;

McpToolResulttype

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.

McpTransportKindtype

McpTransportKind: "http" | "stdio"

The transport an MCP session is communicating over.

protectedResourceMetadatatype

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.

registerMcpRoutestype

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.