From 97f71f6ebbdc69864901f1dc221ef12fb7dda79f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 6 Nov 2026 08:53:00 +0900 Subject: [PATCH] refac --- backend/open_webui/utils/middleware.py | 6 ++++++ backend/open_webui/utils/tool_calling.py | 13 +------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 561ec05996..c6239d68df 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -1077,6 +1077,9 @@ async def chat_completion_tools_handler( if error := prepare_tool_call(prepared, tool.get('spec', {}).get('parameters')): raise ValueError(error) tool_function_params = JSONCodec.loads(prepared['arguments']) + if tool_type != 'mcp': + allowed_params = tool.get('spec', {}).get('parameters', {}).get('properties', {}) + tool_function_params = {k: v for k, v in tool_function_params.items() if k in allowed_params} if tool.get('direct', False): tool_result = await event_caller( @@ -3069,6 +3072,9 @@ async def execute_tool_call(form_data, metadata, event_caller, tool_call, histor return params, 'Error: Uploaded file display is not available.', None, None, False tool_type = tool.get('type', '') direct_tool = tool.get('direct', False) + if tool_type != 'mcp': + allowed_params = tool.get('spec', {}).get('parameters', {}).get('properties', {}) + params = {key: value for key, value in params.items() if key in allowed_params} try: if ( not is_saved_chat_id(metadata.get('chat_id')) diff --git a/backend/open_webui/utils/tool_calling.py b/backend/open_webui/utils/tool_calling.py index 05437030cd..0f9830ac05 100644 --- a/backend/open_webui/utils/tool_calling.py +++ b/backend/open_webui/utils/tool_calling.py @@ -11,10 +11,6 @@ import math import re from uuid import uuid4 -from jsonschema import Draft202012Validator -from referencing import Registry -from referencing.exceptions import Unresolvable - FINAL_ANSWER_PROMPT = ( 'Tool use has stopped for this response. Use the results already available to answer the user. ' 'Explain any unfinished work briefly. Do not request or describe additional tool calls.' @@ -107,15 +103,8 @@ def _coerce(value, schema, depth=0): def normalize_arguments(raw, schema=None): params = parse_arguments(raw) if schema is not None: + # Provider schemas strip nullability; use them for coercion, leaving validation to the tool. params = _coerce(params, schema) - try: - # Schemas may use local $defs; fetching arbitrary external refs is never part of tool execution. - error = next(Draft202012Validator(schema, registry=Registry()).iter_errors(params), None) - except Unresolvable as exc: - raise ValueError('Tool schema contains an unresolved reference.') from exc - if error: - path = '.'.join(str(part) for part in error.absolute_path) or 'arguments' - raise ValueError(f'Invalid {path}: {error.message}') _check_json_value(params) return params