Azure / Azure/LogicAppsUX

Agent Loop: "An item with the same key has already been added. Key: {tool_name}" when using McpClientTool & MCP OAuth Doesn't work.

Open
#9,136 1 comment 0 reactions 0 assignees View on GitHub
MCP needs triage
Dominant language
TypeScript
Stars
111
Forks
109
Avg merge
1d 23h
Merged PRs (30d)
20

Description

### Severity

P1 - Critical (Blocking production)

### Describe the Bug with repro steps

### Describe the Bug

## Description

When adding a `McpClientTool` to an Agent Loop `tools` block, the workflow fails at runtime regardless of the key name used — including the designer-generated default `MCP_server`.

**Error:**

BadRequest – The request sent to the agent failed with the following error:
'HTTP request failed: 'An item with the same key has already been added. Key: {tool_name}'.'

### Plan Type

Standard

### Steps to Reproduce the Bug or Issue

## Steps to Reproduce

1. Create a Stateful workflow with an `Agent` action
2. Add a `McpClientTool` under `tools` with any key name (e.g. `MCP_server`, `ArithmeticMCP`)
3. Trigger the workflow

## Expected Behavior

Agent executes and routes calls to MCP tools correctly.

## Actual Behavior

Immediate `BadRequest` — duplicate key error referencing the MCP tool key name.

## Key Observations

- Happens with **any key name** — not just `MCP_server`
- The key appears **exactly once** in the workflow JSON — no actual duplicate in the definition
- Suggests the runtime registers the tool name internally before processing the user definition, causing the collision

## Workflow JSON (sanitized)

```json
"tools": {
"ArithmeticMCP": {
"type": "McpClientTool",
"kind": "Builtin",
"inputs": {
"parameters": {
"allowedTools": [
"wf_arithmetic_add",
"wf_arithmetic_sub",
"wf_arithmetic_mul",
"wf_arithmetic_div",
"wf_arithmetic_mod",
"wf_arithmetic_pow",
"wf_arithmetic_sqrt"
]
},
"connectionReference": {
"connectionName": "mcpclient"
}
}
},
"SendTheFinalResult": { ... }
}
```

### Workflow JSON

```json
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"actions": {
"Agent": {
"type": "Agent",
"inputs": {
"parameters": {
"deploymentId": "gpt-5-chat",
"messages": [
{
"role": "system",
"content": "You are a maths agent that solves arithmetic expressions following BODMAS order (Brackets, Orders/powers, Division, Multiplication, Addition, Subtraction).\n\nYou have access to arithmetic tools via an MCP server — use them for every calculation, do NOT compute in your head.\n\nApproach:\n1. Parse the expression and identify the correct BODMAS evaluation order.\n2. Call the appropriate MCP tool for each sub-expression, in order.\n3. Substitute the result back and continue until fully resolved.\n4. Return a clear step-by-step breakdown showing each tool call and its result, followed by the final answer.\n\nIf the expression is invalid or undefined (e.g. divide by zero), explain why."
},
{
"role": "user",
"content": "Solve this expression: @{triggerBody()?['expression']}"
}
],
"agentModelType": "AzureOpenAI",
"agentModelSettings": {
"agentHistoryReductionSettings": {
"agentHistoryReductionType": "maximumTokenCountReduction",
"maximumTokenCount": 128000
},
"deploymentModelProperties": {
"name": "gpt-5-chat",
"format": "OpenAI",
"version": "2025-10-03"
}
}
},
"modelConfigurations": {
"model1": {
"referenceName": "agent"
}
}
},
"tools": {
"ArithmeticMCP": {
"type": "McpClientTool",
"kind": "Builtin",
"inputs": {
"parameters": {
"allowedTools": [
"wf_arithmetic_add",
"wf_arithmetic_div",
"wf_arithmetic_mod",
"wf_arithmetic_mul",
"wf_arithmetic_pow",
"wf_arithmetic_sqrt",
"wf_arithmetic_sub"
]
},
"connectionReference": {
"connectionName": "mcpclient"
}
}
},
"SendTheFinalResult": {
"actions": {
"Terminate": {
"type": "Terminate",
"inputs": {
"runStatus": "Succeeded"
},
"runAfter": {
"NotifyResultToUser": [
"SUCCEEDED"
]
}
},
"NotifyResultToUser": {
"type": "Compose",
"inputs": "@agentParameters('MathResult')"
}
},
"description": "Send the final result to the user",
"agentParameterSchema": {
"type": "object",
"properties": {
"MathResult": {
"type": "string",
"description": "Result of the Math Equation"
}
},
"required": [
"MathResult"
]
}
}
},
"runAfter": {},
"limit": {
"count": 100
}
}
},
"outputs": {},
"triggers": {
"ReqMsg": {
"type": "Request",
"kind": "Http",
"inputs": {
"method": "POST",
"schema": {
"type": "object",
"properties": {
"expression": {
"type": "string"
}
}
}
}
}
}
},
"kind": "Stateful"
}
```

### Screenshots or Videos

Image

### Additional context

## Additional Context

- MCP Server is a **Logic Apps Standard** workflow exposed as an MCP server
- MCP Server is configured with **anonymous authentication**
- Auth is **not** a factor — the error occurs before any MCP call is made, at agent initialization
- The duplicate key exception is thrown by the Agent Loop runtime itself during tool registration, not by the MCP server or connection layer
- Both the **Agent Loop** and the **MCP Server** are Logic Apps Standard deployed on **App Service Plan(ASP)**
- MCP endpoint is reachable and functional when called directly outside the Agent Loop

## Intermittent Behavior

- The error is **not consistent** — some runs fail with the duplicate key error, others succeed with identical configuration
- No code or configuration changes between failing and succeeding runs
- Suggests a **race condition** in the Agent Loop tool registration phase, where the runtime occasionally registers the MCP tool key twice before the workflow executes
- Failure rate appears random with no clear pattern tied to time, load, or input

Image

MCP Connector also doesn't support OAuth authorization. Error happens at tool registration, before any MCP call is made

Image

Image

Via Postman
Image

Not able to trigger the workflow:
Image

Works from Postman

Image

### What type of Logic App Is this happening in?

Standard (Portal)

### Are you experiencing a regression?

_No response_

### Which operating system are you using?

Windows

### Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

### Workflow JSON

```json

```

### Screenshots or Videos

Image

--

### Environment

## Environment

- Logic Apps Standard on ASP
- Agent Loop with `McpClientTool` (`Builtin` kind)
- MCP connection via `mcpclient` connection reference
- Stateful workflow

### Additional context

MCP Server is a Logic Apps Standard workflow exposed as an MCP server
MCP Server is configured with anonymous authentication
Auth is not a factor — the error occurs before any MCP call is made, at agent initialization
The duplicate key exception is thrown by the Agent Loop runtime itself during tool registration, not by the MCP server or connection layer
Both the Agent Loop and the MCP Server are Logic Apps Standard deployed on App Service Plan(ASP)
MCP endpoint is reachable and functional when called directly outside the Agent Loop

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Stateful Agent workflow with McpClientTool and the supplied workflow JSON, comparing failing and successful runs. Investigate tool registration before the first MCP call; done means the workflow runs reliably without duplicate-key errors and the OAuth behavior is clarified or fixed.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.