DEV Community

Daniel Jonathan
Daniel Jonathan

Posted on

Azure Function as MCP Server

Azure Function as MCP Server (Arithmetic Tools)

When building AI integrations with Azure Functions, you can expose your function app as an MCP (Model Context Protocol) server.

This allows AI agents or orchestration engines (like Logic Apps, Semantic Kernel, or LangChain) to discover and invoke your server’s tools directly.

The key attributes are:

  • McpToolTrigger(name, description) → marks a function as an MCP tool and gives it a discoverable name and human-friendly description.
  • McpToolProperty(name, type, description) → declares typed inputs that become part of the tool’s schema for clients.

This makes your Functions app self-describing: clients can enumerate tools and call them via tools/call with strongly-typed arguments.

This makes your Azure Function automatically discoverable as a tool that can be called by an MCP-aware agent.


1. Add MCP extension package

dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Mcp
Enter fullscreen mode Exit fullscreen mode

2. Update host.json

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
    "version": "[4.*, 5.0.0)"
  },
  "extensions": {
    "mcp": {
      "instructions": "This server exposes arithmetic operations. Use the `add` tool with operand1 and operand2.",
      "serverName": "AzFuncMCP.ArithmeticOperators",
      "serverVersion": "2.0.0"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

3. Create MCP Trigger Function

What the MCP attributes do

  • [McpToolTrigger("add", "...")]

    • Declares this method as an MCP tool named add.
    • The description is shown to clients during tool discovery.
    • Enables agents to call the tool via tools/call with arguments defined below.
  • [McpToolProperty("operand1", "number", "The first number to add")]

    • Declares a tool parameter named operand1 of type number.
    • The binding converts the incoming argument to the .NET parameter type (double operand1).
  • [McpToolProperty("operand2", "number", "The second number to add")]

    • Declares another tool parameter named operand2 of type number.
    • Bound to the .NET parameter (double operand2).

Binding & validation notes

  • Name matching: Attribute name (e.g., operand1) must match the function parameter name for binding to succeed.
  • Type mapping: MCP types (number, string, boolean, etc.) are converted to your .NET types (double, string, bool, ...).
  • Schema exposure: These attributes are used to generate the tool schema surfaced during discovery.
  • Errors: If a client omits/mis-types a value, binding fails; catch and format errors as shown.

Image description4


4. Test & Validate (tools/call)

Important: Program.cs setup

When you configure your isolated worker in Program.cs, make sure to enable MCP metadata:

var builder = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults(worker =>
    {
        worker.EnableMcpToolMetadata();
    })
    .Build();

builder.Run();
Enter fullscreen mode Exit fullscreen mode

Run the Azure Function locally

From your project folder, start the Functions host:

func start
Enter fullscreen mode Exit fullscreen mode

Image description1

System key requirement

  • When your MCP server is hosted in Azure, the extension endpoints require the mcp_extension system key.
  • If it isn’t provided in the x-functions-key HTTP header, the client request will be rejected with 401 Unauthorized.
  • You can retrieve this key using the standard methods described in Get your function access keys.

Test via Postman

  • In Postman, click New → select MCP.
  • Enter your MCP server URL:
  http://localhost:<port>/runtime/webhooks/mcp
Enter fullscreen mode Exit fullscreen mode
  • Hit Connect.

Discover available tools

Once connected, navigate to the Tools tab in Postman.

Here you’ll see all the available MCP tools exposed by your Function App (for example, add and power).

Select add and provide the inputs:

  • operand1: 1
  • operand2: 2

Click Run. The MCP server responds with the result:

Image description2

5. Going further — more arithmetic tools & (oh no) BODMAS again!

By now, you’ve seen how to expose an add tool with MCP.

But why stop there? Let’s invite the whole math gang:

Create additional tools (e.g., multiply, divide, power,squareroot,subtract) using the same pattern:

[McpToolTrigger("multiply", "Multiplies two numbers")] ...
[McpToolTrigger("squareroot", "Calculates the square root of a number")] ...
[McpToolTrigger("subtract", "Subtracts the second number from the first")] ...
[McpToolTrigger("divide", "Divides two numbers")] ...
[McpToolTrigger("power", "Raises a to the power b")] ...
Enter fullscreen mode Exit fullscreen mode

What is BODMAS?

BODMAS is a rule that defines the correct order of operations in mathematics:

  • B = Brackets
  • O = Orders (powers, exponents, roots)
  • D = Division
  • M = Multiplication
  • A = Addition
  • S = Subtraction

It ensures expressions are solved consistently.

For example:

5 + 2 * 3 = 11 (not 21), because multiplication is done before addition.


An agent can then chain these tools to solve expressions using BODMAS/PEMDAS rules.

Example agent session solving a BODMAS expression
Image description3
Step 1 (Powers):

power(5,2)=25, power(5,3)=12525 * 3 + 5 / 2 + 125

Step 2 (× ÷):

25*3=75, 5/2=2.575 + 2.5 + 125

Step 3 (+):

75+2.5=77.5, 77.5+125=202.5

Final Answer: 202.5


✅ Summary

  • Reference the MCP extension
  • Configure the server in host.json
  • Expose tools with McpToolTrigger + McpToolProperty
  • Test with tools/call (via Postman or another client)
  • Extend with more arithmetic tools to solve full BODMAS equations 👉 Curious about running this in Logic Apps instead of Functions? Read my earlier article: Logic Apps MCP: Expose Arithmetic Tools

Top comments (0)