|
| 1 | +--- |
| 2 | +title: Connect Microsoft Foundry Agents to MongoDB Atlas |
| 3 | +description: Learn how to connect Microsoft Foundry Agents to MongoDB Atlas using the MongoDB MCP Server for data retrieval and vector search. |
| 4 | +ms.topic: how-to |
| 5 | +ms.date: 03/20/2026 |
| 6 | +--- |
| 7 | + |
| 8 | +# Connect Microsoft Foundry agents to MongoDB Atlas |
| 9 | + |
| 10 | +This article shows you how to connect Microsoft Foundry agents that can query and retrieve data from MongoDB Atlas using the MongoDB MCP Server. |
| 11 | + |
| 12 | +## Architecture overview |
| 13 | + |
| 14 | +At a high level, the integration includes these components: |
| 15 | + |
| 16 | +- **Microsoft Foundry Agent** – Orchestrates reasoning and tool usage. |
| 17 | +- **MongoDB MCP Server** – Exposes MongoDB Atlas operations (vector search, aggregation) as agent tools. |
| 18 | +- **MongoDB Atlas** – Stores operational and vectorized data. |
| 19 | +- **Azure hosting** – Hosts the MCP Server in Azure Container Apps. |
| 20 | + |
| 21 | +The Foundry agent calls the MCP Server over HTTPS at query time, and the MCP Server executes operations against your Atlas cluster. Your data remains in MongoDB Atlas. |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +Before you begin, ensure you have: |
| 26 | + |
| 27 | +- An Azure subscription with access to a Microsoft Foundry project. |
| 28 | +- A MongoDB Atlas account with a project and cluster. |
| 29 | +- A vector search index created in MongoDB Atlas (for RAG scenarios). |
| 30 | +- Permission to deploy services to Azure (for MCP Server hosting). |
| 31 | + |
| 32 | +## Prepare MongoDB Atlas |
| 33 | + |
| 34 | +1. Create or select a MongoDB Atlas cluster. |
| 35 | +1. Load your dataset (for example, sample Airbnb or domain-specific data). |
| 36 | +1. Create a vector search index on the target collection. |
| 37 | + |
| 38 | +## Deploy the MongoDB MCP Server |
| 39 | + |
| 40 | +The [MongoDB MCP Server](https://github.com/mongodb-js/mongodb-mcp-server) acts as a bridge between Foundry agents and MongoDB Atlas. |
| 41 | + |
| 42 | +1. Deploy the MCP Server to Azure Container Apps or another Azure-hosted environment. For details on hosting, see the [MongoDB MCP Server Azure deployment guide](https://github.com/mongodb-js/mongodb-mcp-server/blob/main/deploy/azure/README.md). |
| 43 | +1. Configure the server with: |
| 44 | + - MongoDB Atlas connection details |
| 45 | + - Enabled tools (vector search, aggregation) |
| 46 | +1. Expose a remote HTTPS endpoint. |
| 47 | + |
| 48 | +## Create an agent in Microsoft Foundry |
| 49 | + |
| 50 | +1. Open the Microsoft Foundry portal. |
| 51 | +1. Create a new agent, provide system instructions, and choose a deployed Foundry model. |
| 52 | +1. Go to **Tools** > **MongoDB MCP Server** > **Connect**. |
| 53 | +1. Paste the MCP Server remote URL. |
| 54 | +1. Save the agent configuration. |
| 55 | + |
| 56 | +After you add the MCP Server, the agent can invoke MongoDB operations through the MCP tool during reasoning. |
| 57 | + |
| 58 | +## Deploy the embedding endpoint |
| 59 | + |
| 60 | +In retrieval-augmented generation (RAG) scenarios, Foundry agents need to generate embeddings for user queries at runtime before invoking MongoDB Atlas Vector Search. You expose an embedding generation function as an OpenAPI-based tool that the agent calls during reasoning. |
| 61 | + |
| 62 | +Define the embedding function with the following OpenAPI specification: |
| 63 | + |
| 64 | +```yaml |
| 65 | +openapi: 3.0.1 |
| 66 | +info: |
| 67 | + title: Embedding Service API |
| 68 | + version: "1.0" |
| 69 | +paths: |
| 70 | + /embeddings: |
| 71 | + post: |
| 72 | + summary: Generate embeddings for input text |
| 73 | + operationId: generateEmbeddings |
| 74 | + requestBody: |
| 75 | + required: true |
| 76 | + content: |
| 77 | + application/json: |
| 78 | + schema: |
| 79 | + type: object |
| 80 | + properties: |
| 81 | + input: |
| 82 | + type: string |
| 83 | + description: Text to embed |
| 84 | + responses: |
| 85 | + '200': |
| 86 | + description: Embedding vector |
| 87 | + content: |
| 88 | + application/json: |
| 89 | + schema: |
| 90 | + type: object |
| 91 | + properties: |
| 92 | + embedding: |
| 93 | + type: array |
| 94 | + items: |
| 95 | + type: number |
| 96 | +``` |
| 97 | +
|
| 98 | +The implementation behind this API typically calls a Foundry-hosted embedding model (for example, `text-embedding-3-large`) and returns the vector as JSON. |
| 99 | + |
| 100 | +## Configure the agent for vector search |
| 101 | + |
| 102 | +1. In the agent tools, add a new OpenAPI tool. |
| 103 | +1. Paste the OpenAPI specification from the [Deploy the embedding endpoint](#deploy-the-embedding-endpoint) step. |
| 104 | +1. In the agent instructions, guide the agent to invoke this function for vector search use cases. |
| 105 | +1. Save the agent. |
| 106 | + |
| 107 | +Once registered, the agent can invoke `generateEmbeddings` as part of its reasoning chain. |
| 108 | + |
| 109 | +## Test retrieval and responses |
| 110 | + |
| 111 | +Run prompts that require: |
| 112 | + |
| 113 | +- Semantic search over MongoDB data |
| 114 | +- Aggregation queries |
| 115 | +- Context-aware responses grounded in Atlas data |
| 116 | + |
| 117 | +Successful responses confirm end-to-end connectivity between Foundry, the MCP Server, and MongoDB Atlas. |
| 118 | + |
| 119 | +## Next steps |
| 120 | + |
| 121 | +- [MongoDB MCP Server](https://github.com/mongodb-js/mongodb-mcp-server) |
| 122 | +- [What is MongoDB Atlas?](overview.md) |
| 123 | +- [Manage MongoDB Atlas](manage.md) |
0 commit comments