Interface RemoteMcpTools.ToolInterceptor

Enclosing interface:
RemoteMcpTools

public static interface RemoteMcpTools.ToolInterceptor
  • Method Details

    • interceptRequest

      default String interceptRequest(RemoteMcpTools.ToolInterceptorContext context, String requestPayloadJson)
      Intercept calls to tools before they are executed, disallowing the call based on the payload can be done by throwing an exception, modifying the payload is also possible. When modifying the payload, you need to make sure the payload still fulfills the schema of the tool with required fields and correct field types.

      The ledger records the returned arguments as the arguments of the tool call. Returning null fails the tool call.

      Parameters:
      context - Details about the intercepted tool call
      requestPayloadJson - The tool request payload in a Json string.
    • interceptResponse

      default String interceptResponse(RemoteMcpTools.ToolInterceptorContext context, String requestPayloadJson, String responsePayload)
      Intercept responses from MCP tools, disallowing the call based on the result can be done by throwing an exception, modifying the result is also possible. When modifying the result, you need to make sure the payload still is something the model will understand.

      The runtime calls this method for each result that the MCP server returns, including an error result. RemoteMcpTools.ToolInterceptorContext.isError() is true for an error result. The returned text keeps the error flag of the original result, and the interceptor cannot change the flag. A tool call that fails without a result, for example on a timeout, does not reach this method.

      Returning null fails the tool call.

      Parameters:
      context - Details about the intercepted tool call
      requestPayloadJson - The request payload as passed to the MCP tool (possibly modified by interceptRequest(ToolInterceptorContext, String))