From 949aeb113115747c5d33d140005ad05aa8c40d10 Mon Sep 17 00:00:00 2001 From: Yukuan Jia Date: Wed, 24 Sep 2025 16:42:11 +0800 Subject: [PATCH 1/4] fix: fix the system message in simple-chatbot example --- examples/clients/simple-chatbot/mcp_simple_chatbot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py index 65e0dde03..baff5f352 100644 --- a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py +++ b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py @@ -344,7 +344,7 @@ async def start(self) -> None: "Choose the appropriate tool based on the user's question. " "If no tool is needed, reply directly.\n\n" "IMPORTANT: When you need to use a tool, you must ONLY respond with " - "the exact JSON object format below, nothing else:\n" + "the exact JSON object format below without the triple backticks fences, nothing else:\n" "{\n" ' "tool": "tool-name",\n' ' "arguments": {\n' From dfaad4ffa8bced45d5170cd0ecfa3acb9c3370d2 Mon Sep 17 00:00:00 2001 From: Yukuan Jia Date: Wed, 24 Sep 2025 23:08:10 +0800 Subject: [PATCH 2/4] Revert "fix: fix the system message in simple-chatbot example" This reverts commit 949aeb113115747c5d33d140005ad05aa8c40d10. --- examples/clients/simple-chatbot/mcp_simple_chatbot/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py index baff5f352..65e0dde03 100644 --- a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py +++ b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py @@ -344,7 +344,7 @@ async def start(self) -> None: "Choose the appropriate tool based on the user's question. " "If no tool is needed, reply directly.\n\n" "IMPORTANT: When you need to use a tool, you must ONLY respond with " - "the exact JSON object format below without the triple backticks fences, nothing else:\n" + "the exact JSON object format below, nothing else:\n" "{\n" ' "tool": "tool-name",\n' ' "arguments": {\n' From 0fcd21b73217f8a056edb8e00118a74509d051c9 Mon Sep 17 00:00:00 2001 From: Yukuan Jia Date: Wed, 24 Sep 2025 23:12:42 +0800 Subject: [PATCH 3/4] fix: remove the backticks wrapper for JSON in simple-chatbot example --- .../clients/simple-chatbot/mcp_simple_chatbot/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py index 65e0dde03..c27f7ffdc 100644 --- a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py +++ b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py @@ -291,8 +291,15 @@ async def process_llm_response(self, llm_response: str) -> str: """ import json + def _clean_json_string(json_string: str) -> str: + """Remove ```json ... ``` or ``` ... ``` wrappers if the LLM response is fenced.""" + import re + + pattern = r'^```(?:\s*json)?\s*(.*?)\s*```$' + return re.sub(pattern, r'\1', json_string, flags=re.DOTALL | re.IGNORECASE).strip() + try: - tool_call = json.loads(llm_response) + tool_call = json.loads(_clean_json_string(llm_response)) if "tool" in tool_call and "arguments" in tool_call: logging.info(f"Executing tool: {tool_call['tool']}") logging.info(f"With arguments: {tool_call['arguments']}") From 1ccaa19a36f61c0cccfbad4ca3b9c7671375a928 Mon Sep 17 00:00:00 2001 From: Yukuan Jia Date: Fri, 26 Sep 2025 11:06:40 +0800 Subject: [PATCH 4/4] fix: use double quotes instead of single quotes in simple-chatbot example --- examples/clients/simple-chatbot/mcp_simple_chatbot/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py index c27f7ffdc..1a30578b6 100644 --- a/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py +++ b/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py @@ -295,8 +295,8 @@ def _clean_json_string(json_string: str) -> str: """Remove ```json ... ``` or ``` ... ``` wrappers if the LLM response is fenced.""" import re - pattern = r'^```(?:\s*json)?\s*(.*?)\s*```$' - return re.sub(pattern, r'\1', json_string, flags=re.DOTALL | re.IGNORECASE).strip() + pattern = r"^```(?:\s*json)?\s*(.*?)\s*```$" + return re.sub(pattern, r"\1", json_string, flags=re.DOTALL | re.IGNORECASE).strip() try: tool_call = json.loads(_clean_json_string(llm_response))