[Python] AI Foundry - Remote MCP Server - Failure: Error - RequiresAction on ToolCall

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have a custom Remote MCP Server hosted on Azure written in Rust leveraging the "rmcp" crate. I have a python program to deploy the MCP Server (as an agent) into AI Foundry using "McpTool", I see that agent created and that all works fine. The Python program tests connectivity during the deployment like "list tools" and calls a tool to access some of the MCP information. Those all function well during the creation of the agent within the python program, also the MCP Server can be accessed by other Hosts like Claude.AI through a Python Proxy since there isn't native HTTP streaming support in the desktop version. The MCP server isn't suspect at this point, but the interconnection between it and AI Foundry.

    The problem is when I use the Agent in the Playground, I get an "Error: RequiresAction" when trying to execute a tool on the MCP server:

    {
    name: "run_Fhvco5aH9JbS5lceERHW7lDj"
    context: {
    trace_id: "thread_h2Ywxs8TigcIhlQEYSAm1LF4"
    span_id: "run_Fhvco5aH9JbS5lceERHW7lDj"
    thread_id: "thread_h2Ywxs8TigcIhlQEYSAm1LF4"
    }
    kind: "Run"
    parent_id: "thread_h2Ywxs8TigcIhlQEYSAm1LF4"
    start_time: "2025-09-04T17:34:25.000Z"
    end_time: undefined
    status: {
    status_code: "Error"
    description: "RequiresAction"
    }
    attributes: {
    span_type: "Run"
    }
    }


    I have done some digging and testing around this issue, it seems like this failure is due to the Client needing to get permission to run the tool, but this is not interactive within the playground. So guideance has pushed me to adding a set_approval_mode("never") to the McpTool definition (code fragment below), but this line seems to be ignored, as this doesn't get set into the MCP Agent Model.

    # ----------------------------------------------------------------------------
    # Azure AI Foundry helpers
    # ----------------------------------------------------------------------------

    def build_mcp_tool_for_foundry(session_id: str, allowed_tools: Optional[List[str]] = None) -> McpTool:
    """Build McpTool for Azure AI Foundry."""
    # Create McpTool with supported parameters only
    mcp_tool = McpTool(
    server_label=MCP_SERVER_LABEL,
    server_url=MCP_SERVER_URL,
    allowed_tools=allowed_tools or []
    )

    mcp_tool.set_approval_mode("never") # <-- disables approval prompts

    # Set headers
    mcp_tool.update_headers("Accept", "application/json, text/event-stream")
    mcp_tool.update_headers("Content-Type", "application/json")
    mcp_tool.update_headers("Accept-Encoding", "identity")
    mcp_tool.update_headers("SuperSecret", SUPER_SECRET)

    if session_id:
    mcp_tool.update_headers("Mcp-Session-Id", session_id)
    mcp_tool.update_headers("X-Session-Id", session_id)

    if AUTH_BEARER:
    mcp_tool.update_headers("Authorization", f"Bearer {AUTH_BEARER}")

    if VERBOSE:
    print(f"[MCP] Tool configured with {len(allowed_tools or [])} allowed tools")
    if allowed_tools:
    print(f"[MCP] Allowed tools: {', '.join(allowed_tools[:5])}")

    return mcp_tool


    Here is a redacted version of the "Agent" as listed in VS Code "Azure AI Foundry":

    # yaml-language-server: $schema=https://aka.ms/ai-foundry-vsc/agent/1.0.0
    # version of the agent schema
    version: 1.0.0
    name: mcp-agent

    # Give a description of your agent. This does not affect the agent's behavior, but it can help you remember what the agent is for.
    # Please use instructions to define the agent's behavior.
    description: null

    # unique identifier for the agent, should be set by the system when deploy complete
    # keep it empty when creating a new agent and do not change it when updating the agent
    id: asst_NKOCOTFHryz******

    # metadata for the agent, uncommented those lines if you want to add metadata
    # model id of the agent, can not be empty
    # Press SPACE to view a list of models currently connected to your project.
    model:
    id: gpt-4o
    options:
    temperature: 1
    top_p: 1
    # Give your agent clear directions on what to do and how to do it.
    # Include specific tasks, their order, and any special instructions like tone or engagement style.
    instructions: You are a helpful agent that can use MCP tools to assist users.

    # Add external tools to enhance your agent's abilities.
    tools:

    # Use MCP tools to interact with external services.
    - type: mcp
    id: QSCloud
    options:
    server_url: http://XXXXXXXXXX.azure-api.net/v1/mcp
    allowed_tools:
    - XXXXXXXXX
    - XXXXXXXXXX
    - XXXXXXXXXX
    - XXXXXXXXXX
    - XXXXXXXXXX


    I have tried a few other approaches recommended to try but they are usually syntactically incorrect. Anyone know why my attempt to set the approval to "never" is failing or know how to fix this issue?

    Continue reading...

Compartilhe esta Página