[PR #11448] tools: replace structured ToolFunction.Parameters with json.RawMessage #12279

Open
opened 2025-11-12 16:32:33 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11448
Author: @jonigl
Created: 7/16/2025
Status: 🔄 Open

Base: mainHead: tools-json-rawmessage-refactor


📝 Commits (1)

  • 1ab7ba5 tools: replace structured ToolFunction.Parameters with json.RawMessage

📊 Changes

5 files changed (+127 additions, -181 deletions)

View changed files

📝 api/types.go (+3 -14)
📝 openai/openai_test.go (+1 -30)
📝 server/routes_generate_test.go (+22 -54)
📝 tools/tools.go (+68 -4)
📝 tools/tools_test.go (+33 -79)

📄 Description

Summary

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

Problem

The previous structured approach was limiting JSON schema flexibility and preventing support for advanced tooling scenarios that require complete schema definitions.

Changes

  • Replace structured Parameters field with json.RawMessage in ToolFunction
  • Add getProperties() and getRequired() helpers to extract data from JSON parameters
  • Update tests to use json.RawMessage format
  • Remove rigid ParametersSchema struct for true flexibility

Benefits

  • Better performance (minimal JSON parsing vs full struct unmarshaling)
  • Support for any valid JSON schema structure without predefined types
  • Cleaner, more maintainable code with focused helper functions
  • Maintains backward compatibility

Tool Schema Flexibility

This change enables advanced tool usage scenarios:

  • MCP (Model Context Protocol) servers: Full support for MCP-specific schema formats
  • Advanced JSON Schema features: anyOf, oneOf, const, additionalProperties: false, etc.
  • Dynamic schema generation: Runtime schema creation without structural limitations

Additional Context

This issue was discovered while testing Netlify MCP Server with the MCP client for Ollama. The previous structured approach was incompatible with flexible schema requirements.

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/11448 **Author:** [@jonigl](https://github.com/jonigl) **Created:** 7/16/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `tools-json-rawmessage-refactor` --- ### 📝 Commits (1) - [`1ab7ba5`](https://github.com/ollama/ollama/commit/1ab7ba5dfa52832bcc57b27f106083bf6e904200) tools: replace structured ToolFunction.Parameters with json.RawMessage ### 📊 Changes **5 files changed** (+127 additions, -181 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+3 -14) 📝 `openai/openai_test.go` (+1 -30) 📝 `server/routes_generate_test.go` (+22 -54) 📝 `tools/tools.go` (+68 -4) 📝 `tools/tools_test.go` (+33 -79) </details> ### 📄 Description ### Issues and PRs related - **Fixes #11444** (Take a look for more context) - **Relates to #8222** - **ollama-python related PR** to allow sending full json parameters schema https://github.com/ollama/ollama-python/pull/542 ### Summary Simplified `ToolFunction.Parameters` from a structured schema to `json.RawMessage` for better flexibility and performance. ### Problem The previous structured approach was limiting JSON schema flexibility and preventing support for advanced tooling scenarios that require complete schema definitions. ### Changes - Replace structured `Parameters` field with `json.RawMessage` in `ToolFunction` - Add `getProperties()` and `getRequired()` helpers to extract data from JSON parameters - Update tests to use `json.RawMessage` format - Remove rigid `ParametersSchema` struct for true flexibility ### Benefits - Better performance (minimal JSON parsing vs full struct unmarshaling) - Support for any valid JSON schema structure without predefined types - Cleaner, more maintainable code with focused helper functions - Maintains backward compatibility ### Tool Schema Flexibility This change enables advanced tool usage scenarios: - **MCP (Model Context Protocol) servers**: Full support for MCP-specific schema formats - **Advanced JSON Schema features**: `anyOf`, `oneOf`, `const`, `additionalProperties: false`, etc. - **Dynamic schema generation**: Runtime schema creation without structural limitations ### 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). The previous structured approach was incompatible with flexible schema requirements. ### 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 2025-11-12 16:32:33 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#12279
No description provided.