Skip to main content

McpOperationContext

@webda/mcp


Class: McpOperationContext

Defined in: packages/mcp/src/invoke.ts:24

Operation context used for MCP calls: collects AsyncGenerator chunks instead of concatenating them into the output, and stops on cancellation.

Extends​

  • SimpleOperationContext

Properties​

_body​

protected _body: string

Defined in: packages/core/lib/contexts/operationcontext.d.ts:36

Output

Inherited from​

SimpleOperationContext._body


_modes​

protected _modes: string | null | undefined

Defined in: packages/core/lib/contexts/operationcontext.d.ts:32

The sanitization modes (path and mode) the cached body was sanitized with, null when the input was cleared

Inherited from​

SimpleOperationContext._modes


_promises​

_promises: Promise<any>[]

Defined in: packages/core/lib/contexts/icontext.d.ts:29

Contain all registered promises to this context

Inherited from​

SimpleOperationContext._promises


_sanitized​

protected _sanitized: any

Defined in: packages/core/lib/contexts/operationcontext.d.ts:28

Contain the sanitized request body if computed

Inherited from​

SimpleOperationContext._sanitized


_stream​

_stream: Writable

Defined in: packages/core/lib/contexts/operationcontext.d.ts:58

Output stream

Inherited from​

SimpleOperationContext._stream


caches​

caches: any

Defined in: packages/core/lib/contexts/icontext.d.ts:15

Get the caches linked to the context

Inherited from​

SimpleOperationContext.caches


chunks​

chunks: unknown[] = []

Defined in: packages/mcp/src/invoke.ts:28

Chunks yielded by a streaming operation


extensions​

protected extensions: object

Defined in: packages/core/lib/contexts/icontext.d.ts:19

Allow extensions

Index Signature​

[key: string]: any

Inherited from​

SimpleOperationContext.extensions


flushed​

protected flushed: boolean

Defined in: packages/core/lib/contexts/icontext.d.ts:33

If the headers were flushed

Inherited from​

SimpleOperationContext.flushed


httpContext?​

protected optional httpContext?: HttpContext

Defined in: packages/mcp/src/invoke.ts:40

The MCP HTTP request, reduced to its forwarded headers (see McpService forwardHeaders)


input​

input: Buffer

Defined in: packages/core/lib/contexts/simplecontext.d.ts:10

Input

Inherited from​

SimpleOperationContext.input


onChunk?​

optional onChunk?: (chunk, index) => void

Defined in: packages/mcp/src/invoke.ts:36

Called for every streamed chunk with its 1-based index

Parameters​

chunk​

unknown

index​

number

Returns​

void


parameters​

parameters: any

Defined in: packages/core/lib/contexts/operationcontext.d.ts:44

Parameters

Inherited from​

SimpleOperationContext.parameters


session​

protected session: Session

Defined in: packages/core/lib/contexts/operationcontext.d.ts:24

Session

Inherited from​

SimpleOperationContext.session


signal?​

optional signal?: AbortSignal

Defined in: packages/mcp/src/invoke.ts:32

Abort signal of the MCP request

Methods​

addAsyncRequest()​

addAsyncRequest(promise): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:93

Register a promise with the context

Parameters​

promise​

any

the promise to add

Returns​

void

Inherited from​

SimpleOperationContext.addAsyncRequest


clearInput()​

clearInput(): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:106

Remove the input

Returns​

void

Inherited from​

SimpleOperationContext.clearInput


createStream()​

createStream(): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:162

Create a buffer stream

Returns​

void

Inherited from​

SimpleOperationContext.createStream


drained()​

drained(): Promise<void>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:182

Resolves when the client can take more streamed output. callOperation awaits it whenever write() returned false; transports with a real connection override it (backpressure, cancellation).

Returns​

Promise<void>

when more output can be written

Inherited from​

SimpleOperationContext.drained


end()​

end(): Promise<void>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:102

Ensure the whole execution is finished

Returns​

Promise<void>

Inherited from​

SimpleOperationContext.end


flushHeaders()​

flushHeaders(): Promise<void>

Defined in: packages/core/lib/contexts/icontext.d.ts:100

Send the headers to the client

Returns​

Promise<void>

Inherited from​

SimpleOperationContext.flushHeaders


getCurrentUser()​

getCurrentUser<K>(refresh?): Promise<K>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:193

