First, thank you to the AgentCore MCP server maintainers — the browser primitive is genuinely useful for agentic web automation.
Summary
The browser_evaluate tool serializes object/array results with json.dumps(...) but omits ensure_ascii=False. As a result, non-ASCII text (CJK, emoji, accented Latin, etc.) in an object/array result is returned as \uXXXX escape sequences rather than the original characters.
The same function's scalar-string path (isinstance(result, (str, int, float, bool))) already returns the text verbatim, so the same underlying string renders differently depending only on the shape of the JS return value — a scalar string is fine, but the moment it's wrapped in an object or array it gets escaped.
Where
src/amazon-bedrock-agentcore-mcp-server/awslabs/amazon_bedrock_agentcore_mcp_server/tools/browser/observation.py, in ObservationTools.browser_evaluate (~L325-331):
if isinstance(result, (str, int, float, bool)):
return f'Result: {result}' # scalar: verbatim, e.g. "東京" → 東京
return f'Result:\n{json.dumps(result, indent=2, default=str)}' # object/array: escaped → 東京
Reproduction (observed behavior)
Evaluating an expression that returns a scalar string vs. an object containing the same string:
page.evaluate() returns |
browser_evaluate output |
'東京' (scalar) |
Result: 東京 ✅ |
{'city': '東京', 'emoji': '🌐'} (object) |
Result:\n{\n "city": "東京",\n "emoji": "🌐"\n} ❌ |
The escaped form is harder for an LLM/agent to read and is inconsistent with the scalar path.
Suggested fix
Add ensure_ascii=False to the json.dumps call so the object/array path matches the scalar path. This is the same convention the bedrock-kb-retrieval server fix uses (#3820/#3821) — note this is a different server, so it's tracked separately.
I'm happy to open a PR (already prepared locally with a regression test). Please let me know if you'd prefer a different approach.
First, thank you to the AgentCore MCP server maintainers — the browser primitive is genuinely useful for agentic web automation.
Summary
The
browser_evaluatetool serializes object/array results withjson.dumps(...)but omitsensure_ascii=False. As a result, non-ASCII text (CJK, emoji, accented Latin, etc.) in an object/array result is returned as\uXXXXescape sequences rather than the original characters.The same function's scalar-string path (
isinstance(result, (str, int, float, bool))) already returns the text verbatim, so the same underlying string renders differently depending only on the shape of the JS return value — a scalar string is fine, but the moment it's wrapped in an object or array it gets escaped.Where
src/amazon-bedrock-agentcore-mcp-server/awslabs/amazon_bedrock_agentcore_mcp_server/tools/browser/observation.py, inObservationTools.browser_evaluate(~L325-331):Reproduction (observed behavior)
Evaluating an expression that returns a scalar string vs. an object containing the same string:
page.evaluate()returnsbrowser_evaluateoutput'東京'(scalar)Result: 東京✅{'city': '東京', 'emoji': '🌐'}(object)Result:\n{\n "city": "東京",\n "emoji": "🌐"\n}❌The escaped form is harder for an LLM/agent to read and is inconsistent with the scalar path.
Suggested fix
Add
ensure_ascii=Falseto thejson.dumpscall so the object/array path matches the scalar path. This is the same convention the bedrock-kb-retrieval server fix uses (#3820/#3821) — note this is a different server, so it's tracked separately.I'm happy to open a PR (already prepared locally with a regression test). Please let me know if you'd prefer a different approach.