mcp_call_active: Whether an MCP tool call is running

mcp_call_activeR Documentation

Whether an ⁠MCP⁠ tool call is running

Description

Returns TRUE while a tool runs for an ⁠MCP⁠ request, and FALSE otherwise, for example when the in-dashboard chat calls the same tool. While it is TRUE, the environment variable SHIDASHI_USING_MCP is set to "TRUE", so code that cannot call this function, such as skill scripts running in their own process, can check the variable instead.

Usage

mcp_call_active(v)

Arguments

v

optional logical; when given, turns the state on (TRUE) or off (anything else), and sets or removes SHIDASHI_USING_MCP to match. App code normally only reads the state.

Details

The dashboard's ⁠MCP⁠ handler turns the state on before each tool call and off when the call returns, also when the tool fails. A tool that returns a promise returns before the promise settles, so code that runs once it settles sees FALSE.

Value

TRUE or FALSE: the state after any change.

Examples

# Outside of an MCP tool call
mcp_call_active()
Sys.getenv("SHIDASHI_USING_MCP")

# In a tool: print less when an agent calls it over MCP
summarize_values <- function(x) {
  if (!mcp_call_active()) {
    message("Summarizing ", length(x), " values")
  }
  summary(x)
}
summarize_values(1:10)


shidashi documentation built on Oct. 12, 2026, 1:11 a.m.