LocalAI/core/http/endpoints/localai
lif 4cd95b8a9d
fix: Highly inconsistent agent response to cogito agent calling MCP server - Body "Invalid http method" (#7790)
* fix: resolve duplicate MCP route registration causing 50% failure rate

Fixes #7772

The issue was caused by duplicate registration of the MCP endpoint
/mcp/v1/chat/completions in both openai.go and localai.go, leading
to a race condition where requests would randomly hit different
handlers with incompatible behaviors.

Changes:
- Removed duplicate MCP route registration from openai.go
- Kept the localai.MCPStreamEndpoint as the canonical handler
- Added all three MCP route patterns for backward compatibility:
  * /v1/mcp/chat/completions
  * /mcp/v1/chat/completions
  * /mcp/chat/completions
- Added comments to clarify route ownership and prevent future conflicts
- Fixed formatting in ui_api.go

The localai.MCPStreamEndpoint handler is more feature-complete as it
supports both streaming and non-streaming modes, while the removed
openai.MCPCompletionEndpoint only supported synchronous requests.

This eliminates the ~50% failure rate where the cogito library would
receive "Invalid http method" errors when internal HTTP requests were
routed to the wrong handler.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>

* Address feedback from review

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: majiayu000 <1835304752@qq.com>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-01-03 15:43:23 +01:00
..
agent_jobs.go feat(agent-jobs): add multimedia support (#7398) 2025-11-30 14:09:25 +01:00
backend.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
backend_monitor.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
detection.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
edit_model.go feat(importer): unify importing code with CLI (#7299) 2025-11-19 20:52:11 +01:00
edit_model_test.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
gallery.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
get_token_metrics.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
import_model.go feat(ui): runtime settings (#7320) 2025-11-20 22:37:20 +01:00
localai_suite_test.go feat(webui): add import/edit model page (#6050) 2025-08-14 23:48:09 +02:00
mcp.go fix: Highly inconsistent agent response to cogito agent calling MCP server - Body "Invalid http method" (#7790) 2026-01-03 15:43:23 +01:00
metrics.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
p2p.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
settings.go feat: disable force eviction (#7725) 2025-12-25 14:26:18 +01:00
stores.go feat(loader): enhance single active backend to support LRU eviction (#7535) 2025-12-12 12:28:38 +01:00
system.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
tokenize.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
tts.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
types.go feat(webui): add import/edit model page (#6050) 2025-08-14 23:48:09 +02:00
vad.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
video.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
welcome.go feat(ui): runtime settings (#7320) 2025-11-20 22:37:20 +01:00