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