| 132 | } |
| 133 | |
| 134 | func (i *interceptionBase) injectTools() { |
| 135 | if i.mcpProxy == nil || !i.hasInjectableTools() { |
| 136 | return |
| 137 | } |
| 138 | |
| 139 | i.disableParallelToolCalls() |
| 140 | |
| 141 | // Inject tools. |
| 142 | var injectedTools []anthropic.ToolUnionParam |
| 143 | for _, tool := range i.mcpProxy.ListTools() { |
| 144 | injectedTools = append(injectedTools, anthropic.ToolUnionParam{ |
| 145 | OfTool: &anthropic.ToolParam{ |
| 146 | InputSchema: anthropic.ToolInputSchemaParam{ |
| 147 | Properties: tool.Params, |
| 148 | Required: tool.Required, |
| 149 | }, |
| 150 | Name: tool.ID, |
| 151 | Description: anthropic.String(tool.Description), |
| 152 | Type: anthropic.ToolTypeCustom, |
| 153 | }, |
| 154 | }) |
| 155 | } |
| 156 | |
| 157 | // Prepend the injected tools in order to maintain any configured cache breakpoints. |
| 158 | // The order of injected tools is expected to be stable, and therefore will not cause |
| 159 | // any cache invalidation when prepended. |
| 160 | updated, err := i.reqPayload.injectTools(injectedTools) |
| 161 | if err != nil { |
| 162 | i.logger.Warn(context.Background(), "failed to set inject tools in request payload", slog.Error(err)) |
| 163 | return |
| 164 | } |
| 165 | i.reqPayload = updated |
| 166 | } |
| 167 | |
| 168 | func (i *interceptionBase) disableParallelToolCalls() { |
| 169 | // Note: Parallel tool calls are disabled to avoid tool_use/tool_result block mismatches. |