Skip to contents

R6 class for managing MCP session communication with timeout management. Encapsulates session state while maintaining compatibility with existing global state for server communication. Provides automatic resource cleanup and session lifecycle management.

Details

MCP Session Management Class

Handles session lifecycle:

  • Socket Management: Creates and binds nanonext sockets for communication

  • Message Processing: Async tool execution and response handling

  • Timeout Management: Automatic session cleanup after inactivity

  • Resource Cleanup: Proper socket and state resource management

Super class

MCPR::BaseMCPR -> mcprSession

Methods

Inherited methods


Method new()

Create new mcprSession instance

Usage

mcprSession$new(timeout_seconds = 900)

Arguments

timeout_seconds

Timeout in seconds (default: 900)

Returns

A new mcprSession instance


Method start()

Start the MCP session and bind to a socket

Usage

mcprSession$start(session_id = NULL, force = FALSE)

Arguments

session_id

Optional integer socket ID to bind. Auto-selects when NULL.

force

Logical. If TRUE, allows starting in non-interactive sessions.

Returns

Self (invisibly) for method chaining


Method check_timeout()

Check for session timeout and cleanup if expired

Usage

mcprSession$check_timeout()

Returns

Self (invisibly) for method chaining


Method stop()

Stop session and cleanup resources

Usage

mcprSession$stop()

Returns

Self (invisibly) for method chaining


Method get_info()

Get session information

Usage

mcprSession$get_info()

Returns

List with session details


Method clone()

The objects of this class are cloneable with this method.

Usage

mcprSession$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.