资讯动态

Microsoft Agent Framework(.NET) - 尝试一下从MCP Server上获取Agent Skills

发布时间:2026/8/12 19:06:07 来源:尧图企业网站定制
1. 简单介绍MCP是Anthropic公司于2024年11月正式推出MCP开放协议解决了Model和外部系统的连接问题。2025年12月Anthropic正式将Agent Skills发布为一项开放标准Agent Skills允许将特定领域知识打包成独立的Skill在运行时按需加载到 Agent 的上下文中。MCP和Agent Skills两个协议都是Anthropic推出的。微软在2026年4月3号发布了Microsoft Agent Framework(简称MAF) 1.0。MAF提供了两种能力一个是智能体创建另外一个是工作流创建多智能体的编排。这个框架也可以集成MCP和Agent Skills了MAF提供了AgentSkillProvider/AgentSkillsProviderBuilder/AgentClassSkill/AgentInlineSkill等对象模型来支持Agent Skills的集成(file-based skill/class-based skill/inline code-defined skill)。在项目中Agent Skills一般以文件或者代码的存在于应用程序中如果多个应用程序都要使用到同一个Agent Skills则需要在每个应用中创建一份。当前MAF发布了一个新的特性支持从MCF server去获取Agent Skills这样不同Agent应用程序可以从同一个源头去获取Agent Skills便于对Agent Skills进行统一管理和版本控制。这边将简单尝试一下MCP Server发布Agent Skills的新特性同时创建一个简单的Agent去获取Agent Skills。原本打算在AI Agent中使用GitHub Models中的大模型发现GitHub Models当前不能使用了这边后来使用的是DeepSeek的deepseek-v4-pro模型。note, 关于创建MCP server的创建也可以参考一下之前的文章Model Context Protocol (MCP) - 尝试创建和测试一下MCP ServerAI - 尝试一下基于A2A SDK v1使用Microsoft Agent Framework for .NET创建A2A(Agent to Agent) Server和A2A Client2.创建应用程序这边是基于.NET10创建的控制台应用程序。MCP server可以采用两种方式来发布Agent Skills。一种是skill-md将Agent Skills的agent.md以及相关文件以MCP resource的方式暴露出去。另外一种是archiveAgent Skills相关文件以一个archive文件存在于MCP ServerAgent从MCP server获取到的archive文件需要先解压缩然后再使用。存在于archieve中的script将不会被执行。这边创建的应用程序用于获取2025年亚洲杯男篮球员的一些统计信息2.1 添加MCP相关package在项目中添加Microsoft.Agents.AI.Mcp 和 ModelContextProtocol nuget packagenote, 目前ModelConextProtocol已经是2.0.0版本了2.2 创建MCP Server这边采用的MCP协议是Stdiovar builder Host.CreateApplicationBuilder(); builder.Services.AddMcpServer(o o.ServerInfo new() { Name SkillsServer, Version 1.0.0 }) .WithStdioServerTransport() .WithResourcesSkillResources(); await builder.Build().RunAsync();2.3 创建MCP resourceAgent Skills内容将被定义在MCP resource中[McpServerResourceType] internal sealed class SkillResources { private const string IndexJson { $schema: https://schemas.agentskills.io/discovery/0.2.0/schema.json, skills: [ { name: asia-cup-2025-player-data-analysis, type: skill-md, description: Get the average height and age for Asia Cup Players 2025, url: skill://asia-cup-2025-player-data-analysis/SKILL.md } ] } ; private const string SkillMd --- name: asia-cup-2025-player-data-analysis description: asia-cup-2025-player-data-analysis is used to get player data for Asia Cup 2025 and some analysis can be made based on the data. --- ## Asia Cup 2025 Player Data When the user requests a data analysis, use below Asia Cup 2025 data metrics: |Region | Average Age | Average Height | |---------------|----------------------|------------------| |Australia | 24.50 | 200.17 | |China | 26.08 | 199.67 | |New Zealand | 25.25 | 197.58 | |South Korea | 27.25 | 193.25 | |Chinese Taipei | 27.67 | 192.92 | |Japan | 26.00 | 193.50 | |Philippines | 30.67 | 197.67 | |Iran | 26.00 | 197.00 | |Lebanon | 29.50 | 195.25 | ; [McpServerResource(UriTemplate skill://index.json, Name Skill Index, MimeType application/json)] [Description(SEP-2640 skill discovery index)] public static string GetIndex() IndexJson; [McpServerResource(UriTemplate skill://asia-cup-2025-player-data-analysis/SKILL.md, Name Asia Cup 2025 Player Data Analysis Skill, MimeType text/markdown)] [Description(Asia Cup 2025 Player Data Analysis skill instructions)] public static string GetSkillMd() SkillMd; }2.4 创建MCP clientawait using McpClient client await McpClient.CreateAsync( new StdioClientTransport(new() { Name skills-server, Command dotnet, Arguments [thisAssemblyPath, --server], }));2.5 创建AgentSkillProvider将之前创建的MCP client作为UseMcpSkills方法的参数最后创建出一个AgentSkillProvidervar skillsProvider new AgentSkillsProviderBuilder() .UseMcpSkills(client) .Build();2.6 创建AI Agent将步骤2.5创建的AgentSkillProvider添加到AIConextProviders中这样AI Agent就有了Skill的上下文了代码如下所示AIAgent agent chatClient .AsAIAgent(new ChatClientAgentOptions { Name SkillsAgent, ChatOptions new() { ModelId model, Instructions You are a helpful assistant. Use available skills to answer the user., }, AIContextProviders [skillsProvider], }) .AsBuilder() .UseToolApproval(new ToolApprovalAgentOptions { AutoApprovalRules [AgentSkillsProvider.AllToolsAutoApprovalRule], }) .Build();2.7 使用AI Agent这边要获取的是2025年亚洲杯男篮球员的平均身高然后按降序排列AgentResponse response await agent.RunAsync(Please tell me average height data for Asia Cup 2025 Players,and sort by height desc. And finally show the info as table.); Console.WriteLine($Agent: {response.Text});3. 运行项目使用dotnet run命令运行项目最后Agent返回了预期的亚洲杯男篮球员的信息4.总结本文简单介绍了一下如何在MCP server中部署Agent Skills以及在Agent中如何使用这些Agent Skills的过程。当前MCP skills API处于experimental阶段。关于Microsoft Agent Framework的内容很多还需继续跟着微软老师学习一下。本文如果哪里有错误麻烦告之谢谢谢谢

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价