Class ChenileToolCallback

java.lang.Object
org.chenile.mcp.model.ChenileToolCallback
All Implemented Interfaces:
org.springframework.ai.tool.ToolCallback

public class ChenileToolCallback extends Object implements org.springframework.ai.tool.ToolCallback
The MCP transport adapter. Turns an MCP tool call into a ChenileExchange and runs it through ChenileEntryPoint, so a tool call passes through the chenile-highway exactly like an HTTP request: header validation, pre/post processors, transformation, service selection and the service interceptors.

Each tool parameter is bound to the exchange by its HttpBindingType: the BODY parameter is passed as JSON and typed by the highway's transformer (and body type selectors), HEADER parameters become headers and a HEADERS parameter is merged into the headers. Polymorph fixed values are bound the same way.

  • Field Details

    • OBJECT_MAPPER

      private static final ObjectMapper OBJECT_MAPPER
    • logger

      static org.slf4j.Logger logger
    • toolDefinition

      private final org.springframework.ai.tool.definition.ToolDefinition toolDefinition
    • toolMetadata

      private final org.springframework.ai.tool.metadata.ToolMetadata toolMetadata
    • chenileEntryPoint

      private final ChenileEntryPoint chenileEntryPoint
    • contextContainer

      private final ContextContainer contextContainer
    • serviceDefinition

      private final ChenileServiceDefinition serviceDefinition
    • operationDefinition

      private final OperationDefinition operationDefinition
    • parameters

    • toolCallResultConverter

      private final org.springframework.ai.tool.execution.ToolCallResultConverter toolCallResultConverter
  • Constructor Details

  • Method Details

    • getToolDefinition

      public org.springframework.ai.tool.definition.ToolDefinition getToolDefinition()
      Specified by:
      getToolDefinition in interface org.springframework.ai.tool.ToolCallback
    • getToolMetadata

      public org.springframework.ai.tool.metadata.ToolMetadata getToolMetadata()
      Specified by:
      getToolMetadata in interface org.springframework.ai.tool.ToolCallback
    • call

      public String call(String toolInput)
      Specified by:
      call in interface org.springframework.ai.tool.ToolCallback
    • call

      public String call(String toolInput, org.springframework.ai.chat.model.ToolContext toolContext)
      Specified by:
      call in interface org.springframework.ai.tool.ToolCallback
    • makeExchange

      private ChenileExchange makeExchange(String toolInput, org.springframework.ai.chat.model.ToolContext toolContext)
    • copyCallerHeaders

      private void copyCallerHeaders(ChenileExchange exchange, org.springframework.ai.chat.model.ToolContext toolContext)
      Copies the headers of the HTTP request that carried the tool call (captured by ChenileMcpHeaderExtractor) into the exchange. They are copied before the entry point headers and the tool parameters, so a caller cannot override those.
    • readInput

      private JsonNode readInput(String toolInput)
    • bind

      private void bind(ChenileExchange exchange, ChenileToolCallback.ChenileToolParameter parameter, JsonNode valueNode)
    • asHeaderValue

      private String asHeaderValue(JsonNode node)
    • payload

      private Object payload(Object response)
    • errorMessage

      private String errorMessage(ChenileExchange exchange)
    • buildInputSchema

      public static String buildInputSchema(List<ChenileToolCallback.ChenileToolParameter> parameters)
    • removeRequiredFields

      private static void removeRequiredFields(JsonNode node)
      By default all fields are marked as required. We need to remove that from the schema manually
      Parameters:
      node -