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

相关推荐
技术小黑4 小时前
NLP学习系列 | Transformer代码简单实现
人工智能·自然语言处理
overstarry4 小时前
zed 配置 acp-claude-code 使用 Claude Code
人工智能·claude
yangshuo12814 小时前
Augmentcode免费额度AI开发WordPress商城实战
人工智能
JAMES费4 小时前
分布式AI算力系统番外篇-----超体的现实《星核》
人工智能·分布式
relis5 小时前
RoPE位置编码缩放因子的最优解:频率维度与位置敏感度的精妙权衡
人工智能·算法·语言模型
PetterHillWater5 小时前
Claude Code下Kimi-k2模型初试
aigc
山烛5 小时前
OpenCV 图像轮廓检测
图像处理·人工智能·python·opencv·计算机视觉·轮廓检测
Passwerob5 小时前
Deformable 3D Gaussians:把动态场景装进“可变形的静态世界”
人工智能·python·计算机视觉·3d·3dgs
云卓SKYDROID5 小时前
无人机传感器技术要点与难点解析
人工智能·数码相机·无人机·高科技·云卓科技·固件升级