[PR #11446] [CLOSED] Refactor ToolFunction.Parameters to use json.RawMessage #24081

Closed
opened 2026-04-19 17:22:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11446
Author: @jonigl
Created: 7/16/2025
Status: Closed

Base: mainHead: tools-json-rawmessage-refactor


📝 Commits (1)

  • 8f6023d tools: replace structured ToolFunction.Parameters with json.RawMessage

📊 Changes

3 files changed (+90 additions, -112 deletions)

View changed files

📝 api/types.go (+3 -14)
📝 tools/tools.go (+33 -3)
📝 tools/tools_test.go (+54 -95)

📄 Description

  • Fixes #11444 (Take a look for more context)
  • Relates to #8222*

Summary

Simplified ToolFunction.Parameters from a structured schema to json.RawMessage for better flexibility and performance.

Problem

The previous structured approach was stripping essential JSON schema fields from tool function parameters, causing compatibility issues with advanced tooling that relies on complete schema definitions.

Changes

  • Replace structured Parameters field with json.RawMessage in ToolFunction
  • Add getProperties() helper to extract properties from JSON parameters
  • Update tests to use json.RawMessage format
  • Tools Test renamed json to jsonTmpl variable since adding "encoding/json"

Benefits

  • Better performance (single JSON unmarshal vs multiple field accesses)
  • Support for flexible parameter schemas beyond rigid JSON Schema structure
  • Cleaner, more maintainable code
  • Maintains backward compatibility

Tool Schema Flexibility

This change particularly benefits advanced tool usage scenarios:

  • MCP (Model Context Protocol) servers: Support for MCP-specific schema formats and validation requirements
  • Tools with union types: Enable anyOf, oneOf schema patterns for complex parameter validation
  • Strict validation tools: Support additionalProperties: false and other strict validation rules
  • Tools using constant values: Enable const and other advanced JSON Schema features

Additional Context

This issue was discovered while testing Netlify MCP Server with the MCP client for Ollama. This MCP Server tool specification relies heavily on JSON schema features that were being stripped by the previous structured approach.

Testing

  • All existing tests pass
  • Tool parsing functionality preserved
  • No breaking changes to external API

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/11446 **Author:** [@jonigl](https://github.com/jonigl) **Created:** 7/16/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `tools-json-rawmessage-refactor` --- ### 📝 Commits (1) - [`8f6023d`](https://github.com/ollama/ollama/commit/8f6023df5bbac5925f20c2a24423c7f28d0ef9c4) tools: replace structured ToolFunction.Parameters with json.RawMessage ### 📊 Changes **3 files changed** (+90 additions, -112 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+3 -14) 📝 `tools/tools.go` (+33 -3) 📝 `tools/tools_test.go` (+54 -95) </details> ### 📄 Description ### Issues related - **Fixes #11444** (Take a look for more context) - **Relates to #8222*** ### Summary Simplified `ToolFunction.Parameters` from a structured schema to `json.RawMessage` for better flexibility and performance. ### Problem The previous structured approach was stripping essential JSON schema fields from tool function parameters, causing compatibility issues with advanced tooling that relies on complete schema definitions. ### Changes - Replace structured `Parameters` field with `json.RawMessage` in `ToolFunction` - Add `getProperties()` helper to extract properties from JSON parameters - Update tests to use `json.RawMessage` format - Tools Test renamed json to jsonTmpl variable since adding "encoding/json" ### Benefits - Better performance (single JSON unmarshal vs multiple field accesses) - Support for flexible parameter schemas beyond rigid JSON Schema structure - Cleaner, more maintainable code - Maintains backward compatibility ### Tool Schema Flexibility This change particularly benefits advanced tool usage scenarios: - **MCP (Model Context Protocol) servers**: Support for MCP-specific schema formats and validation requirements - **Tools with union types**: Enable `anyOf`, `oneOf` schema patterns for complex parameter validation - **Strict validation tools**: Support `additionalProperties: false` and other strict validation rules - **Tools using constant values**: Enable `const` and other advanced JSON Schema features ### Additional Context This issue was discovered while testing [Netlify MCP Server](https://github.com/netlify/netlify-mcp) with the [MCP client for Ollama](https://github.com/jonigl/mcp-client-for-ollama). This MCP Server tool specification relies heavily on JSON schema features that were being stripped by the previous structured approach. ### Testing - All existing tests pass - Tool parsing functionality preserved - No breaking changes to external API --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-19 17:22:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#24081