Skip to main content
Defined in: server/context.ts:83

Properties

auth

Defined in: server/context.ts:85 Auth token for the current request, if any.

http

Defined in: server/context.ts:98 The HTTP request carrying the current MCP message, when serving over an HTTP transport; undefined on stdio. Fresh per request: on a sessionful connection each request’s own headers appear here, never the initialize-time ones. Credential headers are withheld by default and listed in http.redactedHeaderNames (tune with FastMCPOptions.http). Untrusted input; see HttpRequestContext’s docs before deriving any authorization from it.

inputResponses

Defined in: server/context.ts:174 The current round’s embedded input responses, when this request is a retry of an earlier inputRequired(...) return. undefined on the flow’s first call (no prior round to respond to). Read with the SDK’s acceptedContent(ctx.inputResponses, key) / inputResponse(ctx.inputResponses, key) (re-exported from fastmcp-ts/server) rather than indexing this object directly — those readers validate shape and, for acceptedContent, optionally the content against a schema.

requestId

Defined in: server/context.ts:87 The MCP request ID for the current call.

Methods

alert()

Defined in: server/context.ts:110

Parameters

message
string
loggerName?
string

Returns

Promise<void>

critical()

Defined in: server/context.ts:109

Parameters

message
string
loggerName?
string

Returns

Promise<void>

debug()

Defined in: server/context.ts:104

Parameters

message
string
loggerName?
string

Returns

Promise<void>

deleteState()

Defined in: server/context.ts:201 Remove a value from session-scoped state.

Parameters

key
string

Returns

void

elicit()

Defined in: server/context.ts:149 Ask the client to collect input from the user via a form dialog. Throws if the client has not advertised the elicitation capability.

Parameters

message
string
schema
ElicitationSchema

Returns

Promise<ElicitationResult>

Deprecated

Throws a clear error naming the replacement when called on a modern (2026-07-28) request — return inputRequired({ inputRequests: { id: inputRequired.elicit({...}) } }) instead (see ctx.sample’s docs; the same write-once, serve-both-eras guidance applies).

emergency()

Defined in: server/context.ts:111

Parameters

message
string
loggerName?
string

Returns

Promise<void>

error()

Defined in: server/context.ts:108

Parameters

message
string
loggerName?
string

Returns

Promise<void>

getState()

Defined in: server/context.ts:197 Retrieve a value from session-scoped state. Returns undefined if not set.

Parameters

key
string

Returns

unknown

info()

Defined in: server/context.ts:105

Parameters

message
string
loggerName?
string

Returns

Promise<void>

listRoots()

Defined in: server/context.ts:162 Request the list of filesystem roots the client has declared. Throws if the client has not advertised the roots capability.

Returns

Promise<Root[]>

Deprecated

Roots is deprecated as of protocol revision 2026-07-28 (SEP-2577) — prefer passing paths via tool parameters, resource URIs, or server configuration. Throws a clear error naming inputRequired(...) as the multi-round-trip replacement when called on a modern request (see ctx.sample’s docs).

log()

Defined in: server/context.ts:103 Send a log message to the client at the specified RFC 5424 severity level.

Parameters

level
LogLevel
message
string
loggerName?
string

Returns

Promise<void>

mintRequestState()

Defined in: server/context.ts:192 Seals payload into the opaque requestState string to return from inputRequired({ requestState }). HMAC-signed via FastMCPOptions.requestState when configured; otherwise a plain JSON.stringify(payload) with a console warning — the resulting state is unsigned and MUST NOT be trusted for anything that influences authorization, resource access, or business logic (the client can read and tamper with it) unless FastMCPOptions.requestState is set.

Type Parameters

T
T = unknown

Parameters

payload
T

Returns

Promise<string>

notice()

Defined in: server/context.ts:106

Parameters

message
string
loggerName?
string

Returns

Promise<void>

onClose()

Defined in: server/context.ts:219 Register a callback that runs when the current session closes. Useful for releasing per-session resources (e.g. uploaded files). No-op if called outside an active HTTP session.

Parameters

callback
() => void

Returns

void

reportProgress()

Defined in: server/context.ts:119 Send a progress notification to the client. No-op if the request did not include a progressToken in its _meta.

Parameters

progress
number
total?
number
message?
string

Returns

Promise<void>

requestState()

Defined in: server/context.ts:182 Reads the current round’s requestState, already verified and decoded when FastMCPOptions.requestState is configured (the payload verify resolved with); the raw, unverified wire string when it is not configured — treat that case as attacker-controlled input. undefined when the round carried no state.

Type Parameters

T
T = unknown

Returns

T | undefined

resolveToolName()

Defined in: server/context.ts:210 Resolve a logical tool name to its current external name, accounting for any namespace prefix applied when the owning FastMCPApp was mounted. Returns the name unchanged when called outside a mounted context.

Parameters

name
string

Returns

string

sample()

Defined in: server/context.ts:136 Ask the client to perform an LLM inference call and return the result. Throws if the client has not advertised the sampling capability.

Parameters

params
SamplingParams

Returns

Promise<SamplingResult>

Deprecated

Sampling is deprecated as of protocol revision 2026-07-28 (SEP-2577) and this push-style call only works on a legacy (2025-era) connection — calling it on a modern request throws a clear error naming the replacement (return inputRequired({ inputRequests: { id: inputRequired.createMessage({...}) } }) from the handler instead; see fastmcp-ts/server’s re-exported inputRequired). A handler written the inputRequired way serves both eras unchanged — the SDK’s legacy shim fulfils it via a real server→client request on 2025-era connections, so there is rarely a reason to keep calling ctx.sample() directly in new code.

setState()

Defined in: server/context.ts:199 Store a value in session-scoped state. Persists for the lifetime of the session.

Parameters

key
string
value
unknown

Returns

void

warning()

Defined in: server/context.ts:107

Parameters

message
string
loggerName?
string

Returns

Promise<void>