Get the current user from session

Type Parameters​

K​

K extends IUser

Parameters​

refresh?​

boolean

whether to refresh

Returns​

Promise<K>

the result

Inherited from​

SimpleOperationContext.getCurrentUser


getCurrentUserId()​

getCurrentUserId(): string

Defined in: packages/core/lib/contexts/operationcontext.d.ts:201

Get the current user id from session

A session waiting for its second factor (mfa: "pending") is not logged: it has no current user. Code that needs the pending user reads getSession().userId.

Returns​

string

the result

Inherited from​

SimpleOperationContext.getCurrentUserId


getExtension()​

getExtension<K>(name): K

Defined in: packages/core/lib/contexts/operationcontext.d.ts:64

Get an extension of the context

Type Parameters​

K​

K = any

Parameters​

name​

string

of the extension

Returns​

K

extension object

Inherited from​

SimpleOperationContext.getExtension


getHttpContext()​

getHttpContext(): HttpContext | undefined

Defined in: packages/mcp/src/invoke.ts:56

The MCP HTTP request carrying only its forwarded headers; undefined over stdio or when none is forwarded

Returns​

HttpContext | undefined

the reduced request


getInput()​

getInput(sanitizedOptions?): Promise<any>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:121

Get the sanitized input body, caching the result after the first call

Every string is HTML-sanitized, except:

  • with raw: true, nothing is (the parsed body is returned as received, and not cached);
  • with raw: [paths], the values of these keys, whatever they hold;
  • with modes: { path: mode }, the strings at these paths (* for any array index or object key), sanitized with their mode (none, html, markdown): what an operation input schema declares with x-webda-sanitize.

The body is read again when raw is given, or when modes differs from the one of the cached body: a change made to a body read before is lost, so read it once with the options you need.

Parameters​

sanitizedOptions?​

IOptions & object & object

the sanitized options

Returns​

Promise<any>

the result

Inherited from​

SimpleOperationContext.getInput


getOutput()​

getOutput(): string

Defined in: packages/core/lib/contexts/operationcontext.d.ts:98

Get output as string, if a OutputStream is provided it will returned null

Returns​

string

the result string

Inherited from​

SimpleOperationContext.getOutput


getOutputStream()​

getOutputStream(): Promise<Writable>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:144

Get the HTTP stream to output raw data

Returns​

Promise<Writable>

the result

Inherited from​

SimpleOperationContext.getOutputStream


getParameters()​

getParameters(): any

Defined in: packages/core/lib/contexts/operationcontext.d.ts:76

Get the parameters

Returns​

any

the result

Inherited from​

SimpleOperationContext.getParameters


getRawInput()​

getRawInput(limit?, _timeout?): Promise<Buffer<ArrayBufferLike>>

Defined in: packages/core/lib/contexts/simplecontext.d.ts:32

Parameters​

limit?​

number

_timeout?​

number

Returns​

Promise<Buffer<ArrayBufferLike>>

Inherited from​

SimpleOperationContext.getRawInput


getRawInputAsString()​

getRawInputAsString(limit?, timeout?, encoding?): Promise<string>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:131

By default empty

Parameters​

limit?​

number

the maximum count

timeout?​

number

the timeout in milliseconds

encoding?​

BufferEncoding

the encoding to use

Returns​

Promise<string>

the result string

Inherited from​

SimpleOperationContext.getRawInputAsString


getRawStream()​

getRawStream(): Readable

Defined in: packages/core/lib/contexts/operationcontext.d.ts:139

Returns​

Readable

Inherited from​

SimpleOperationContext.getRawStream


getResponseHeaders()​

getResponseHeaders(): any

Defined in: packages/core/lib/contexts/icontext.d.ts:96

Get current response headers

Returns​

any

the result

Inherited from​

SimpleOperationContext.getResponseHeaders


getSession()​

getSession<K>(): K

Defined in: packages/core/lib/contexts/operationcontext.d.ts:149

Get linked session

Type Parameters​

K​

K = Session

Returns​

K

the result

Inherited from​

SimpleOperationContext.getSession


init()​

init(): Promise<McpOperationContext>

Defined in: packages/core/lib/contexts/operationcontext.d.ts:187

Initialize the operation context

Returns​

Promise<McpOperationContext>

this for chaining

