Skip to main content
Glama
Azure Purview MCP Server

Azure Purview MCP Server

README.md
# Azure Purview MCP Server

> Model Context Protocol (MCP) server for Azure Purview - easily manage your data catalog with AI

Connect your AI assistant to Azure Purview to search, read, and update data catalog metadata including table and column descriptions.

## ⚠️ Important Notice

**Development Use Only**: This MCP server is intended strictly for developer use within your organization. Do not use these tools for external applications or scenarios outside the approved development environment.

**User Consent Required**: All tools that access or modify data require explicit user authorization and consent. Users must understand what data is being accessed and what actions are being taken before approval.

**Production Considerations**: For production deployments, implement additional security controls, audit logging, and appropriate access restrictions based on your organization's security policies.

## Quick Start

```bash
# 1. Login to Azure
az login

# 2. Install and build
npm install && npm run build

# 3. Create .env file
cat > .env << EOF
PURVIEW_ENDPOINT=https://your-purview-account.purview.azure.com
AUTH_METHOD=cli
EOF

# 4. Add to Claude Desktop config
# Edit: ~/Library/Application Support/Claude/claude_desktop_config.json
```

```json
{
  "mcpServers": {
    "purview": {
      "command": "node",
      "args": ["/absolute/path/to/purview-mcp-server/dist/index.js"],
      "env": {
        "PURVIEW_ENDPOINT": "https://your-purview-account.purview.azure.com",
        "AUTH_METHOD": "cli"
      }
    }
  }
}
```

That's it! Restart Claude Desktop and start using Purview.

See [QUICKSTART.md](QUICKSTART.md) for detailed step-by-step instructions.

## Features

✅ **Search & Discovery** - Find tables, columns, and assets in your Purview catalog
✅ **Read Metadata** - Get detailed information by GUID or qualified name
✅ **Update Descriptions** - Modify table and column descriptions (userDescription field)
✅ **Bulk Operations** - Upload descriptions from CSV or JSON files
✅ **Smart Retry Logic** - Automatic exponential backoff for failed requests
✅ **Flexible Auth** - Azure CLI (easiest), Interactive Browser, or Service Principal

## Prerequisites

- **Node.js** 18 or higher
- **Azure CLI** installed ([install guide](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli))
- **Azure Purview** account with access
- **Purview Permissions** - Your account needs the "Data Curator" role

## Authentication

### Option 1: Azure CLI (Recommended) 🎯

**Easiest method - uses your existing Azure login!**

```bash
az login
```

Configuration:
```env
PURVIEW_ENDPOINT=https://your-account.purview.azure.com
AUTH_METHOD=cli
```

✅ No Service Principal needed
✅ No secrets to manage
✅ Uses your Azure account

### Option 2: Interactive Browser

Opens a browser for authentication when first used.

Configuration:
```env
PURVIEW_ENDPOINT=https://your-account.purview.azure.com
AUTH_METHOD=interactive
AZURE_TENANT_ID=your-tenant-id  # Optional
```

### Option 3: Service Principal

For production deployments and automation.

```bash
# Create service principal
az ad sp create-for-rbac --name "purview-mcp-sp" --role Contributor
```

Configuration:
```env
PURVIEW_ENDPOINT=https://your-account.purview.azure.com
AUTH_METHOD=service-principal
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-client-secret
```

**Important:** Assign "Data Curator" role to the service principal in Purview:
1. Azure Portal → Purview Account → Data plane access
2. Add role assignment → Data Curator → Select your service principal

## Installation

```bash
# Clone or download this repository
cd purview-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

# Test it (optional)
npm run dev
```

## Configuration

### Create .env file

```bash
cp .env.example .env
```

### Edit .env with your settings

**Minimal configuration (Azure CLI):**
```env
PURVIEW_ENDPOINT=https://your-purview-account.purview.azure.com
AUTH_METHOD=cli
```

**All options:**
```env
# Required
PURVIEW_ENDPOINT=https://your-purview-account.purview.azure.com

# Authentication (choose one)
AUTH_METHOD=cli                    # Default: Azure CLI
# AUTH_METHOD=interactive          # Browser login
# AUTH_METHOD=service-principal    # Service Principal

# Only for service-principal auth
# AZURE_TENANT_ID=your-tenant-id
# AZURE_CLIENT_ID=your-client-id
# AZURE_CLIENT_SECRET=your-client-secret

# Optional
LOG_LEVEL=info
```

