fix: Highly inconsistent agent response to LocalAGI agent calling MCP server - Body "Invalid http method" #7790
+6
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #7772
Problem
The issue was caused by duplicate registration of the MCP endpoint
/mcp/v1/chat/completionsin bothopenai.goandlocalai.go. This led to a race condition where approximately 50% of requests would randomly hit different handlers with incompatible behaviors, resulting in "Invalid http method" errors.Changes
Removed duplicate MCP route registration from openai.go
MCPCompletionEndpointhandler and its associated middlewareConsolidated to single canonical handler in localai.go
localai.MCPStreamEndpointas the canonical handleropenai.MCPCompletionEndpointonly supported synchronous requestsAdded all three MCP route patterns for backward compatibility
/v1/mcp/chat/completions- Primary pattern/mcp/v1/chat/completions- Alternate ordering/mcp/chat/completions- Legacy pattern for backward compatibilityDocumentation and maintenance improvements
Testing
go fmtImpact
This eliminates the ~50% failure rate where the cogito library would receive "Invalid http method" errors when internal HTTP requests were randomly routed to the wrong handler.
Generated with Claude Code