Inherited from​

SimpleOperationContext.init


isGlobalContext()​

isGlobalContext(): boolean

Defined in: packages/core/lib/contexts/icontext.d.ts:38

Whether this is the global (non-request-scoped) context

Returns​

boolean

true if the condition is met

Inherited from​

SimpleOperationContext.isGlobalContext


newSession()​

newSession(): Session

Defined in: packages/core/lib/contexts/operationcontext.d.ts:154

Create and assign a new empty session

Returns​

Session

the result

Inherited from​

SimpleOperationContext.newSession


parameter()​

parameter(name, defaultValue?): any

Defined in: packages/core/lib/contexts/operationcontext.d.ts:71

Get one parameter

Parameters​

name​

string

the name to use

defaultValue?​

any

the default value

Returns​

any

the result

Inherited from​

SimpleOperationContext.parameter


pipeline()​

pipeline(stream1, ...streams): Promise<void>

Defined in: packages/core/lib/contexts/icontext.d.ts:108

Pipeline streams into the output stream

Parameters​

stream1​

ReadableStream

the first stream

streams​

...(ReadWriteStream | PipelineOptions)[]

additional streams

Returns​

Promise<void>

See​

https://nodejs.org/api/stream.html#streampipelinestreams-options

Inherited from​

SimpleOperationContext.pipeline


registerPromise()​

registerPromise(promise): void

Defined in: packages/core/lib/contexts/icontext.d.ts:47

Register a promise with the context

Parameters​

promise​

any

the promise to add

Returns​

void

Inherited from​

SimpleOperationContext.registerPromise


reinit()​

reinit(): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:158

Remove sanitized body

Returns​

void

Inherited from​

SimpleOperationContext.reinit


resetResponse()​

resetResponse(): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:166

Remove everything that was about to be sent

Returns​

void

Inherited from​

SimpleOperationContext.resetResponse


setExtension()​

setExtension(name, extension): this

Defined in: packages/core/lib/contexts/operationcontext.d.ts:88

Set the extension

Parameters​

name​

string

to add

extension​

any

object to store

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.setExtension


setHeader()​

setHeader(name, value): void

Defined in: packages/core/lib/contexts/icontext.d.ts:83

Set a header in the response

Parameters​

name​

string

the name to use

value​

string | number | string[]

the value to set

Returns​

void

Inherited from​

SimpleOperationContext.setHeader


setHttpContext()​

setHttpContext(http): this

Defined in: packages/mcp/src/invoke.ts:47

Set the HTTP context

Parameters​

http​

HttpContext | undefined

the reduced MCP HTTP request

Returns​

this

this


setInput()​

setInput(input): this

Defined in: packages/core/lib/contexts/simplecontext.d.ts:22

Set the input

Parameters​

input​

Buffer

the input

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.setInput


setParameters()​

setParameters(params): void

Defined in: packages/core/lib/contexts/operationcontext.d.ts:81

Set the parameters

Parameters​

params​

any

the service parameters

Returns​

void

Inherited from​

SimpleOperationContext.setParameters


setSession()​

setSession(session): this

Defined in: packages/core/lib/contexts/simplecontext.d.ts:28

Set the session

Parameters​

session​

Session

the session object

Returns​

this

this for chaining

Inherited from​

SimpleOperationContext.setSession


write()​

write(output, encoding?, cb?): boolean

Defined in: packages/mcp/src/invoke.ts:67

Write operation

Parameters​

output​

any

chunk or result

encoding?​

any

unused for chunks

cb?​

any

unused for chunks

Returns​

boolean

true

Overrides​

SimpleOperationContext.write


writeHead()​

writeHead(_code, headers): void

Defined in: packages/core/lib/contexts/icontext.d.ts:89

For easier compatibility with WebContext On OperationContext this call is simply ignored

Parameters​

_code​

number

the status code

headers​

{[key: string]: string | number | string[]; }

Returns​

void

Inherited from​

SimpleOperationContext.writeHead


fromContext()​

static fromContext(context): Promise<SimpleOperationContext>

Defined in: packages/core/lib/contexts/simplecontext.d.ts:16

Create another context from an existing one

Parameters​

context​

OperationContext

the execution context

Returns​

Promise<SimpleOperationContext>

the result

Inherited from​

SimpleOperationContext.fromContext