## MCP Client Setup

### Claude Desktop

**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "purview": {
      "command": "node",
      "args": ["/absolute/path/to/purview-mcp-server/dist/index.js"],
      "env": {
        "PURVIEW_ENDPOINT": "https://your-account.purview.azure.com",
        "AUTH_METHOD": "cli"
      }
    }
  }
}
```

⚠️ **Important:**
- Use the **absolute path** to your `dist/index.js` file
- Run `az login` before starting Claude Desktop
- Restart Claude Desktop after config changes

## Available Tools

### 🔍 search-entities

Search for assets in the Purview catalog.

**Parameters:**
- `keywords` (required) - Search terms
- `entityType` (optional) - Filter by type (e.g., "azure_sql_table", "azure_sql_column")
- `limit` (optional) - Max results (default: 50)

**Example usage in Claude:**
```
Search for all tables containing "customer" in Purview
```

### 📄 get-entity-by-guid

Get detailed metadata for an entity by its GUID.

**Parameters:**
- `guid` (required) - The entity GUID

**Example:**
```
Get metadata for Purview entity with GUID: abc123...
```

### 📄 get-entity-by-qualified-name

Get detailed metadata by qualified name.

**Parameters:**
- `qualifiedName` (required) - The qualified name (e.g., "mssql://server/db/schema/table")
- `typeName` (optional) - Entity type for precise search

**Example:**
```
Get metadata for table: mssql://myserver.database.windows.net/mydb/dbo/customers
```

### ✏️ update-description

Update the userDescription field for a table or column.

**Parameters:**
- `guid` (required) - The entity GUID
- `description` (required) - New description text (supports HTML)

**Example:**
```
Update the description for entity abc123 to "Customer master data table"
```

### 📦 bulk-update-from-csv

Bulk update descriptions from CSV content.

**Parameters:**
- `csvContent` (required) - CSV with columns: qualifiedName, name, description, typeName, guid
- `dryRun` (optional) - Default: true (validates without changes)

**CSV Format:**
```csv
qualifiedName,name,description,typeName,guid
mssql://server/db/schema/table,Table,Table description,azure_sql_table,
mssql://server/db/schema/table#col1,Col1,Column description,azure_sql_column,
```

**Example:**
```
Bulk update descriptions from this CSV:
[paste CSV content]
Set dryRun to false to apply changes.
```

### 📦 bulk-update-from-json

Bulk update descriptions from JSON array.

**Parameters:**
- `jsonContent` (required) - JSON array of entity updates
- `dryRun` (optional) - Default: true

**JSON Format:**
```json
[
  {
    "qualifiedName": "mssql://server/db/schema/table",
    "typeName": "azure_sql_table",
    "description": "Customer data table"
  }
]
```

## Usage Examples

### Search and Update Workflow

```
You: Search for tables with "sales" in the name

Claude: [Uses search-entities tool]
Found 5 tables with "sales":
1. SalesOrders (GUID: abc123...)
2. SalesCustomers (GUID: def456...)
...

You: Update the description for SalesOrders to "Main sales transaction table"

Claude: [Uses update-description tool with GUID abc123]
Successfully updated description!
```

### Bulk Update Workflow

```
You: I have a CSV file with 100 table descriptions. Can you update them?

Claude: Please paste the CSV content.

You: [pastes CSV]
qualifiedName,name,description,typeName
mssql://server/db/dbo/Customers,Customers,Customer master data,azure_sql_table
...

Claude: [Uses bulk-update-from-csv with dryRun=true]
Validation results: Would update 100 entities. Ready to apply?

You: Yes, apply the changes

Claude: [Uses bulk-update-from-csv with dryRun=false]
Processed 100 entities: 98 successful, 2 failed
```

## Key Concepts

### Qualified Names

Unique identifiers for Purview entities:

- **Azure SQL Table:** `mssql://server.database.windows.net/database/schema/table`
- **Azure SQL Column:** `mssql://server.database.windows.net/database/schema/table#columnName`
- **Hive Table:** `default.table_name@cluster`

### Entity Types

