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

Method injectTools

intercept/responses/injected_tools.go:18–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func (i *responsesInterceptionBase) injectTools() {
19 if i.mcpProxy == nil || !i.hasInjectableTools() {
20 return
21 }
22
23 i.disableParallelToolCalls()
24
25 // Inject tools.
26 var injected []responses.ToolUnionParam
27 for _, tool := range i.mcpProxy.ListTools() {
28 var params map[string]any
29
30 if tool.Params != nil {
31 params = map[string]any{
32 "type": "object",
33 "properties": tool.Params,
34 // "additionalProperties": false, // Only relevant when strict=true.
35 }
36 }
37
38 // Otherwise the request fails with "None is not of type 'array'" if a nil slice is given.
39 if len(tool.Required) > 0 {
40 // Must list ALL properties when strict=true.
41 params["required"] = tool.Required
42 }
43
44 injected = append(injected, responses.ToolUnionParam{
45 OfFunction: &responses.FunctionToolParam{
46 Name: tool.ID,
47 Strict: openai.Bool(false), // TODO: configurable.
48 Description: openai.String(tool.Description),
49 Parameters: params,
50 },
51 })
52 }
53
54 updated, err := i.reqPayload.injectTools(injected)
55 if err != nil {
56 i.logger.Warn(context.Background(), "failed to inject tools", slog.Error(err))
57 return
58 }
59 i.reqPayload = updated
60}
61
62// disableParallelToolCalls disables parallel tool calls, to simplify the inner agentic loop.
63// This is best-effort, and failing to set this flag does not fail the request.

Callers

nothing calls this directly

Calls 4

hasInjectableToolsMethod · 0.95
ListToolsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected