Model Context Protocol bindings for Azure Functions overview

The Model Context Protocol (MCP) is a client-server protocol intended to enable language models and agents to more efficiently discover and use external data sources and tools.

Important

The Azure Functions MCP extension is currently in preview. You can expect changes to the trigger and binding APIs until the extension becomes generally available.
You should avoid using preview extensions in production apps.

The Azure Functions MCP extension allows you to use Azure Functions to create remote MCP servers. These servers can host MCP tool trigger functions, which MCP clients, such as language models and agents, can query and access to do specific tasks.

Action Type
Run a function from an MCP tool call request Trigger

Important

The MCP extension doesn't currently support PowerShell apps.

Prerequisites

  • Requires version 2.0.2 or later of the Microsoft.Azure.Functions.Worker.Sdk package.

Install extension

Note

For C#, the Azure Functions MCP extension supports only the isolated worker model.

Add the extension to your project by installing this NuGet package in your preferred way:

Microsoft.Azure.Functions.Worker.Extensions.Mcp

Install bundle

To be able to use this preview binding extension in your app, you must reference a preview extension bundle that includes it.

Add or replace the following code in your host.json file, which specifically targets the latest preview version of the 4.x bundle:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
    "version": "[4.0.0, 5.0.0)"
  }
}

Select the previous link to verify that the latest preview bundle version does contain the preview extension.

host.json settings

This section describes the configuration settings available for this binding in versions 2.x and higher. Settings in the host.json file apply to all functions in a function app instance. The example host.json file below contains only the version 2.x+ settings for this binding. For more information about function app configuration settings in versions 2.x and later versions, see host.json reference for Azure Functions.

Note

Until the extension is no longer in preview, the JSON schema for host.json isn't updated, and specific properties and behaviors might change. During the preview period, you might see warnings in your editor that say the mcp section isn't recognized. You can safely ignore these warnings.

You can use host.json to define MCP server information.

{
  "version": "2.0",
  "extensions": {
    "mcp": {
      "instructions": "Some test instructions on how to use the server",
      "serverName": "TestServer",
      "serverVersion": "2.0.0",
      "messageOptions": {
        "useAbsoluteUriForEndpoint": false
      }
    }    
  }
}
Property Description
instructions Describes to clients how to access the remote MCP server.
serverName A friendly name for the remote MCP server.
serverVersion Current version of the remote MCP server.
messageOptions Options object for the message endpoint in the SSE transport.
messageOptions.UseAbsoluteUriForEndpoint Defaults to false. Only applicable to the server-sent events (SSE) transport; this setting doesn't affect the Streamable HTTP transport. If set to false, the message endpoint is provided as a relative URI during initial connections over the SSE transport. If set to true, the message endpoint is returned as an absolute URI. Using a relative URI isn't recommended unless you have a specific reason to do so.

Connect to your MCP server

To connect to the MCP server exposed by your function app, you need to provide an MCP client with the appropriate endpoint and transport information. The following table shows the transports supported by the Azure Functions MCP extension, along with their corresponding connection endpoint.

Transport Endpoint
Streamable HTTP /runtime/webhooks/mcp
Server-Sent Events (SSE)1 /runtime/webhooks/mcp/sse

1 Newer protocol versions have deprecated the Server-Sent Events transport. Unless your client specifically requires it, you should use the Streamable HTTP transport instead.

When hosted in Azure, the endpoints exposed by the extension also require the system key named mcp_extension. If it isn't provided in the x-functions-key HTTP header, your client receives a 401 Unauthorized response. You can retrieve the key using any of the methods described in Get your function access keys. The following example shows how to get the key with the Azure CLI:

az functionapp keys list --resource-group <RESOURCE_GROUP> --name <APP_NAME> --query systemKeys.mcp_extension --output tsv

MCP clients accept this configuration in various ways. Consult the documentation for your chosen client. The following example shows an mcp.json file like you might use to configure MCP servers for GitHub Copilot in Visual Studio Code. The example sets up two servers, both using the Streamable HTTP transport. The first is for local testing with the Azure Functions Core Tools. The second is for a function app hosted in Azure. The configuration takes input parameters for which VS Code prompts you when you first run the remote server. Using inputs ensures that secrets like the system key aren't saved to the file and checked into source control.

{
    "inputs": [
        {
            "type": "promptString",
            "id": "functions-mcp-extension-system-key",
            "description": "Azure Functions MCP Extension System Key",
            "password": true
        },
        {
            "type": "promptString",
            "id": "functionapp-host",
            "description": "The host domain of the function app."
        }
    ],
    "servers": {
        "local-mcp-function": {
            "type": "http",
            "url": "http://localhost:7071/runtime/webhooks/mcp"
        },
        "remote-mcp-function": {
            "type": "http",
            "url": "https://${input:functionapp-host}/runtime/webhooks/mcp",
            "headers": {
                "x-functions-key": "${input:functions-mcp-extension-system-key}"
            }
        }
    }
}

Create a tool endpoint in your remote MCP server