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

相关推荐
霍格沃兹测试开发学社测试人社区43 分钟前
新手指南:通过 Playwright MCP Server 为 AI Agent 实现浏览器自动化能力
运维·人工智能·自动化
JJJJ_iii1 小时前
【机器学习01】监督学习、无监督学习、线性回归、代价函数
人工智能·笔记·python·学习·机器学习·jupyter·线性回归
qq_416276423 小时前
LOFAR物理频谱特征提取及实现
人工智能
余俊晖4 小时前
如何构造一个文档解析的多模态大模型?MinerU2.5架构、数据、训练方法
人工智能·文档解析
Akamai中国5 小时前
Linebreak赋能实时化企业转型:专业系统集成商携手Akamai以实时智能革新企业运营
人工智能·云计算·云服务
LiJieNiub6 小时前
读懂目标检测:从基础概念到主流算法
人工智能·计算机视觉·目标跟踪
weixin_519535776 小时前
从ChatGPT到新质生产力:一份数据驱动的AI研究方向指南
人工智能·深度学习·机器学习·ai·chatgpt·数据分析·aigc
爱喝白开水a7 小时前
LangChain 基础系列之 Prompt 工程详解:从设计原理到实战模板_langchain prompt
开发语言·数据库·人工智能·python·langchain·prompt·知识图谱
takashi_void7 小时前
如何在本地部署大语言模型(Windows,Mac,Linux)三系统教程
linux·人工智能·windows·macos·语言模型·nlp
OpenCSG7 小时前
【活动预告】2025斗拱开发者大会,共探支付与AI未来
人工智能·ai·开源·大模型·支付安全