Azure MCP Server:连接AI与Azure服务的智能桥梁

Azure MCP Server

Azure MCP Server 实现了 MCP 规范,在AI代理与Azure服务之间创建无缝连接。该项目目前处于公开预览阶段,在正式发布前实现可能会有重大变化。

✨ 功能特性

  • 多服务支持: 提供Azure Kubernetes Service (AKS)、App Configuration、Authorization RBAC、Datadog集成等多种Azure服务操作
  • 智能命令系统: 支持批量操作、资源列表查询、详细配置管理等丰富命令
  • 最佳实践指导: 内置Azure和Terraform最佳实践指导,确保代码生成符合生产标准
  • 安全认证: 集成Azure AD认证,支持跨租户操作和安全的权限管理
  • 缓存优化: 实现高效的缓存机制,提升查询性能和响应速度
  • 扩展性强: 模块化架构设计,易于添加新的服务区域和功能

🚀 安装指南

系统要求

  • Node.js (最新LTS版本)
  • VS Code (稳定版或Insiders版)
  • GitHub Copilot 和 GitHub Copilot Chat 扩展

推荐安装方式(VS Code用户)

  1. 安装VS Code:

  2. 安装必要的扩展:

  3. 配置MCP服务器: 在.vscode/mcp.json中添加配置:

json 复制代码
{
  "servers": {
    "Azure MCP Server": {
      "command": "npx",
      "args": ["-y", "@azure/mcp@latest", "server", "start"]
    }
  }
}

其他客户端配置

Windsurf用户 : 在~/.codeium/windsurf/mcp_config.json中配置:

json 复制代码
{
  "mcpServers": {
    "Azure MCP Server": {
      "command": "npx",
      "args": ["-y", "@azure/mcp@latest", "server", "start"]
    }
  }
}

📖 使用说明

快速开始

  1. 在VS Code中打开GitHub Copilot并切换到Agent模式
  2. 点击工具列表中的刷新按钮
  3. 尝试使用Azure MCP Server工具的提示,例如:"列出我的Azure存储容器"
  4. 代理应该能够使用Azure MCP Server工具完成您的查询

核心命令示例

列出AKS集群

bash 复制代码
azmcp-aks-cluster-list --subscription <订阅ID>

获取应用配置键值

bash 复制代码
azmcp-appconfig-kv-show --account <配置存储名称> --key <键名>

列出角色分配

bash 复制代码
azmcp-role-assignment-list --subscription <订阅ID> --scope <范围>

💻 核心代码

AKS服务实现

csharp 复制代码
// AzureMcp.Aks.Services.AksService
public sealed class AksService : BaseAzureService, IAksService
{
    public async Task<List<Cluster>> ListClusters(
        string subscription,
        string? tenant = null,
        RetryPolicyOptions? retryPolicy = null)
    {
        ValidateRequiredParameters(subscription);
        
        // 缓存键生成
        var cacheKey = string.IsNullOrEmpty(tenant)
            ? $"clusters_{subscription}"
            : $"clusters_{subscription}_{tenant}";

        // 优先从缓存获取
        var cachedClusters = await _cacheService.GetAsync<List<Cluster>>("aks", cacheKey, TimeSpan.FromHours(1));
        if (cachedClusters != null)
        {
            return cachedClusters;
        }

        // 获取订阅资源并列出集群
        var subscriptionResource = await _subscriptionService.GetSubscription(subscription, tenant, retryPolicy);
        var clusters = new List<Cluster>();

        await foreach (var cluster in subscriptionResource.GetContainerServiceManagedClustersAsync())
        {
            // 处理集群数据...
        }
        
        return clusters;
    }
}

App配置服务接口

csharp 复制代码
// AzureMcp.AppConfig.Services.IAppConfigService
public interface IAppConfigService
{
    Task<List<AppConfigurationAccount>> GetAppConfigAccounts(
        string subscriptionId, 
        string? tenant = null, 
        RetryPolicyOptions? retryPolicy = null);
    
    Task<List<KeyValueSetting>> ListKeyValues(
        string accountName,
        string subscriptionId,
        string? key = null, 
        string? label = null,
        string? tenant = null,
        RetryPolicyOptions? retryPolicy = null);
    
    Task<KeyValueSetting> GetKeyValue(
        string accountName, 
        string key, 
        string subscriptionId, 
        string? tenant = null, 
        RetryPolicyOptions? retryPolicy = null, 
        string? label = null);
    
    // 其他操作方法...
}

Bicep架构生成器

csharp 复制代码
// AzureMcp.BicepSchema.Services.SchemaGenerator
public static class SchemaGenerator
{
    public static List<ComplexType> GetResponse(TypesDefinitionResult typesDefinitionResult)
    {
        var allComplexTypes = new List<ComplexType>();
        allComplexTypes.AddRange(typesDefinitionResult.ResourceTypeEntities);
        allComplexTypes.AddRange(typesDefinitionResult.ResourceFunctionTypeEntities);
        allComplexTypes.AddRange(typesDefinitionResult.OtherComplexTypeEntities);
        return allComplexTypes;
    }

    public static TypesDefinitionResult GetResourceTypeDefinitions(
        IServiceProvider serviceProvider,
        string resourceTypeName,
        string? apiVersion = null)
    {
        var resourceVisitor = serviceProvider.GetRequiredService<ResourceVisitor>();
        
        if (string.IsNullOrEmpty(apiVersion))
        {
            apiVersion = ApiVersionSelector.SelectLatestStable(
                resourceVisitor.GetResourceApiVersions(resourceTypeName));
        }

        return resourceVisitor.LoadSingleResource(resourceTypeName, apiVersion);
    }
}

Azure MCP Server 提供了强大的工具集,使AI代理能够安全、高效地与Azure服务进行交互。通过标准化的MCP协议,开发者可以构建智能的云资源管理体验。

相关推荐
IT_陈寒29 分钟前
Vite 5年迭代揭秘:3个核心优化让你的项目构建速度提升200%
前端·人工智能·后端
doubao3641 分钟前
审美积累,顶刊论文插图原理图、流程图
人工智能·经验分享·aigc·ai写作·绘图·文献综述·科研绘图
CG大魔王1 小时前
SenseVoice微调
人工智能·语言模型·音频
爱编程的喵喵1 小时前
Al Agent开发零基础构建复合智能体
人工智能·agent·智能体
Pocker_Spades_A1 小时前
论文精读(六):微服务系统服务依赖发现技术综述
人工智能
catchadmin3 小时前
PHP 快速集成 ChatGPT 用 AI 让你的应用更聪明
人工智能·后端·chatgpt·php
杀生丸学AI3 小时前
【无标题】SceneSplat:基于视觉-语言预训练的3DGS场景理解
3d·aigc·slam·语义分割·三维重建·视觉大模型·空间智能
编程武士6 小时前
从50ms到30ms:YOLOv10部署中图像预处理的性能优化实践
人工智能·python·yolo·性能优化
max5006007 小时前
基于Meta Llama的二语习得学习者行为预测计算模型
人工智能·算法·机器学习·分类·数据挖掘·llama
月疯8 小时前
OPENCV摄像头读取视频
人工智能·opencv·音视频