MCPcopy Create free account
hub / github.com/coder/aibridge / injectTools

Method injectTools

intercept/messages/base.go:133–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 5

ProcessRequestMethod · 0.45
ProcessRequestMethod · 0.45

Calls 4

hasInjectableToolsMethod · 0.95
ListToolsMethod · 0.65
ErrorMethod · 0.45