🧩 Consume an MCP Endpoint from Azure Logic Apps — with an Agent Loop
Want your Logic App to think, pick the right MCP tool, build the JSON-RPC payload, and call your MCP server — all in one run?
This post shows exactly that: how to establish a session, discover tools from an MCP server, and let the Logic Apps “Agent” action loop until the task is done.
We’ll use a simple example: you POST a math expression to the Logic App; the Agent discovers available MCP tools, selects the right one, constructs tools/call
, invokes your MCP server, and returns the final result.
⚡ What you’ll build
Flow (high-level):
-
Trigger: HTTP request with a
MathEquation
string. -
Establish a session: Call
initialize
on the MCP server endpoint → captureMcp-Session-Id
.- 2.1 MCP Server URL:
https://<your-mcp-server-url>/api/mcp
(MCPArithmetic Server, authentication set as anonymous)
- 2.1 MCP Server URL:
-
Discover tools: Call
tools/list
→ store the available tool catalog. - Agent loop: Logic Apps Agent picks the right tool and calls it via a custom InvokeMCPTools tool (HTTP action under the hood).
- Return: Final result (plain text or JSON) back to the caller.
🔗 Establish a Session (initialize
)
The first HTTP call is to the MCP endpoint with the initialize
method:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": {
"listChanged": true
}
},
"clientInfo": {
"name": "LogicApps",
"version": "1.0.0"
}
}
}
The MCP server responds with headers containing a session id:
Mcp-Session-Id: <guid>
📝 Note: Save this Mcp-Session-Id
into a Logic Apps variable (mcpSessionId
).
You must include it in all subsequent MCP requests.
🔍 Tool Discovery with tools/list
Once a session is established, the next step is to discover which MCP tools are available.
This is done by calling the MCP endpoint with the tools/list
method.
Request
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
Include the session header:
Mcp-Session-Id: @{variables('mcpSessionId')}
Response
The MCP server returns a catalog of available tools:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "wf_arithmetic_add",
"description": "Adds two numbers",
"parameters": {
"number1": "integer",
"number2": "integer"
}
},
{
"name": "wf_arithmetic_subtract",
"description": "Subtracts two numbers",
"parameters": {
"number1": "integer",
"number2": "integer"
}
}
]
}
}
In Logic Apps, save this JSON into a variable (mcpTools
).
The Agent will use this catalog to know which tool to call.
🔍 MCP Server Discovery (Screenshots)
Here are the actions in the designer:
Initialise (session), Get Tools (tools/list) and set variables
🤖 Agent Loop, Tool Invocation & Agent Parameters
This section shows how the Agent action plans, sets Agent Parameters, and invokes your MCP server through a custom tool (InvokeMCPTools).
1) Agent Loop — Overview
- The Agent receives:
- User input (e.g.,
@{triggerBody()?['MathEquation']}
) - The discovered tool catalog (
@{variables('mcpTools')}
)
- User input (e.g.,
- It chooses the correct tool from the catalog, prepares the JSON-RPC
tools/call
payload, and invokes the tool via the InvokeMCPTools wrapper. - The Agent returns only the final tool output (plain text or JSON), keeping internal reasoning hidden.
System prompt reminder: instruct the Agent to use InvokeMCPTools, pick the right tool, build a valid payload, and return only the final result.
2) Tool Wrapper: InvokeMCPTools
The Agent needs a wrapper tool that knows how to make an HTTP POST to the MCP endpoint.
Inside Logic Apps, this wrapper looks like:
{
"jsonrpc": "2.0",
"id": "@{guid()}",
"method": "tools/call",
"params": {
"name": "@{agentParameters('mcpToolName')}",
"arguments": "@outputs('ArgumentJson')"
}
}
3) 🛠️ Tool Invocation with Agent Parameters
When the Agent calls InvokeMCPTools
, it must provide two parameters.
Parameter | Type | Purpose | Example |
---|---|---|---|
mcpToolName |
string | Exact identifier of the MCP tool | "wf_arithmetic_add" |
mcpToolPayload |
string | Stringified JSON of the tool arguments | "{\"number1\":25,\"number2\":10}" |
Flow inside Logic Apps
-
Agent sets parameters
-
mcpToolName = "wf_arithmetic_add"
mcpToolPayload = "{\"number1\":25,\"number2\":10}"
-
-
Compose (ArgumentJson)
- Logic Apps runs:
@json(agentParameters('mcpToolPayload'))
-
Converts the string into a JSON object:
{ "number1": 25, "number2": 10 }
-
InvokeMCPTool (HTTP action)
- Sends the final
tools/call
payload to the MCP server.
- Sends the final
Headers
-
Mcp-Session-Id
→ from theinitialize
step (mcpSessionId
variable) -
Content-Type: application/json
-
Accept: application/json, text/event-stream
Body
{
"jsonrpc": "2.0",
"id": "@{guid()}",
"method": "tools/call",
"params": {
"name": "@{agentParameters('mcpToolName')}",
"arguments": "@outputs('ArgumentJson')"
}
}
📸 Tool Invocation in Designer
Here’s how it looks in the Logic Apps designer:
🧪 Testing the End-to-End Flow
Once deployed, you can test the Logic App by posting a JSON body with a math equation.
Example Request
POST https://<your-logicapp-endpoint>/triggers/RcvReq/invoke
Content-Type: application/json
{
"MathEquation": "10 + 50 * 25"
}
Here’s the run in Postman showing the request and successful response:
✅ Summary
By combining session initialization, tool discovery, and an Agent loop for tool invocation, Logic Apps can seamlessly orchestrate MCP servers.
-
initialize
→ start a session and capture theMcp-Session-Id
-
tools/list
→ fetch the catalog of available tools - Agent → selects the tool and prepares parameters (
mcpToolName
,mcpToolPayload
) -
tools/call
→ MCP server executes the tool and returns the output
Refer below for the tools call to solve the math problem of 10 ^ 5 * 19 + (3 * 3 + 2)
With this pattern, your Logic App can effectively think, plan across tools, and deliver only the final result back to the caller.
Top comments (0)