-
Notifications
You must be signed in to change notification settings - Fork 228
Open
Description
When I use MCP on a sub-agent under the supervisor multi-agent and test it with langgraph-cli, I find that 1. a repeated loop; 2. a blocking when calling a method. However, when running it locally, the results are returned normally.
# graph.py
from contextlib import asynccontextmanager
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langgraph_supervisor import create_supervisor
from langchain.chat_models import init_chat_model
async def make_graph():
MCP_DIR = r"xxxxxxxx"
client = MultiServerMCPClient(
{
"desktop-commander": {
"command": "npx",
"args": [
"--no-install",
"--yes",
"@wonderwhy-er/desktop-commander",
"serve",
"--no-onboarding"
],
"transport": "stdio",
"cwd": MCP_DIR
},
"ssh-mcp-server": {
"command": "npx",
"args": [
"--no-install",
"-y",
"@fangjunjie/ssh-mcp-server",
"--host", "xxxxxx",
"--port", "22",
"--username", "xxxxx",
"--password", "xxxxx",
],
"transport": "stdio",
"cwd": MCP_DIR
}
}
)
tools = await client.get_tools()
Filesystem_tools = [t for t in tools if t.name in {
'read_file', 'read_multiple_files', 'write_file', 'create_directory',
'list_directory', 'move_file', 'get_file_info', 'edit_block',
'start_search', 'stop_search', 'list_searches', 'get_more_search_results'
}]
Terminal_tools = [t for t in tools if t.name in {
'start_process', 'read_process_output', 'interact_with_process',
'force_terminate', 'list_sessions', 'list_processes', 'kill_process'
}]
SSH_tools = [t for t in tools if t.name in {
'execute-command', 'upload', 'download', 'list-servers'
}]
llm = init_chat_model(
model="qwen3:14b",
model_provider="ollama",
base_url="http://localhost:11434",
)
filesystem_agent = create_react_agent(
llm,
tools=Filesystem_tools,
prompt="""xxxxxx""",
name="filesystem_agent",
)
terminal_agent = create_react_agent(
llm,
tools=Terminal_tools,
prompt="""xxxxxx""",
name="terminal_agent",
)
ssh_agent = create_react_agent(
llm,
tools=SSH_tools,
prompt="""xxxxxx""",
name="ssh_agent",
)
agent = create_supervisor(
model=llm,
agents=[filesystem_agent, terminal_agent, ssh_agent],
prompt='xxxxxx',
add_handoff_back_messages=True,
output_mode="full_history",
).compile()
return agent
if __name__ == '__main__':
# 'langgraph dev --allow-blocking'
import asyncio
async def main():
graph = await make_graph()
result = await graph.ainvoke(
input={"messages": [{"role": "user", "content": r"SSH remote connection to the server and check the disk space"}]}
)
print("Agent Invocation Result:")
print(result)
asyncio.run(main())
The test cases are:List the files/folders under "/PATH". The filesystem_agent will always ask "I'm here to help with file system tasks. What would you like to do?" The same prompt will work fine when running locally.

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels