Forum Discussion
Unable to Connect Localhost MCP Server from Azure AI Foundry Hosted Agent (o4-mini)
I'm using the Azure AI Foundry Toolkit in VS Code and have configured an MCP server running on my local machine (localhost).
When I run my Azure AI Foundry-hosted agent (o4-mini), it fails to connect to the MCP server. Based on the error logs, it appears that the hosted agent cannot reach the localhost endpoint.
My understanding is that the MCP server is running correctly locally, but the hosted agent seems unable to access services running on my machine.
Has anyone successfully connected a locally hosted MCP server to an Azure AI Foundry-hosted agent while using the Foundry Toolkit in VS Code?
1 Reply
A hosted Foundry agent will not be able to reach localhost on your machine. From the agent runtime, localhost means the hosted environment, not your laptop. Put the MCP server behind an HTTPS endpoint the agent can reach, such as Container Apps, App Service, Functions, or a short-lived secure tunnel for testing. For anything beyond a test, add auth instead of exposing the dev server directly.