-
Notifications
You must be signed in to change notification settings - Fork 474
Description
Using langchain to call playwright mcp, this issue not repro in Microsoft MCP @playwright/mcp@latest".
The code is as below:
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_mcp_adapters.tools import load_mcp_tools
async def get_playwright_tools():
client = MultiServerMCPClient({
"playwright": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@executeautomation/playwright-mcp-server"]
}
})
async with client.session("playwright") as session:
tools = []
try:
tools = await load_mcp_tools(session)
for tool in tools:
print(f" - {tool.name} - {tool.description} - type: {type(tool)}")
except Exception as tool_error:
print(f" ✗ tool_error: {tool_error}")
import traceback
print(f" error detail: {traceback.format_exc()}")
if not tools:
print(" ⚠ warning: no tools available!")
The error message:
Failed to parse JSONRPC message from server
Traceback (most recent call last):
File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\mcp\client\stdio_init_.py", line 155, in stdout_reader
message = types.JSONRPCMessage.model_validate_json(line)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\pydantic\main.py", line 766, in model_validate_json
return cls.pydantic_validator.validate_json(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for JSONRPCMessage
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Shutdown signal received', input_type=str]
For further information visit https://errors.pydantic.dev/2.12/v/json_invalid
- Exception Group Traceback (most recent call last):
| File "c:\Users\Desktop\auto test code\AI_agent\langchain_demo\mcp\playwright_mcp_demo\playwright_mcp_绑定工具_.py", line 102, in
| tools= asyncio.run(get_playwright_tools())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
| return runner.run(main)
| ^^^^^^^^^^^^^^^^
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
| return self.loop.run_until_complete(task)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
| return future.result()
| ^^^^^^^^^^^^^^^
| File "c:\Users\Desktop\auto test code\AI_agent\langchain_demo\mcp\playwright_mcp_demo\playwright_mcp_绑定工具.py", line 35, in get_playwright_tools
| async with client.session("playwright") as session:
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 217, in aexit
| await anext(self.gen)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\langchain_mcp_adapters\client.py", line 123, in session
| async with create_session(self.connections[server_name]) as session:
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 217, in aexit
| await anext(self.gen)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\langchain_mcp_adapters\sessions.py", line 403, in create_session
| async with create_stdio_session(**params) as session:
| File "C:\Users\JIAFLIU\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 217, in aexit
| await anext(self.gen)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\langchain_mcp_adapters\sessions.py", line 228, in create_stdio_session
| async with (
| File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 217, in aexit
| await anext(self.gen)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\mcp\client\stdio_init.py", line 182, in stdio_client
| async with (
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\anyio_backends_asyncio.py", line 781, in aexit
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\mcp\client\stdio_init.py", line 155, in stdout_reader
| message = types.JSONRPCMessage.model_validate_json(line)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\pydantic\main.py", line 766, in model_validate_json
| return cls.pydantic_validator.validate_json(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pydantic_core.pydantic_core.ValidationError: 1 validation error for JSONRPCMessage
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Shutdown signal received', input_type=str]
For further information visit https://errors.pydantic.dev/2.12/v/json_invalid
|
| During handling of the above exception, another exception occurred:
|
| Traceback (most recent call last):
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\mcp\client\stdio_init.py", line 158, in stdout_reader
| await read_stream_writer.send(exc)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\anyio\streams\memory.py", line 243, in send
| self.send_nowait(item)
| File "C:\Users\Desktop\auto test code\AI_agent\venv\Lib\site-packages\anyio\streams\memory.py", line 214, in send_nowait
| raise BrokenResourceError
| anyio.BrokenResourceError
+------------------------------------