27 Configured interaction scenarios🔗ℹ

A configured scenario binds a session for its Racket body:
(scenario (greeting session)
  #:interface mcp-interface
  #:transport 'stdio
  #:clock (make-manual-clock #:seconds 100)
  #:principal "reader"
  (define reply
    (scenario-call session "tools/call"
                   (hasheq 'name "greet" 'arguments (hasheq 'name "Ada"))))
  (check-equal? (hash-ref (hash-ref reply 'result) 'content)
                (list (text-content "Hello, Ada"))))

The #:interface expression is required. Optional clauses follow this order: #:transport, #:clock, #:principal, #:adapters, #:capabilities, #:state, #:authorize, #:timeout, #:sse?. Configuration expressions run once, in that order, when the test submodule executes. They do not run when the application’s interface descriptors are constructed. The session binder has ordinary lexical Racket scope in the body. Missing interface clauses, malformed binders and repeated/out-of-order clauses fail expansion. The older (scenario name body ...) form remains valid.

call-with-scenario-session, exported by mcp and mcp/scenario, is the equivalent procedure. It takes an interface and a one-argument callback plus the same optional keywords. It returns the callback’s values and closes the session’s transport, runtime workers and store on exit. A retained session rejects later calls. The defaults are local dispatch, a manual clock at Unix zero, principal "scenario", empty adapters/capabilities, memory storage, an allowing authorization callback, a five-second real request timeout, and a preference for quick HTTP JSON responses. #:state supplies an explicit SQLite path. Reusing that path in another session permits continuation tests across runtime/store reopenings; it does not simulate killing a separate process.

scenario-request takes the same arguments as scenario-call and returns an SDK request-handle immediately. Import mcp/stdio for the common handle accessors and request-cancel!. Synchronizing the handle returns its JSON-RPC outcome or exception value; scenario-call waits and raises exception values. The handle’s notification channel supports authored progress and subscription assertions while other requests are running. Request deadlines use real elapsed time, independently of the scenario clock. Both call forms accept #:timeout: a positive finite number of seconds, or #f to disable the request deadline. Ordinary requests default to the session timeout; subscription listeners default to #f, matching the SDK clients. HTTP still bounds response header acquisition by the session timeout. An explicitly bounded subscription can test timeout behavior without changing other requests. Cancellation retains the first terminal outcome, signals cooperative cancellation, and bounds worker cleanup. Session exit cancels outstanding requests before destroying their event machinery, so escaped handles remain synchronizable. Local dispatch uses a bounded 256-message notification queue; overflow terminates the request with exn:fail:notification-overflow. Wire transports retain their own SDK limits.

scenario-call takes the session, a method string and an optional JSON params object. #:capabilities can override the session’s capabilities for that call. Each call gets a fresh request ID and returns its JSON-RPC outcome. Local calls round-trip request data through JSON and use dispatch-message. Stdio calls use the actual SDK client/server over bounded pipes; HTTP uses a loopback server and the actual SDK client. #:sse? #t selects HTTP SSE responses. Transport errors retain their native exception types; for example, HTTP authorization challenges may raise an HTTP authorization exception. Failed or uncertain calls are never automatically replayed.

scenario-interact accepts session, method and params, requires explicit #:elicit and #:navigate callbacks, and delegates MRTR/Tasks interaction to run-interaction. Optional #:max-rounds and #:wait retain that runner’s policy. Logical clock advancement does not replace real task scheduling. Session accessors expose its runtime, store, clock, transport and principal for authored assertions and fixtures.

The HTTP session installs the supplied principal through a testing authentication adapter; it exercises runtime authorization rather than a hosted OAuth flow. serve-stdio now also accepts #:principal, defaulting to ’local, so the same principal/policy can be tested through all three paths. HTTP scenario keep-alives are at most one second and at most half the request timeout.

Call timeouts and session teardown are tested with uncooperative handlers. Longer HTTP requests now switch from the JSON preference to SSE, allowing stream closure to cancel work before session teardown. The regression probe at dev/check-http-json-disconnect.rkt passes for this adaptive behavior. Asynchronous requests, notification assertions and explicit cancellation are available through the session API. Explicit transport loss is available through the controls below; actual process restarts and the complete fault grammar remain unfinished.