Edit

Share via


Connect an MCP server on Azure Functions to a Foundry Agent Service agent

This article shows you how to connect your Model Context Protocol (MCP) server hosted on Azure Functions to Microsoft Foundry Agent Service. After completing this guide, your agent can discover and invoke the tools exposed by your MCP server.

This article follows this basic process for configuring the MCP server connection from Foundry Agent Service:

  • Create and deploy an MCP server to your function app in Azure.
  • Get the MCP server endpoint URL.
  • Get the authentication credentials (as required).
  • Disable key-based authentication (when not needed).
  • Add an MCP server tool connection to an existing agent.

Prerequisites

Before you begin, make sure you have these resources in place:

Review connection options

This table summarizes the currently supported options for authenticating your agent connection to an MCP server in Foundry Agent Service:

Method Description Use case Additional setup Functions supports
Key-based (default) Agent authenticates by passing a shared function access key in the request header. This method is the default authentication for HTTP endpoints in Functions. Use during development or when the MCP server doesn't require Microsoft Entra authentication. None Yes
Microsoft Entra Agent authenticates using either its own identity (agent identity) or the shared identity of the Foundry project (project managed identity). Use agent identity for production scenarios, but limit shared identity to development. Disable key-based authentication and configure built-in server authorization and authentication. Project managed (shared) identity
OAuth identity passthrough Agent prompts users to sign in and authorize access, using the provided token to authenticate. Use in production when each user must authenticate with their own identity and user context must be persisted. Disable key-based authentication and configure built-in server authorization and authentication. Yes
Unauthenticated access Agent makes unauthenticated calls. Use during development or when your MCP server accesses only public information. Disable key-based authentication. Yes

To learn more about the MCP server authentication options that the Foundry Agent Service supports, see Set up authentication for MCP tools.

Get the remote MCP server endpoint

Before you can connect the agent to a Functions-hosed MCP server, you must get the endpoint URL for the service. The specific URL format depends on how you created and deployed your MCP server:

MCP server type Endpoint format
MCP extension-based server https://<FUNCTION_APP_NAME>.azurewebsites.net/runtime/webhooks/mcp
Self-hosted MCP server https://<FUNCTION_APP_NAME>.azurewebsites.net/mcp (unless you changed the route)

For more information, see Remote MCP servers.

Get credentials

The credentials that your agent needs to connect to the MCP server depend on the way you plan to secure the connection. Choose the tab that indicates your connection authentication option.

When you use an access key to connect to your MCP server endpoint, you use a shared secret key to make it more difficult for random agents to connect to your server.

Important

While access keys can help prevent unwanted endpoint access by default, consider using Microsoft Entra ID or OAuth identity authentication to provide enhanced security to your MCP server endpoints in production.

The name of the access key you need depends on your MCP server deployment:

MCP server type Key name Key type
MCP extension-based server mcp_extension System key
Self-hosted MCP server default Host key

To get the key from the Azure portal:

  1. Go to your function app resource in the Azure portal.
  2. Expand the Functions dropdown in the left menu.
  3. Select App keys.
  4. Copy either the mcp_extension key (under System keys) or the default key (under Host keys), depending on your MCP server type.

For more information, see Work with access keys in Azure Functions.

Disable key-based authentication

When you choose to use a different authentication method than the default key-based authentication, you don't need Functions to enforce key-based access to your MCP endpoints. You can disable key-based access requirement by changing the access setting from system (key-based) to anonymous (unauthenticated). How you make this change depends on the type of MCP server you're hosting:

When you use the default key-based authentication, no changes are required.

Add your MCP server

The process for creating the agent connection to the MCP server depends on your specific endpoint authentication options.

When you use key-based authentication, the agent authenticates by passing a function access key in the request header to your MCP server.

To connect to your MCP server endpoint:

  1. Go to the Foundry portal (new Foundry).

  2. Select the Build tab at the top of the page and select an agent to connect to your MCP server.

  3. In the Playground tab, expand the Tools dropdown and select Add.

  4. In the Custom tab in Select a tool, select Model Context Protocol (MCP) > Create.

  5. In Add Model Content Protocol tool, provide information from this table to configure an access key-based connection:

    Field Description Example
    Name A unique identifier for your MCP server. Use your function app name as the default. contoso-mcp-tools
    Remote MCP Server endpoint The URL endpoint for your MCP server. https://contoso-mcp-tools.azurewebsites.net/runtime/webhooks/mcp
    Authentication The authentication method to use. Key-based
    Credential The key-value pair to authenticate with your function app. x-functions-key: aaaaaaaa-0b0b-1c1c-2d2d-333333333333
  6. Select Connect to create a connection to your MCP server endpoint. You see your server name listed under Tools.

  7. Select Save to save the MCP tool configuration in your agent.

Test your MCP tools

After connecting your MCP server to your agent, verify that the tools work correctly.

  1. In the Agent Builder, find the chat window under Playground.
  2. Enter a prompt that triggers one of your MCP tools. For example, if your MCP server has a greeting tool, try: Use the greeting tool to say hello.
  3. If you're using OAuth identity passthrough, select Open Consent and sign in with your Entra account.
  4. When the agent requests to invoke an MCP tool, review the tool name and arguments, and select Approve to allow the call.
  5. Verify the tool returns the expected result.

Your agent can now use the tools exposed by your MCP server hosted on Azure Functions.

These additional articles can help you build your agent and function app capabilities: