Microsoft Foundry โ MongoDB + Azure AI Samples
A collection of samples and reference architectures for building AI-powered applications with MongoDB Atlas and Microsoft Azure AI Foundry โ including retrieval-augmented generation (RAG), hosted agents, and Model Context Protocol (MCP) tool integrations.
๐ Quick Start
Deploy the full sample with a single script, or launch in GitHub Codespaces with zero local install.
๐ฌ simple-rag-movies
Foundry agent performing semantic search over MongoDB Atlas movie data via MCP tools.
๐ Security
No secrets in source control โ secure parameters, env vars, and protected config files.
What's Inside
| Sample | Description | Technologies |
|---|---|---|
| simple-rag-movies | Fully automated, single-script deployment of a Microsoft Foundry agent performing RAG over MongoDB Atlas movie data via MCP tools | Microsoft Foundry, Azure Native MongoDB Atlas, Atlas Vector Search, MongoDB MCP Server, Azure Functions (Flex Consumption), Bicep, PowerShell |
simple-rag-movies
Build a Microsoft Foundry agent that performs semantic search over MongoDB Atlas
sample movie data โ deployed end to end with one script (./scripts/setup-and-deploy.ps1).
What the agent can do
- Semantic Search โ find documents by meaning, not just keywords ("movies about hope and redemption")
- Direct Queries โ filter by specific fields (year, genre, cast)
- Aggregations โ statistics, top results, counts
What's included
- Foundry prompt agent (gpt-5-mini) wired to MCP tools:
- an embedding Function (Flex Consumption) that serves the
semantic_searchMCP endpoint and relays all other calls untouched - the MongoDB MCP Server on Azure Container Apps โ the only component holding the connection string, performing all database operations
- an embedding Function (Flex Consumption) that serves the
- Full automation โ one command sets up Atlas (cluster, sample data, vector index), provisions Azure (Foundry account, models, Function, Container App), and creates the agent
- GitHub Codespaces dev container for a zero-local-install deployment path
- Infrastructure as Code โ Bicep templates for the MCP Server and embedding Function
- Sample queries and agent instructions to test semantic search, direct filters, and aggregations
โ Full setup guide: simple-rag-movies/README.md
Architecture
The agent registers one MCP server โ the Azure Function โ which advertises
semantic_search plus every tool the MongoDB MCP server offers. Calls that are not
semantic_search are relayed to the MongoDB MCP server untouched, so the MCP server performs
all database operations and is the only component holding the connection string. The Function has
no MongoDB driver and no database credentials โ it only embeds the user query.
Prerequisites
- An Azure subscription with:
- Owner or Contributor โ to create the Atlas resource, resource group, Function, Container App, and Foundry account
- Azure AI User (Foundry User) assigned at subscription scope โ required for the Foundry data plane when the script creates the agent
- Azure CLI (run
az loginfirst) - MongoDB Atlas CLI
- PowerShell 7+ (cross-platform: Windows, macOS, Linux)
- An existing MongoDB Atlas Organization via Azure Native Integration
Quick Start
Option A โ GitHub Codespaces (fastest, zero local install)
The dev container preinstalls Azure CLI, PowerShell, Python, Bicep, and the MongoDB Atlas CLI. Then run one command:
./scripts/setup-and-deploy.ps1
Option B โ Local
git clone https://github.com/mongodb-partners/Microsoft_Foundry.git
cd Microsoft_Foundry/simple-rag-movies
./scripts/setup-and-deploy.ps1
You're prompted to sign in to Azure and MongoDB Atlas (browser device-code login); the script then sets up Atlas + Azure + the agent end to end.
Test the agent
Open mongodb-search-agent in the Foundry playground and try:
- "Find movies about hope and redemption" โ routes to the
semantic_searchMCP tool (vector search) - "Show me movies from 1994" โ routes to the MongoDB MCP tool (
find) - "What are the top 10 highest rated sci-fi movies?" โ routes to the MongoDB MCP tool (
aggregate)
Repository Structure
Microsoft_Foundry/
โโโ index.html # This documentation site (GitHub Pages)
โโโ README.md # Hub overview
โโโ MSFT Foundry_Architecture.png # Reference architecture diagram
โโโ simple-rag-movies/ # Sample: Foundry agent + Atlas Vector Search RAG
โโโ README.md # Sample setup guide
โโโ LICENSE # Sample license
โโโ sample-queries.md # Example queries to test the agent
โโโ deploy/ # Bicep templates + config.example.json
โโโ docs/ # Architecture doc and agent instructions
โโโ imgs/ # Sample architecture diagram
โโโ scripts/ # setup-and-deploy.ps1 + atlas/ and azure/ automation
โโโ src/embedding-function/ # Azure Function (Python) for embeddings
โโโ .devcontainer/ # GitHub Codespaces dev container
Configuration
Embedding Function
| Setting | Description | Default |
|---|---|---|
AZURE_OPENAI_ENDPOINT | Azure OpenAI resource endpoint | Required |
AZURE_OPENAI_API_KEY | Azure OpenAI API key | Required |
EMBEDDING_MODEL | Embedding model deployment name | text-embedding-ada-002 |
MCP Server
| Setting | Description | Default |
|---|---|---|
MDB_MCP_CONNECTION_STRING | MongoDB connection string | Required |
MDB_MCP_READ_ONLY | Restrict to read operations | true |
MDB_MCP_HTTP_PORT | HTTP port | 8080 |
Security
This repository follows security best practices:
- No secrets in source control โ
.gitignoreexcludes.envfiles,local.settings.json,config.json, certificates, and other credential files - Secrets are passed as parameters โ deployment templates use
@secure()parameters (Bicep), and deployment scripts prompt for credentials at runtime - Configuration via environment variables โ sample code reads credentials from environment variables, never hardcoded
- Template files (e.g.,
config.example.json) contain only placeholders โ copy them and fill in your own values locally