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

Open
opened 2026-04-13 00:29:49 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/ollama/ollama/pull/11448

State: open
Merged: No


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
**Original Pull Request:** https://github.com/ollama/ollama/pull/11448 **State:** open **Merged:** No --- ### 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
GiteaMirror added the pull-request label 2026-04-13 00:29:49 -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#13542