azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Cannot add multiple MCP servers to agent

Open cqzheng opened this issue 1 year ago • 6 comments

  • Package Name: azure-ai-agents
  • Package Version: 1.2.0b2
  • Operating System: Windows
  • Python Version: 3.11.9

Describe the bug Can not connect to multiple MCP servers. According the document, https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/model-context-protocol?utm_source=chatgpt.com, multiple MCP servers can be supported for an agent. But when create two McpTool objects with two different MCP server information and call ToolSet.add(), exception will be thrown.

To Reproduce Below is the sample codes causing exception.

mcp_toolset = ToolSet() mcp_tool1 = McpTool(server_label="label1",server_url="url1") mcp_toolset.add(mcp_tool1) mcp_tool2 = McpTool(server_label="label2",server_url="url2") mcp_toolset.add(mcp_tool2) ------> Here exception will be thrown that not allow two tools with same type added to ToolSet(). Below is the exception information.

raise ValueError("Tool of type {type(tool).__name__} already exists in the ToolSet.")

ValueError: Tool of type {type(tool).name} already exists in the ToolSet.

Expected behavior Multiple MCP servers should be configured with agent successfully

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

cqzheng avatar Aug 26 '25 01:08 cqzheng

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dargilco @glharper @howieleung @jhakulin @nick863 @trangevi.

github-actions[bot] avatar Aug 26 '25 14:08 github-actions[bot]

@cqzheng Please don't use ToolSet for this, ToolSet only accepts one or less instances of each tool type at the moment. Instead, add both McpTool instances to the tools parameter in create_agent, ala

    agent = agents_client.create_agent(
        model=os.environ["MODEL_DEPLOYMENT_NAME"],
        name="<agent_name>",
        instructions="<agent_instructions>",
        tools=[
            mcp_tool1.definitions[0],
            mcp_tool2.definitions[0],
        ],
    )

glharper avatar Aug 26 '25 15:08 glharper

Hi @cqzheng. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar Aug 26 '25 15:08 github-actions[bot]

/unresolve

cqzheng avatar Aug 28 '25 02:08 cqzheng

@glharper Thanks for your sample codes. I tried it and it did works. Here I have some more questions.

  1. How to pass tool_resources? How to combine tool_resources from both mcp_tools. I am use the stream interface, agents_client.runs.stream
  2. Will ToolSet be updated to support multiple mcp servers in future release?

Thanks.

cqzheng avatar Aug 28 '25 02:08 cqzheng

@glharper Thanks for your sample codes. I tried it and it did works. Here I have some more questions.

  1. How to pass tool_resources? How to combine tool_resources from both mcp_tools. I am use the stream interface, agents_client.runs.stream
  2. Will ToolSet be updated to support multiple mcp servers in future release?

Thanks.

  1. This is not super easy currently, but doable:
    tool_resources = mcp_tool1.resources
    tool_resources["mcp"].extend(mcp_tool2["mcp"][0])

Expect a static class method to merge multiple mcp_tools into a ToolResources instance in the next release.

  1. Yes, there is a PR out now

glharper avatar Aug 28 '25 13:08 glharper