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

azure-ai-agents: MCP usage errors with Azure AI Foundry

Open jacobreesmontgomery opened this issue 1 year ago • 47 comments

  • Packages:
    • azure-ai-projects: 1.0.0b10
    • azure-ai-agents: 1.2.0b1
  • Operating System: macOS Sequoia 15.5
  • Python Version: 3.11.8

Describe the bug I've been having issues using the MCP integrations with Azure AI Foundry agents. Specifically, there are two things:

  1. An AssertionError is frequently occurring. It's happened for both GitMCP and Tavily's MCP servers. I have yet to try more MCP servers, but I suspect I'll continue to see these errors coming up. See the error below.
  2. I'm seeing repeated failures to invoke the tools provided to the agent for these MCP servers, resulting in unsatisfactory answers. See below for the error.
    • Perhaps I need to provide more specific instructions to the agent to guide it towards invoking the tools provided? I would think the agent would be smart enough to know as is without more specific prompting.

Error to problem 1

The result with the error:

{
  "data": {
    "response": "I encountered an issue while trying to get the current weather information for Seattle. You can check a reliable weather website or app for real-time updates. Alternatively, if you need general information about Seattle's climate or typical weather patterns, feel free to ask!"
  },
  "meta": {
    "run_steps": [
      {
        "id": "step_hgixrj0R0tORvoMZpTkf14cN",
        "object": "thread.run.step",
        "created_at": 1754658900,
        "run_id": "run_cT1NcPI13R3b88JJA9oDq179",
        "assistant_id": "asst_GyjPbDs3XfMbSrv0VehZmcFv",
        "thread_id": "thread_jlp4vdxxi3HlI7F5E67A6jEC",
        "type": "message_creation",
        "status": "completed",
        "cancelled_at": null,
        "completed_at": 1754658901,
        "expires_at": null,
        "failed_at": null,
        "last_error": null,
        "step_details": {
          "type": "message_creation",
          "message_creation": {
            "message_id": "msg_q8TpSGSexr47v7Pb0nImYnbc"
          }
        },
        "usage": {
          "prompt_tokens": 152,
          "completion_tokens": 52,
          "total_tokens": 204,
          "prompt_token_details": {
            "cached_tokens": 0
          }
        }
      },
      {
        "id": "step_ovu486RNvTcTKZ0zIBUmEB72",
        "object": "thread.run.step",
        "created_at": 1754658900,
        "run_id": "run_cT1NcPI13R3b88JJA9oDq179",
        "assistant_id": "asst_GyjPbDs3XfMbSrv0VehZmcFv",
        "thread_id": "thread_jlp4vdxxi3HlI7F5E67A6jEC",
        "type": "tool_calls",
        "status": "completed",
        "cancelled_at": null,
        "completed_at": 1754658900,
        "expires_at": null,
        "failed_at": null,
        "last_error": null,
        "step_details": {
          "type": "tool_calls",
          "tool_calls": [
            {
              "id": "call_UWl9nlG2w8akjCWKLMpgdeKi",
              "type": "mcp",
              "arguments": "{\"location\":\"Seattle, WA\"}",
              "name": "weather",
              "server_label": "tavily",
              "output": "content_type='system_error' name='AssertionError' text=\"Encountered exception: <class 'AssertionError'>.\""
            }
          ]
        },
        "usage": {
          "prompt_tokens": 106,
          "completion_tokens": 19,
          "total_tokens": 125,
          "prompt_token_details": {
            "cached_tokens": 0
          }
        }
      }
    ]
  }
}

Error to problem 2

{
  "data": {
    "response": "I currently don't have real-time capabilities to check the latest weather. However, you can easily find the current weather in Seattle by checking a weather website or app like Weather.com, the Weather Channel, or a local news website. Alternatively, you can use a digital assistant on your phone or smart device to get the latest weather update."
  },
  "meta": {
    "run_steps": [
      {
        "id": "step_47k5HIxdJe4D1T02IvGfzqZ5",
        "object": "thread.run.step",
        "created_at": 1754659678,
        "run_id": "run_HF0DgO0m9n8PhVZyYqMKz7JL",
        "assistant_id": "asst_xOCNz0JcZ2yMbzbDDZ96FIee",
        "thread_id": "thread_uKI5zjsP5xAIhXfJ9rEO0x43",
        "type": "message_creation",
        "status": "completed",
        "cancelled_at": null,
        "completed_at": 1754659679,
        "expires_at": null,
        "failed_at": null,
        "last_error": null,
        "step_details": {
          "type": "message_creation",
          "message_creation": {
            "message_id": "msg_ThsZroUC9qje77hFJuPTuSR8"
          }
        },
        "usage": {
          "prompt_tokens": 106,
          "completion_tokens": 68,
          "total_tokens": 174,
          "prompt_token_details": {
            "cached_tokens": 0
          }
        }
      }
    ]
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Create a Foundry agent integrated with the Tavily MCP server:
    • server_label: "tavily"
    • server_url: "https://mcp.tavily.com/mcp/?tavilyApiKey=<MY_TAVILY_API_KEY>",
    • allowed_tools: ["tavily-search"]
  2. Ask the agent something like "What is the weather in Seattle today?"
  3. Repeat the above two steps a handful of times to see both problems outlined above.

Expected behavior I would expect two things:

  1. No assertion errors when the tavily-search tool is invoked.
  2. The tool always being invoked (although I understand there's a level of non-determinism to agents).

Screenshots N/A

Additional context

  • The agent is using model gpt-4o with a provided temperature of 0.7.
  • The agent's instructions are very basic: You are a helpful assistant. When appropriate, use the available tools to help answer the user's query..

jacobreesmontgomery avatar Aug 08 '25 13:08 jacobreesmontgomery

Also, when the tool is successfully invoked, accomplished after changing the prompt to be more enforcing, I am still seeing a failure result:

  "detail": "An unexpected error occurred: Failed to process query: Agent run failed: server_error - Sorry, something went wrong.",

This is the only context I receive in the logs which isn't particularly insightful. I can remote debug into your SDK, although more insightful logging would be ideal.

jacobreesmontgomery avatar Aug 08 '25 13:08 jacobreesmontgomery

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 08 '25 14:08 github-actions[bot]

@jacobreesmontgomery We are aware of multiple issues involving MCP tool usage in Agents and are triaging them now.

@apryiomka FYI

glharper avatar Aug 08 '25 16:08 glharper

I’m facing the same issue. Is there any update or workaround available?

abhilashknair avatar Aug 10 '25 12:08 abhilashknair

Having the exact same issue, it was working fine Friday but now getting the unhelpful 'server_error' response. Is there any update on this?

jbaconCCG avatar Aug 11 '25 13:08 jbaconCCG

@jacobreesmontgomery can you please confirm the region for the ai service account where you observe the error?

apryiomka avatar Aug 11 '25 15:08 apryiomka

@jacobreesmontgomery can you please confirm the region for the ai service account where you observe the error?

eastus2

jacobreesmontgomery avatar Aug 11 '25 17:08 jacobreesmontgomery

We're facing the same issue. all our agents in dev and prod are down.

ehsan-aculis avatar Aug 11 '25 17:08 ehsan-aculis

We were able to identify the issue. We will be rolling out a hotfix in production soon.

apryiomka avatar Aug 11 '25 20:08 apryiomka

We were able to identify the issue. We will be rolling out a hotfix in production soon.

Hi how soon will it be live? I really need it today😅. Is REST an alternative until than or is that also broken?

Luzors avatar Aug 12 '25 02:08 Luzors

The fix was deployed in the following production regions:

  • West US 2
  • West US
  • Norway East
  • Switzerland North
  • UAE North
  • South India

More regions will be deployed tomorrow. The fix should be deployed in all regions by the end of week. Your connected AI Service Account, not the project, must be in one of the list regions.

apryiomka avatar Aug 12 '25 03:08 apryiomka

All working in Switzerland North again this morning!

jbaconCCG avatar Aug 12 '25 08:08 jbaconCCG

More regions will be deployed tomorrow. The fix should be deployed in all regions by the end of week. Your connected AI Service Account, not the project, must be in one of the list regions.

Is swedencentral planned for today? 🥺

abhilashknair avatar Aug 12 '25 11:08 abhilashknair

Can you update us here as you continue to deploy to more regions please? I'm EAST US2.

jacobreesmontgomery avatar Aug 12 '25 11:08 jacobreesmontgomery

Hello, can you please provide an update for the East region?

artex323 avatar Aug 12 '25 14:08 artex323

The fix is now available in these regions:

  • West US 3
  • Japan East
  • UK South
  • Poland Central

More regions, including East US 2 should be available on Wednesday. East US and Sweden Central should be available on Thursday.

Thanks.

apryiomka avatar Aug 12 '25 16:08 apryiomka

Hi apryiomka, Ty for the help, Has the fix already been applied in the East 2 region?

artex323 avatar Aug 13 '25 15:08 artex323

The fix is now available in these regions:

  • France Central
  • Australia East
  • East US 2

Tomorrow we plan to deploy in East US and Sweden Central. Thanks everyone for your patience.

apryiomka avatar Aug 13 '25 16:08 apryiomka

@apryiomka Great to hear. Please let us know when you've deployed to East US & Sweden Central. Eager to start using it again. 😄 Thanks for excellent communication!

mtnptrsn avatar Aug 14 '25 11:08 mtnptrsn

@apryiomka, thanks for your help. I'm still seeing that server_error though in certain MCP cases like with the remote Tavily MCP server. I'm also seeing the above assertion error still when trying to use the GitMCP server.

jacobreesmontgomery avatar Aug 14 '25 15:08 jacobreesmontgomery