diff --git a/routes/chat.py b/routes/chat.py index 39cc33d..9ec277c 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -144,12 +144,11 @@ async def enhanced_generate_stream_response( is_ui_resource = ( msg.text and msg.text.lstrip().startswith('{"') - and ( - ('"ui://' in msg.text and ('"text/html' in msg.text or '"text/uri-list' in msg.text)) - or '"__ask_user__"' in msg.text - ) + and '"ui://' in msg.text + and ('"text/html' in msg.text or '"text/uri-list' in msg.text) ) - if config.tool_response or is_ui_resource: + is_ask_user = msg.name == 'ask_user' + if config.tool_response or is_ui_resource or is_ask_user: new_content = f"[{message_tag}] {msg.name}\n{msg.text}\n" # Collect full content diff --git a/skills/common/mcp-ui/ui_render_server.py b/skills/common/mcp-ui/ui_render_server.py index ea6bf0c..3f3536a 100644 --- a/skills/common/mcp-ui/ui_render_server.py +++ b/skills/common/mcp-ui/ui_render_server.py @@ -21,32 +21,20 @@ from mcp_common import ( ) -ASK_USER_MARKER = "__ask_user__" +ASK_USER_RESPONSE = "Questions sent to user." -def ask_user(questions: list) -> Dict[str, Any]: - """Create an ask_user response. +def ask_user() -> Dict[str, Any]: + """Return a minimal fixed response for ask_user tool. - Args: - questions: List of dicts, each with "question", "options", and "multi_select". - - Returns a JSON structure with a marker so the backend can detect it - and emit it as a special delta.ask_user event at the end of the stream. + The actual questions/options are already in the TOOL_CALL arguments, + so the frontend parses them directly from there. This response only + serves to acknowledge the tool call and minimize token usage in the + subsequent LLM inference round. """ - normalized = [] - for q in questions: - normalized.append({ - "question": q.get("question", ""), - "options": q.get("options", []), - "multi_select": q.get("multi_select", False), - }) - payload = { - "__type__": ASK_USER_MARKER, - "questions": normalized, - } return { "content": [ - {"type": "text", "text": json.dumps(payload, ensure_ascii=False)} + {"type": "text", "text": ASK_USER_RESPONSE} ] } @@ -168,7 +156,7 @@ async def handle_request(request: Dict[str, Any]) -> Dict[str, Any]: request_id, -32602, "Missing required parameter: questions" ) - result = ask_user(questions) + result = ask_user() return {"jsonrpc": "2.0", "id": request_id, "result": result} else: