Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

Address feedback from review#39

Open
blackboxprogramming wants to merge 2 commits intomasterfrom
fix/mcp
Open

Address feedback from review#39
blackboxprogramming wants to merge 2 commits intomasterfrom
fix/mcp

Conversation

@blackboxprogramming
Copy link

Description

This PR fixes #

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

majiayu000 and others added 2 commits January 2, 2026 21:29
Fixes mudler#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>
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Copilot AI review requested due to automatic review settings January 4, 2026 11:37
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses review feedback by consolidating and refactoring MCP (Model Context Protocol) endpoint implementations. The main changes involve removing duplicate MCP endpoints from the OpenAI routes and consolidating functionality into a single LocalAI endpoint that supports both streaming and non-streaming modes.

  • Removed duplicate MCP completion handler from OpenAI routes
  • Renamed and updated MCP endpoint to support both streaming and non-streaming modes
  • Added route registration for /mcp/chat/completions path
  • Fixed indentation formatting issue in UI API routes

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/http/routes/ui_api.go Fixed indentation of closing brace in error response
core/http/routes/openai.go Removed MCP completion handler and related middleware from OpenAI routes
core/http/routes/localai.go Updated comments, renamed handler function, and added additional route registration for MCP endpoint
core/http/endpoints/openai/mcp.go Deleted entire file containing duplicate MCP completion implementation
core/http/endpoints/localai/mcp.go Renamed function from MCPStreamEndpoint to MCPEndpoint and updated documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// MCP Stream endpoint
// MCP endpoint - supports both streaming and non-streaming modes
// Note: streaming mode is NOT compatible with the OpenAI apis. We have a set which streams more states.
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "streaming mode is NOT compatible with the OpenAI apis", but it should specify "OpenAI API" (singular and capitalized) for consistency with technical documentation standards.

Suggested change
// Note: streaming mode is NOT compatible with the OpenAI apis. We have a set which streams more states.
// Note: streaming mode is NOT compatible with the OpenAI API. We have a set which streams more states.

Copilot uses AI. Check for mistakes.

// MCP Stream endpoint
// MCP endpoint - supports both streaming and non-streaming modes
// Note: streaming mode is NOT compatible with the OpenAI apis. We have a set which streams more states.
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "We have a set which streams more states" which is unclear. Consider rewording to "This endpoint streams additional state information beyond what the standard OpenAI API provides" or similar phrasing to clarify what "a set which streams more states" means.

Suggested change
// Note: streaming mode is NOT compatible with the OpenAI apis. We have a set which streams more states.
// Note: streaming mode is NOT compatible with the OpenAI APIs. This endpoint streams additional state information beyond what the standard OpenAI API provides.

Copilot uses AI. Check for mistakes.
}

// MCPStreamEndpoint is the SSE streaming endpoint for MCP chat completions
// MCPEndpoint is the endpoint for MCP chat completions. Supports SSE mode, but it is not compatible with the OpenAI apis.
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "SSE mode, but it is not compatible with the OpenAI apis". The phrase should use "OpenAI API" (singular and capitalized) for consistency with technical documentation standards.

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants