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:

    • 稳定版
    • Insiders版
  2. 安装必要的扩展:

    • GitHub Copilot
    • GitHub Copilot Chat
    • Azure MCP Server
  3. 配置MCP服务器: 在.vscode/mcp.json中添加配置:

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

其他客户端配置

Windsurf用户: 在~/.codeium/windsurf/mcp_config.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集群

azmcp-aks-cluster-list --subscription <订阅ID>

获取应用配置键值

azmcp-appconfig-kv-show --account <配置存储名称> --key <键名>

列出角色分配

azmcp-role-assignment-list --subscription <订阅ID> --scope <范围>

? 核心代码

AKS服务实现

// 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配置服务接口

// 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架构生成器

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

本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:[email protected]