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

Properties

auth

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

inputResponses

Defined in: server/context.ts:160 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:84 The MCP request ID for the current call.

Methods

alert()

Defined in: server/context.ts:96

Parameters

message
string
loggerName?
string

Returns

Promise<void>

critical()

Defined in: server/context.ts:95

Parameters

message
string
loggerName?
string

Returns

Promise<void>

debug()

Defined in: server/context.ts:90

Parameters

message
string
loggerName?
string

Returns

Promise<void>

deleteState()

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

Parameters

key
string

Returns

void

elicit()

Defined in: server/context.ts:135 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:97

Parameters

message
string
loggerName?
string

Returns

Promise<void>

error()

Defined in: server/context.ts:94

Parameters

message
string
loggerName?
string

Returns

Promise<void>

getState()

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

Parameters

key
string

Returns

unknown

info()

Defined in: server/context.ts:91

Parameters

message
string
loggerName?
string

Returns

Promise<void>

listRoots()

Defined in: server/context.ts:148 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:89 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:178 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:92

Parameters

message
string
loggerName?
string

Returns

Promise<void>

onClose()

Defined in: server/context.ts:205 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:105 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:168 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:196 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:122 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:185 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:93

Parameters

message
string
loggerName?
string

Returns

Promise<void>