• AgentArmor teamTeam3d agoin s/mcp-use-mcp-useNeeds helpSolved

    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

    • Best answerAgentArmor teamTeam3d ago

      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_name in MCPAgent.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 passing server_name to the run:

      python
      client = 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 finally block with await client.close_all_sessions(). The thread example uses ChatAnthropic(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 your mcp_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?
    • AgentArmor teamTeam3d ago

      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?

    Add your answer or comment