Common types in Purview:
- `azure_sql_table` - Azure SQL tables
- `azure_sql_column` - Azure SQL columns
- `azure_data_explorer_table` - ADX tables
- `azure_data_explorer_column` - ADX columns
- `hive_table` - Hive tables
- `hive_column` - Hive columns

### Description Fields

- **description** - System-generated from scans (read-only)
- **userDescription** - User-provided descriptions (this is what gets updated)

## Advanced Features

### Retry Logic

- Automatic retry with exponential backoff
- Retries on network errors, rate limits, and server errors
- Up to 3 retry attempts with increasing delays

### Batch Processing

- Bulk operations process 50 entities per batch
- Progress logged to console
- Individual failures don't stop the batch

### Error Handling

- Detailed error messages
- Failed updates collected and reported
- Validation before making changes

## Troubleshooting

### Authentication Issues

**Azure CLI authentication:**
```bash
# Check if logged in
az account show

# Re-login
az login

# Clear cache if needed
az account clear && az login
```

**Verify Purview permissions:**
1. Go to Azure Portal
2. Navigate to your Purview account
3. Check "Data plane access"
4. Ensure you have "Data Curator" role

### Common Errors

**"Missing required environment variable: PURVIEW_ENDPOINT"**
- Create `.env` file with your Purview endpoint

**"Entity not found"**
- Use search-entities first to find the correct qualified name
- Verify the entity exists in Purview catalog

**"Authentication failed"**
- For CLI: Run `az login`
- For Interactive: Check tenant ID is correct
- For Service Principal: Verify credentials and roles

**Server not appearing in Claude**
- Use absolute path in config (not relative)
- Check Claude logs for errors
- Restart Claude Desktop completely

### Rate Limiting

If you hit rate limits:
- Reduce batch sizes in bulk operations
- The server automatically retries with backoff
- Add delays between large operations

## Development

```bash
# Run in development mode
npm run dev

# Build
npm run build

# Run built version
npm start

# Watch mode (auto-rebuild)
npm run watch
```

## Project Structure

```
purview-mcp-server/
├── src/
│   ├── index.ts              # MCP server entry point
│   ├── config.ts             # Configuration & auth settings
│   ├── purview/
│   │   ├── client.ts        # Purview client with auth
│   │   ├── entities.ts      # Entity CRUD operations
│   │   ├── search.ts        # Search operations
│   │   └── bulk.ts          # Bulk operations
│   ├── tools/
│   │   └── index.ts         # MCP tool handlers
│   ├── utils/
│   │   ├── errors.ts        # Error handling
│   │   ├── retry.ts         # Retry logic
│   │   └── csv.ts           # CSV parsing
│   └── types/
│       └── index.ts         # TypeScript types
├── examples/
│   ├── sample-descriptions.csv
│   └── sample-descriptions.json
├── dist/                     # Built JavaScript
├── .env                      # Your config (not in git)
├── .env.example             # Template
├── package.json
├── tsconfig.json
├── README.md                # This file
└── QUICKSTART.md            # Quick start guide
```

## Security Notes

- Never commit `.env` file to version control
- Use Azure CLI auth for development
- Use Service Principal for production with proper secret management
- Rotate Service Principal secrets regularly
- Grant minimum required permissions (Data Curator role only)

## Resources

- [Azure Purview Documentation](https://learn.microsoft.com/en-us/azure/purview/)
- [Purview REST API Reference](https://learn.microsoft.com/en-us/rest/api/purview/)
- [Model Context Protocol](https://modelcontextprotocol.io)
- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
- [Azure CLI Documentation](https://docs.microsoft.com/en-us/cli/azure/)

## Important Documents

- [Privacy Policy](PRIVACY.md) - How we handle your data
- [Testing Guide](TESTING.md) - Set up test environment with sample data
- [Quick Start](QUICKSTART.md) - 5-minute setup guide
- [MD to Purview Workflow](WORKFLOW_MD_TO_PURVIEW.md) - Upload descriptions from markdown files
- [License](LICENSE) - MIT License

## License

MIT

## Contributing

Contributions welcome! Please open an issue or PR.

## Support

For issues or questions:
1. Check the [Troubleshooting](#troubleshooting) section
2. Review [QUICKSTART.md](QUICKSTART.md)
3. Open an issue on GitHub with:
   - Error messages
   - Your configuration (redact secrets!)
   - Steps to reproduce

---

**Made with ❤️ for Azure Purview users**