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协议,开发者可以构建智能的云资源管理体验。

相关推荐
黑客思维者13 分钟前
机器学习001:从“让机器学会思考”到生活中的智能魔法
人工智能·机器学习·生活
ayingmeizi16325 分钟前
电子及通信设备制造业CRM解决方案,AI赋能线索+商机+销售+服务,助力企业降本增效与价值升级
人工智能·crm·数智化
也许是_27 分钟前
大模型应用技术之 Spring AI 2.0 变更说明
java·人工智能·spring
黑客思维者38 分钟前
机器学习006:监督学习【回归算法】(概论)--教AI从历史中预测未来
人工智能·学习·机器学习·监督学习·回归算法
高洁0142 分钟前
DNN案例一步步构建深层神经网络(二)
人工智能·python·深度学习·算法·机器学习
合方圆~小文1 小时前
4G定焦球机摄像头综合介绍产品指南
数据结构·数据库·人工智能
Coding茶水间1 小时前
基于深度学习的螺栓螺母检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·深度学习·yolo·目标检测·机器学习·计算机视觉
yiersansiwu123d1 小时前
AI全球善治的困境突破与中国方案的实践路径
人工智能
老蒋新思维1 小时前
反脆弱性设计:创始人IP与AI智能体如何构建愈动荡愈强大的知识商业|创客匠人
人工智能·网络协议·tcp/ip·算法·机器学习·创始人ip·创客匠人