From 5ee159a4b343bac1c5575788366d31bc836331fc Mon Sep 17 00:00:00 2001 From: 633WHU Date: Sun, 3 Aug 2025 21:52:03 +0800 Subject: [PATCH] perf: optimize string operations in OpenAPI parameter processing (#1342) --- src/fastmcp/utilities/openapi.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/fastmcp/utilities/openapi.py b/src/fastmcp/utilities/openapi.py index 044d58aa3..886456ca7 100644 --- a/src/fastmcp/utilities/openapi.py +++ b/src/fastmcp/utilities/openapi.py @@ -82,13 +82,9 @@ def format_array_parameter( return values else: # For path parameters, fallback to string representation without Python syntax - str_value = ( - str(values) - .replace("[", "") - .replace("]", "") - .replace("'", "") - .replace('"', "") - ) + # Use str.translate() for efficient character removal + translation_table = str.maketrans("", "", "[]'\"") + str_value = str(values).translate(translation_table) return str_value