SIGN IN SIGN UP

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

* fix: Ollama MCP tool calling for Mistral and Gemma3 models (#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>

* fix: resolve CI failures in prettier and jest module resolution

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>

* fix: remove relative-path jest.mock calls that break ESM resolution

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>

* fix: guard unprotected JSON.parse calls in Ollama.ts

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 #11523.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Joaquin Hui Gomez <joaquinhui1995@gmail.com>

* fix: add missing type cast through unknown for ToolCall arguments

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>

* fix: guard undefined arguments before JSONSchema7Object cast

---------

Signed-off-by: Joaquin Hui Gomez <joaquinhui1995@gmail.com>
Co-authored-by: Joaquin Hui Gomez <joaquinhui1995@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
J
Joaquin Hui committed
3c12dab7aa5478e62343b348a12a1adf1c952efa
Parent: 65c02ea
Committed by GitHub <noreply@github.com> on 3/24/2026, 8:49:32 PM