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

Method injectTools

intercept/chatcompletions/base.go:129–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127}
128
129func (i *interceptionBase) injectTools() {
130 if i.req == nil || i.mcpProxy == nil || !i.hasInjectableTools() {
131 return
132 }
133
134 // Disable parallel tool calls when injectable tools are present to simplify the inner agentic loop.
135 i.req.ParallelToolCalls = openai.Bool(false)
136
137 // Inject tools.
138 for _, tool := range i.mcpProxy.ListTools() {
139 fn := openai.ChatCompletionToolUnionParam{
140 OfFunction: &openai.ChatCompletionFunctionToolParam{
141 Function: openai.FunctionDefinitionParam{
142 Name: tool.ID,
143 Strict: openai.Bool(false), // TODO: configurable.
144 Description: openai.String(tool.Description),
145 Parameters: openai.FunctionParameters{
146 "type": "object",
147 "properties": tool.Params,
148 // "additionalProperties": false, // Only relevant when strict=true.
149 },
150 },
151 },
152 }
153
154 // Otherwise the request fails with "None is not of type 'array'" if a nil slice is given.
155 if len(tool.Required) > 0 {
156 // Must list ALL properties when strict=true.
157 fn.OfFunction.Function.Parameters["required"] = tool.Required
158 }
159
160 i.req.Tools = append(i.req.Tools, fn)
161 }
162}
163
164func (i *interceptionBase) unmarshalArgs(in string) (args recorder.ToolArgs) {
165 if len(strings.TrimSpace(in)) == 0 {

Callers 2

ProcessRequestMethod · 0.45
ProcessRequestMethod · 0.45

Calls 2

hasInjectableToolsMethod · 0.95
ListToolsMethod · 0.65

Tested by

no test coverage detected