class ActionController::MCPServer::RequestContext

Overview

the MCP request a route is running for, available to the route as mcp_context.

Routes annotated @[AC::MCP(long_running: true)] are streamed to clients that accept an event stream: they can report progress, and are cancelled when the client disconnects

@[AC::MCP(long_running: true)]
@[AC::Route::GET("/:id/export")]
def export(id : Int64) : Nil
  rows = Row.where(widget_id: id)
  rows.each_with_index do |row, index|
    break if mcp_context.try &.cancelled?
    response << row.to_csv
    mcp_context.try &.progress(index + 1, rows.size)
  end
end

Defined in:

action-controller/mcp/request_context.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(progress_token : JSON::Any | Nil = nil) #

[View source]

Instance Method Detail

def cancelled? : Bool #

the client disconnected, the route should stop work


[View source]
def done : Channel(Nil) #

closed when the request is cancelled, select on it to stop waiting


[View source]
def full=(full : Bool) #

true once the response has reached the route's max_bytes


[View source]
def full? : Bool #

true once the response has reached the route's max_bytes


[View source]
def progress(progress : Number, total : Number | Nil = nil, message : String | Nil = nil) : Nil #

reports progress to the client, ignored when the client didn't request progress. Progress must increase, values that don't are ignored


[View source]
def progress_token : JSON::Any | Nil #

the _meta.progressToken of the request, progress isn't reported without one


[View source]