VOOZH about

URL: https://dev.to/imdj/consume-an-mcp-endpoint-from-azure-logic-apps-with-an-agent-loop-52jh

⇱ 🧩Consume an MCP Endpoint from Azure Logic Apps β€” with an Agent Loop - DEV Community


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):

  1. Trigger: HTTP request with a MathEquation string.
  2. Establish a session: Call initialize on the MCP server endpoint β†’ capture Mcp-Session-Id.
    • 2.1 MCP Server URL: https://<your-mcp-server-url>/api/mcp (MCPArithmetic Server, authentication set as anonymous)
  3. Discover tools: Call tools/list β†’ store the available tool catalog.
  4. Agent loop: Logic Apps Agent picks the right tool and calls it via a custom InvokeMCPTools tool (HTTP action under the hood).
  5. 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')})
  • 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

  1. Agent sets parameters

    • mcpToolName = "wf_arithmetic_add"
    • mcpToolPayload = "{\"number1\":25,\"number2\":10}"
  2. Compose (ArgumentJson)

    • Logic Apps runs:
     @json(agentParameters('mcpToolPayload'))
    
  • Converts the string into a JSON object:

    {"number1":25,"number2":10}
  1. InvokeMCPTool (HTTP action)
    • Sends the final tools/call payload to the MCP server.

Headers

  • Mcp-Session-Id β†’ from the initialize 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:

πŸ‘ LAWorkflow


πŸ§ͺ 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:

πŸ‘ Postman execution


βœ… 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 the Mcp-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)

πŸ‘ RunHistory

With this pattern, your Logic App can effectively think, plan across tools, and deliver only the final result back to the caller.