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

Method injectTools

aibridge/intercept/chatcompletions/base.go:141–174  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

ProcessRequestMethod · 0.45
ProcessRequestMethod · 0.45

Calls 3

hasInjectableToolsMethod · 0.95
ListToolsMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected