Edit

Share via


Build and register a Model Context Protocol (MCP) server

Model Context Protocol (MCP) provides a standard interface for AI agents to interact with APIs and external services. When you need to integrate private or internal enterprise systems that don't have existing MCP server implementations, you can build your own custom server. This article shows you how to create a remote MCP server using Azure Functions, register it in a private organizational tool catalog using Azure API Center, and connect it to Foundry Agent Service.

This approach enables you to securely integrate internal APIs and services into the Microsoft Foundry ecosystem, allowing agents to call your enterprise-specific tools through a standardized MCP interface.

Prerequisites

Build an MCP server by using Azure Functions

Azure Functions is a serverless compute service that provides scale-to-zero capability, burst scaling, and enterprise features including identity-based access and virtual networking. The lightweight programming model makes it straightforward to build MCP servers so you can focus on implementing your business logic rather than infrastructure management.

  1. Open a terminal or command prompt and navigate to the folder where you want to create your project.

  2. Run the azd init command to initialize the project from this sample MCP server template:

    azd init --template remote-mcp-functions-python -e mcpserver-python
    
  3. Review the sample code structure. The template includes:

    • Function definitions for MCP endpoints.
    • Configuration for authentication and authorization.
    • Deployment scripts for Azure.
  4. Customize the MCP server functions to expose your specific APIs and services. Modify the function code to implement the tools and capabilities your agents need.

  5. Test your MCP server locally by using the Azure Functions Core Tools:

    func start
    
  6. Deploy your MCP server to Azure by using the Azure Developer CLI:

    azd up
    

    Follow the prompts to select your Azure subscription and resource group.

  7. After deployment completes, save the following information for later steps:

    Item Example or value
    Remote MCP server endpoint https://{function_app_name}.azurewebsites.net/runtime/webhooks/mcp
    Authentication information For access key authentication, note the mcp_extension system key from the Azure portal

For detailed implementation guidance, see Quickstart: Build a custom remote MCP server using Azure Functions.

Register your MCP server in the organizational tool catalog

When you register your MCP server in Azure API Center, you create a private organizational tool catalog. This step is optional but recommended for sharing MCP servers across your organization with consistent governance and discoverability.

To register your MCP server:

  1. Sign in to the Azure portal and go to your Azure API Center resource.

    Tip

    The API Center name becomes your private tool catalog name in the registry filter. Choose an informative name that helps users identify your organization's tool catalog.

  2. Register your remote MCP server by adding it as an API:

    a. In the left navigation pane, select APIs.

    b. Select + Add API and provide the required information about your MCP server.

    c. Configure environments and deployments following the tutorial: Add environments and deployments for APIs in Azure API Center.

  3. Configure authentication for your MCP server (optional):

    a. In the left navigation pane of your API Center resource, select Governance > Authorization.

    Screenshot showing the Azure API Center authorization configuration page with Governance menu expanded.

    b. Select Add configuration.

    c. Choose the security scheme that matches your MCP server requirements:

    • API Key: Developers provide the API key during tool configuration in Foundry
    • OAuth: Configure OAuth 2.0 authentication parameters
    • HTTP: Configure bearer token authorization

    d. Provide the required authentication details for your selected scheme.

    Note

    If you choose API Key authentication, the key you store in Azure Key Vault isn't automatically used in Foundry. Developers must provide the API key when configuring the MCP server connection.

  4. Configure access management (optional):

    a. Go to your registered MCP server in API Center.

    b. Select Details > Versions > Manage Access (preview).

    c. Configure which users or groups can access this MCP server through the organizational catalog.

After registration, your MCP server appears in the Foundry tool catalog with the governance and authentication settings you configured.

Connect the MCP server to Agent Service

You can connect your MCP server to Agent Service through the organizational tool catalog (if you registered it) or as a custom MCP tool.

Connect using the organizational tool catalog

If you registered your MCP server in Azure API Center, users with appropriate access can discover and configure it:

  1. In Foundry portal, go to your project.

  2. Go to Build > Tools or open Agent Builder.

  3. Browse the organizational tool catalog to find your registered MCP server.

  4. Follow the configuration guidance displayed in the tool catalog to add the server to your agent.

Connect using a custom MCP tool

If you don't register your MCP server in the organizational catalog, add it directly as a custom tool:

  1. In Foundry portal, go to your project.

  2. Go to Build > Tools or open Agent Builder.

  3. Select Add tool > Custom > Model Context Protocol.

  4. Enter your MCP server details:

    • Name: Unique name for your remote MCP server
    • Remote MCP Server endpoint: Enter your remote MCP server endpoint URL (for example, https://{function_app_name}.azurewebsites.net/runtime/webhooks/mcp)
    • Authentication: Select the authentication method. For Key-based authentication, provide the following credential:
      • Credential: "x-functions-key": "{mcp_extension_system_key}"
  5. Select Connect to register the custom MCP tool.

For detailed configuration steps, see Connect to a Model Context Protocol server endpoint in Agent Service.

After connecting your MCP server, agents in your Foundry project can call the tools and functions exposed by your custom server. Test the connection by creating an agent and verifying it can successfully invoke your MCP server's capabilities.

Troubleshooting

Here are some common issues you might encounter when building and connecting your MCP server:

  • MCP server connection fails: Ensure that your Azure Function is running and accessible. Check the function logs in the Azure portal for any errors.
  • Authentication errors: Verify that you're using the correct system key or API key. If using API Key authentication, ensure the key is correctly configured in the Foundry connection settings.
  • Tool not found: If you registered your MCP server in the organizational catalog, make sure you've added it to your agent. If using a custom tool, verify the endpoint URL and tool name.