MCPAgent.run() server_name is obsolete: how do I limit a run to specific servers?
In mcp-use (mcp-use/mcp-use), the docs still describe a server_name parameter in MCPAgent.run(), but according to the issue reporter, referencing issue #52, it is obsolete because the implementation changed. How do you limit a run to specific servers with the current API? Issue #53, opened 2025-05-07, closed as completed.
Originally asked on GitHub: https://github.com/mcp-use/mcp-use/issues/82
2 answers
The issue is closed as completed, and a maintainer (comment 2) acknowledged the report and said they would fix it and post the solution. That follow-up is not in this thread, so the only proven approach here is the community workaround from comment 1.
The reporter stated, referencing issue #52, that
server_nameinMCPAgent.run()is obsolete because the implementation changed, while the documentation still describes it. The workaround is to pick the server when creating the session instead of passingserver_nameto the run:pythonclient = MCPClient.from_config_file( os.path.join(os.path.dirname(__file__), "mcp_configs.json") ) await client.create_session("airbnb") # only this server gets a session agent = MCPAgent(llm=llm, client=client, max_steps=30) result = await agent.run( "Find me a nice place to stay in Barcelona for 2 adults for a week in August...", max_steps=30, )The commenter reported this got around the removed parameter. Clean up in a
finallyblock withawait client.close_all_sessions(). The thread example usesChatAnthropic(model="claude-3-5-sonnet-20240620")with the API key loaded from the environment via python-dotenv.So in practice, limiting a run to specific servers means creating sessions only for those servers via
client.create_session(<server_name>). As general advice, make sure the name you pass matches a server key in yourmcp_configs.json. Since the maintainer's official fix isn't posted in this thread, check the repository's current documentation if you are on a newer release.Did this work for you?What @ogulcanakca tried on GitHub (Worked)
Replaced the removed server_name parameter by creating the session explicitly: loaded configs with MCPClient.from_config_file(), called await client.create_session("airbnb"), then ran agent.run() without server_name. The commenter reported this worked as a workaround.
Source: https://github.com/mcp-use/mcp-use/issues/82#issuecomment-2870012902 (opens external site)
Did this work for you?
Related questions
- How to stream output from mcp-use MCPAgent like LangChain's agent_executor?
- Does mcp-use support the MCP Streamable HTTP transport?
- Can I use mcp-use with Python 3.10?
- mcp-use: tool call with invalid action input fails the whole run and never retries
- How to set the startup timeout for a local MCP server connection in mcp-use?