Replies: 1 comment 1 reply
-
|
i was looking for something similar in spring ai tools section did not found any control over tool calling, whether in MCP server i think there is Elicitation which can be configured using McpSyncRequestContext. This idea looks good and promising later we can extend it with rate limiting feature. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
1. Motivation
Spring AI supports tool calling, allowing models to invoke arbitrary functions, services, and APIs via
ToolCallbacks. While powerful, this introduces risk:Today, once the model decides to call a tool, Spring AI executes it without any pluggable approval step.
This proposal introduces a small, focused Tool Approval Strategy that lets application developers decide, at runtime, whether a given tool call should be executed, rejected, or handled in a custom way, without breaking existing behavior.
2. Goals and Non-Goals
2.1 Goals
2.2 Non-Goals (for v1)
The following ideas are explicitly out of scope for this initial version and can be addressed in follow-up work:
3. High-Level Design
At a high level, the design adds:
ToolApprovalStrategyfunctional interface that is consulted before any tool is executed.ToolApprovalDecisionvalue type describing the outcome (approved/rejected).ToolApprovalExceptionfor signaling hard failures in the approval layer.requiresApprovalflag on tool metadata to allow per-tool configuration.DefaultToolCallingManagerto invoke the strategy and handle rejections.Default behavior is preserved via an
AlwaysApproveStrategythat simply approves every tool call. Applications can provide their own strategy as a Spring bean to override this behavior.4. Public API (v1)
4.1
ToolApprovalStrategyA functional interface that receives information about the tool call and returns a decision.
A simple default implementation:
Framework default:
AlwaysApproveStrategy.4.2
ToolApprovalDecisionA small value type that represents the outcome of a strategy decision.
reasonis intended primarily for logging and optional model/user-facing messages.metadatais included for future extensibility (e.g., attaching policy IDs, severity, tenant IDs). v1 does not prescribe a specific schema.4.3
ToolApprovalExceptionA dedicated exception type for approval-layer failures.
This exception is not thrown for “normal” rejections (those are represented by
ToolApprovalDecision); it is used when something goes wrong evaluating the approval (e.g., policy engine unavailable).4.4
ToolMetadata.requiresApprovalTools can opt in or out of approval on a per-tool basis.
For example:
requiresApproval = falseto bypass approval even if a global strategy is configured.requiresApproval = trueto ensure it is always subject to the strategy.5. Default Behavior and Backwards Compatibility
To avoid breaking existing applications:
ToolApprovalStrategybean is registered, Spring AI configures anAlwaysApproveStrategyinternally.requiresApproval()returnsnulland the default strategy is used, the behavior is identical to today: all tools are executed as requested by the model.ToolApprovalStrategy, andrequiresApprovalistrue, or the strategy is applied globally (see below).6.
DefaultToolCallingManagerIntegrationDefaultToolCallingManageris extended to consult the approval strategy before invoking a tool.High-level flow for a single tool call:
ToolCallback.toolApprovalStrategy.approve(...).Pseudo-code:
Notes:
ToolExecutionResult.rejected(...)is a placeholder for the existing response type used to represent tool outputs. In v1, rejections would be encoded as a tool response that the model can see (e.g., “Tool execution was denied: ”).isApprovalRequired()returnstrue. With the defaultAlwaysApproveStrategy, this is O(1) and effectively a no-op.7. Example Usage
7.1 Application configuration: simple blacklist
An application might define a simple blacklist strategy:
With no changes to the rest of the application, any attempt by the model to call
deleteAccountordropDatabasewill be rejected before execution.7.2 Per-tool override: safe tools
Even if the global
ToolApprovalStrategyimplements complex policies, this tool bypasses approval.8. Future Extensions (Out of Scope for v1)
The v1 design intentionally limits scope to a small, composable core. Potential future enhancements include:
ToolApprovalDecision.metadata.These can be added incrementally on top of the v1 foundation without breaking changes.
End of v1 doc
Beta Was this translation helpful? Give feedback.
All reactions