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
MathEquationstring. -
Establish a session: Call
initializeon 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
π MCPScope
π€ 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/callpayload, 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/callpayload to the MCP server.
- Sends the final
Headers
-
Mcp-Session-Idβ from theinitializestep (mcpSessionIdvariable) -
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.
For further actions, you may consider blocking this person and/or reporting abuse
