Skip to content

fix: Ollama MCP tool calling for Mistral and Gemma3 models#11523

Open
joaquinhuigomez wants to merge 6 commits intocontinuedev:mainfrom
joaquinhuigomez:fix/ollama-mcp-tool-calling
Open

fix: Ollama MCP tool calling for Mistral and Gemma3 models#11523
joaquinhuigomez wants to merge 6 commits intocontinuedev:mainfrom
joaquinhuigomez:fix/ollama-mcp-tool-calling

Conversation

@joaquinhuigomez
Copy link

@joaquinhuigomez joaquinhuigomez commented Mar 17, 2026

No description provided.

…ev#9249)

Fix two issues with Ollama tool calling:

1. Mistral/Ministral: reorder messages so system messages never follow
   tool messages (causes "Unexpected role 'system' after role 'tool'")

2. Gemma3: strip unsupported fields (index, id, type) from tool_calls
   when converting assistant messages to Ollama format (causes "unknown
   variant 'index'")

Also forward assistant toolCalls to Ollama's tool_calls format for
proper multi-turn tool calling conversations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joaquinhuigomez joaquinhuigomez requested a review from a team as a code owner March 17, 2026 02:25
@joaquinhuigomez joaquinhuigomez requested review from Patrick-Erichsen and removed request for a team March 17, 2026 02:25
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 17, 2026
@github-actions
Copy link
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/llm/llms/Ollama.ts">

<violation number="1" location="core/llm/llms/Ollama.ts:331">
P2: Unguarded `JSON.parse` of string tool-call arguments can throw and abort `_streamChat` before the Ollama request is sent.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@joaquinhuigomez
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

joaquinhui and others added 5 commits March 17, 2026 11:48
Remove .js extensions from jest.mock paths so the moduleNameMapper
resolves ollamaHelper and url modules correctly. Apply prettier
formatting to both changed files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The jest ESM config resolves relative mock paths from the setup file
context, not the test file, causing 'Cannot find module' errors.
These mocks are unnecessary since the test bypasses the constructor
via Object.create() and only tests pure transformation methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Wrap JSON.parse of tool-call arguments in _convertToOllamaMessage and
pull-progress lines in installModel with try/catch to prevent unhandled
exceptions from aborting the request flow.

Addresses Cubic review feedback on PR continuedev#11523.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Joaquin Hui Gomez <joaquinhui1995@gmail.com>
TypeScript rejects a direct cast from string to JSONSchema7Object.
Cast through unknown first to satisfy the type checker.

Signed-off-by: Joaquin <joaquin@users.noreply.github.com>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joaquinhuigomez
Copy link
Author

Update: latest CI is green on the code/test side. Remaining blockers appear to be CLA/process-related rather than the implementation itself.

@joaquinhuigomez
Copy link
Author

recheck

1 similar comment
@joaquinhuigomez
Copy link
Author

recheck

@RomneyDa RomneyDa closed this Mar 21, 2026
@github-project-automation github-project-automation bot moved this from Todo to Done in Issues and PRs Mar 21, 2026
@RomneyDa RomneyDa reopened this Mar 21, 2026
@github-project-automation github-project-automation bot moved this from Done to In Progress in Issues and PRs Mar 21, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants