@@ -72,33 +72,20 @@ func MCPCompletionEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader,
7272 fragment = fragment .AddMessage (message .Role , message .StringContent )
7373 }
7474
75- // Extract port from APIAddress (format: ":8080" or "127.0.0.1:8080" or "0.0.0.0:8080")
76- port := "8080" // default
77- if appConfig .APIAddress != "" {
78- lastColon := strings .LastIndex (appConfig .APIAddress , ":" )
79- if lastColon >= 0 && lastColon + 1 < len (appConfig .APIAddress ) {
80- port = appConfig .APIAddress [lastColon + 1 :]
81- } else {
82- log .Warn ().Str ("APIAddress" , appConfig .APIAddress ).Msg ("[MCP] Could not extract port from APIAddress, using default 8080" )
83- }
84- }
85-
75+ port := appConfig .APIAddress [strings .LastIndex (appConfig .APIAddress , ":" )+ 1 :]
8676 apiKey := ""
87- if len ( appConfig .ApiKeys ) > 0 {
77+ if appConfig .ApiKeys != nil {
8878 apiKey = appConfig .ApiKeys [0 ]
8979 }
9080
91- baseURL := "http://127.0.0.1:" + port
92- log .Debug ().Str ("baseURL" , baseURL ).Str ("model" , config .Name ).Msg ("[MCP] Creating OpenAI LLM client for internal API calls" )
93-
9481 ctxWithCancellation , cancel := context .WithCancel (ctx )
9582 defer cancel ()
9683 handleConnectionCancellation (c , cancel , ctxWithCancellation )
9784 // TODO: instead of connecting to the API, we should just wire this internally
9885 // and act like completion.go.
9986 // We can do this as cogito expects an interface and we can create one that
10087 // we satisfy to just call internally ComputeChoices
101- defaultLLM := cogito .NewOpenAILLM (config .Name , apiKey , baseURL )
88+ defaultLLM := cogito .NewOpenAILLM (config .Name , apiKey , "http://127.0.0.1:" + port )
10289
10390 cogitoOpts := []cogito.Option {
10491 cogito .WithStatusCallback (func (s string ) {
@@ -140,8 +127,7 @@ func MCPCompletionEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader,
140127 cogitoOpts ... ,
141128 )
142129 if err != nil && ! errors .Is (err , cogito .ErrNoToolSelected ) {
143- log .Error ().Err (err ).Msgf ("[MCP] ExecuteTools failed for model %s" , config .Name )
144- return fmt .Errorf ("failed to execute tools: %w" , err )
130+ return err
145131 }
146132
147133 f , err = defaultLLM .Ask (ctx , f )
0 commit comments