reshapr icon indicating copy to clipboard operation
reshapr copied to clipboard

Add support for multi-tools orchestration/aggregation in `CustomTools`

Open lbroudoux opened this issue 5 months ago • 2 comments

As of today, the Reshapr CustomTools allows redefining a tool interface and how it maps onto an existing API call. This is nice when we already have the correct or a coarse business feature available, and we want to refine/taylor/simplify the interface. However, it doesn't solve the 1-to-N issue of mapping 1 MCP tool to N different API calls.

To solve this 1-to-N mapping in a very flexible way, we propose extending CustomTools capabilities by allowing us to provide custom orchestration and aggregation logic via JavaScript scripting. Such a script should allow the user to call tools the way they want (blocking or non-blocking) and recompose the response as they want, easily, just using JavaScript primitives.

Instead or using tool and argumentsas of today (see https://reshapr.io/docs/references/custom-tools-specification) for 1-to-1 mapping, one could then integrate script in the case of 1-to-N orchestration. We'll envision something like this:

apiVersion: reshapr.io/v1alpha1
kind: CustomTools
service:
  name: My API
  version: '1.0'
customTools:
  my_custom_tool:
    description: The description of what this tool is doing
    input:
      type: object
      properties:
        user:
          type: string
          description: Example
      required:
        - user
    script: |-
      const profile = rs.callTool("get_profile", input.user);
      const orders = rs.callTool("Order API:1.0", "get_orders", profile.data.userId);
      const shippingP = rs.callToolAsync("ShippingService:v1", "getShippings", profile.data.userId);
      const bonusesP = rs.callToolAsync("ShippingService:v1", "getBonuses", profile.data.userId);
      const response = rs.awaitPromises([shippingP, bonusesP]);
      return {
        profile: profile.data, 
        orders: order.orders, 
        shippings: response[0].shippings, 
        bonuses: response[1].bonuses
     };

The above script introduces several APIs that we'll provide in the JavaScript context:

  • rs.callTool("get_profile", input.user) allows calling another tool in the same service, reusing the input of the custom tool.
  • rs.callTool("Order API:1.0", "get_orders", profile.data.userId) allows calling another tool in another service, in a blocking way.
  • rs.callToolAsync("ShippingService:v1", "getShippings", profile.data.userId) allows calling another service tool, in a non-blocking way,
  • rs.awaitPromises([shippingP, bonusesP]); allows waiting for non-blocking call to end.

One important thing that happens here is that all calls to subsequent tools will be made in the same authentication/identity context with the pre-flight security checks for each tool. To realize those pre-flights - and also to handle possible elicitation retrieval beforehand- the user will also need to list the tools that will be actually called within the script. This will be done with an additional tools section like this:

apiVersion: reshapr.io/v1alpha1
kind: CustomTools
service:
  name: My API
  version: '1.0'
customTools:
  my_custom_tool:
    description: The description of what this tool is doing
    input:
      # [...]
    script: |-
      # [...]
    tools:
      - tool: get_profile
      - service: Order API:1.0
         tool: get_orders
      - service: ShippingService:v1
         tool: getShippings
      - service: ShippingService:v1
         tool: getBonuses

We're looking forward to get your feedback and comments on this proposal!

lbroudoux avatar Jun 15 '26 08:06 lbroudoux

It's now implemented and available in the nightly image.

rs.callTool(...) and each entry returned by rs.awaitPromises(...) is a result object:

{
  ok: true,                 // false if the call failed
  content: { /* ... */ },   // the tool response, parsed as JSON when possible (else a string); null on error
  error: null               // { code, message } when ok is false
}

A script should check result.ok before reading result.content.

lbroudoux avatar Jun 16 '26 12:06 lbroudoux

I think we have something solid for this iteration! Closing this one, and we'll be able to enhance further later.

lbroudoux avatar Jun 17 '26 14:06 lbroudoux