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
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"
}
}
}
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.
- Declares this method as an MCP tool named
-
[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
).
- Declares a tool parameter named
-
[McpToolProperty("operand2", "number", "The second number to add")]
- Declares another tool parameter named
operand2
of type number. - Bound to the .NET parameter (
double operand2
).
- Declares another tool parameter named
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.
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();
Run the Azure Function locally
From your project folder, start the Functions host:
func start
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 with401 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
- 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:
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")] ...
What is BODMAS?
BODMAS is a rule that defines the correct order of operations in mathematics:
|
![]() |
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
Step 1 (Powers):
power(5,2)=25
, power(5,3)=125
→ 25 * 3 + 5 / 2 + 125
Step 2 (× ÷):
25*3=75
, 5/2=2.5
→ 75 + 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)