https://github.com/azure-samples/snippy
đź§© Demo: Build AI-powered MCP Tools for GitHub Copilot using Azure Functions, OpenAI, AI Agents & Cosmos DB. Manages code snippets w/ vector search.
https://github.com/azure-samples/snippy
ai-agents azure-functions copilot cosmosdb mcp mcp-server
Last synced: 5 months ago
JSON representation
đź§© Demo: Build AI-powered MCP Tools for GitHub Copilot using Azure Functions, OpenAI, AI Agents & Cosmos DB. Manages code snippets w/ vector search.
- Host: GitHub
- URL: https://github.com/azure-samples/snippy
- Owner: Azure-Samples
- License: mit
- Created: 2025-04-24T18:25:10.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-05-10T04:09:50.000Z (5 months ago)
- Last Synced: 2025-05-10T04:29:10.511Z (5 months ago)
- Topics: ai-agents, azure-functions, copilot, cosmosdb, mcp, mcp-server
- Language: Python
- Homepage:
- Size: 2.21 MB
- Stars: 11
- Watchers: 11
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Snippy · Intelligent Code-Snippet Service with MCP Tools[](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=Azure-Samples/snippy&machine=basicLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json)
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/snippy)Snippy is an **Azure Functions**–based reference application that turns any function into an **MCP (Model Context Protocol) tool** consumable by GitHub Copilot Chat and other MCP‑aware clients. The sample implements a production‑style *code‑snippet service* with AI‑powered analysis:
* **Save snippets** – persists code, metadata and OpenAI embeddings in **Cosmos DB DiskANN**
* **Semantic retrieve** – vector search over embeddings
* **AI Agents** – generate a **deep wiki** or language‑specific **code style guide** from stored snippets
* **Durable fan‑out/fan‑in with Blueprints** – [in experimental branch](https://github.com/Azure-Samples/snippy/tree/gk/durable-functions) for large‑scale processing
* **Microsoft Fabric integration** – [in gk/fabric branch](https://github.com/Azure-Samples/snippy/tree/gk/fabric) demonstrating how to build Agents with Fabric Data AgentsThe project ships with reproducible **azd** infrastructure, so `azd up` will stand up the entire stack – Functions, Cosmos DB, Azure OpenAI and Azure AI Agents – in a single command.
> **Important Security Notice**
> This repository is intended for learning and demonstration purposes. **Do not** deploy it to production without a thorough security review. At a minimum you should:
>
> * Swap connection strings for **Managed Identity** + **Azure Key Vault**
> * Restrict network access to Azure services via Private Endpoints or service‑tags
> * Enable GitHub secret‑scanning and CI security tools[Features](#features) • [Architecture](#architecture-diagram) • [Getting Started](#getting-started) • [Guidance](#guidance)
---
## Features
* **Remote MCP trigger** – expose Functions as real‑time SSE tools
* **AI‑assisted documentation** – "deep‑wiki" and "code‑style" agents create rich Markdown (Mermaid, diagrams, etc.)
* **Vector search on Cosmos DB DiskANN** – low‑latency semantic retrieval
* **One‑click deploy** – `azd up` provisions and deploys code & infra
* **Codespaces & Dev Containers** – fully configured dev environment in your browser or local VS Code### Tool Matrix
| Tool Name | Purpose |
| -------------- | ------------------------------------------------------------------- |
| `save_snippet` | Save code snippets with vector embeddings for semantic search |
| `get_snippet` | Retrieve previously saved code snippets by their unique name |
| `code_style` | Generate language-specific code style guides from saved snippets |
| `deep_wiki` | Create comprehensive wiki documentation by analyzing code snippets |---
### Architecture Diagram

```mermaid
flowchart LR
%% ─── MCP Hosts & Clients (local) ──────────────────────────────
subgraph mcphosts["MCP Hosts & Clients (Your Computer)"]
Host["Host
(VS Code / IDE)"]
Client["Client
(GitHub Copilot)"]
end%% ─── Application on Azure (remote) ────────────────────────────
subgraph app["Application (Azure)"]
Snippy["MCPÂ Server
Snippy Triggers
(Function App)"]:::dashed
Foundry["Foundry Agent
Deep Wiki · Code Style"]
Cosmos["Cosmos DB
Operational + Vector DB"]:::datasource
AOAI["Azure OpenAI
text‑embedding‑3‑small"]
FabricDA["Fabric – Data Agent"]
VectorTool["Tools – Vector Search"]
end%% ─── Local interactions ───────────────────────────────────────
Host <--> Client%% ─── MCP protocol to Azure ────────────────────────────────────
Client <-- "MCP Protocol (SSE)" --> Snippy%% ─── Bindings & data flow inside Azure ────────────────────────
Snippy -- Bindings --> AOAI
Snippy --> Cosmos
Snippy --> Foundry
Foundry --> FabricDA
Foundry --> VectorTool%% ─── Styling ──────────────────────────────────────────────────
classDef datasource stroke-width:2,stroke-dasharray:5 5
classDef dashed stroke-width:2,stroke-dasharray:5 5,fill:transparent
class Cosmos datasource
class Snippy dashed
style mcphosts fill:transparent
style app fill:transparent
```---
## Getting Started
You can run Snippy in **GitHub Codespaces**, **VS Code Dev Containers**, or your **local environment**. The fastest path is Codespaces.
> Snippy requires an Azure region that supports *text‑embedding‑3‑small* (or a compatible embeddings model) **and** Azure AI Agents. The `azd` workflow prompts you for a region; we recommend **eastus** for best availability.
### GitHub Codespaces
1. Click **Open in Codespaces** above (first badge) – the container build may take a few minutes.
2. When the terminal appears, sign in:```bash
azd auth login --use-device-code
```
3. Launch the stack:```bash
azd up
```
4. Once deployment completes, copy the printed MCP URL and open GitHub Copilot Chat → *Agent* mode to try commands like “Save this snippet as **hello‑world**”.### VS Code Dev Containers
Prerequisites: [Docker Desktop](https://www.docker.com/products/docker-desktop) + the [Dev Containers](https://aka.ms/vscode/dev-containers) extension.
1. Click the **Dev Containers** badge (second badge) or run *Remote‑Containers: Open Repository in Container* from VS Code.
2. Sign in and launch as shown for Codespaces:```bash
azd auth login
azd up
```### Local Environment
#### Prerequisites
* [azd](https://aka.ms/install-azd)Â CLI
* Python 3.11 + [`uv`](https://github.com/astral-sh/uv)
* Node 18+ (for Functions Core Tools)
* Azure Functions Core Tools v4 (`npm i -g azure-functions-core-tools@4 --unsafe-perm`)#### Quickstart
```bash
# 1. Clone & init
azd init --template Azure-Samples/snippy# 2. Sign in
azd auth login# 3. Provision & deploy
azd up
```The CLI prints the Function App URL, MCP endpoint and system key when finished. To remove all resources later:
```bash
azd down --purge
```---
## Guidance
### Region Availability
Azure OpenAI model support varies by region. Verify availability [here](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#standard-deployment-model-availability) and choose the same region for all Azure resources. **eastus** and **swedencentral** are good default choices.
### Costs
Estimate monthly cost using the [Azure Pricing Calculator](https://azure.microsoft.com/pricing/calculator/). Major components:
* Azure Functions – Consumption / Flex tiers
* Cosmos DB – Serverless or provisioned throughput
* Azure OpenAI – pay‑as‑you‑go per 1K tokens
* Azure AI Agents – per‑execution billing (preview)### Security
Snippy uses User-Assigned Managed Identity for secure service-to-service authentication. The infrastructure is configured with:
* **User-Assigned Managed Identity** on the Function App with appropriate RBAC roles:
* Cosmos DB Data Contributor
* Storage Blob Data Owner and Queue Data Contributor
* Application Insights Monitoring Metrics Publisher
* Azure AI Project DeveloperFor production deployments, we recommend:
* Restrict inbound traffic with Private Endpoints + VNet integration
* Enable network security features like service endpoints and firewall rules---
## Resources
* Blog – *Build AI agent tools using Remote MCP with Azure Functions* ([https://aka.ms/snippy-blog](https://aka.ms/snippy-blog))
* Model Context Protocol spec – [https://aka.ms/mcp](https://aka.ms/mcp)
* Azure Functions Remote MCP docs – [https://aka.ms/azure-functions-mcp](https://aka.ms/azure-functions-mcp)
* Develop Python apps for Azure AI – [https://learn.microsoft.com/azure/developer/python/azure-ai-for-python-developers](https://learn.microsoft.com/azure/developer/python/azure-ai-for-python-developers)---
## Contributing
Standard **fork → branch → PR** workflow. Use *Conventional Commits* (`feat:`, `fix:`) in commit messages.
---
## License
MIT © Microsoft Corporation