项目简介
这是一个基于Model Context Protocol (MCP) 构建的服务器实现,旨在集成到 Xperience by Kentico 应用中。它作为一个 NuGet 包提供,通过暴露特定的工具和资源,使得像 VS Code Copilot 这样的 AI 代理能够更好地理解和与 Xperience 项目的上下文进行交互,从而提升开发者的工作效率。
主要功能点
- 资源托管与访问: 将 Xperience 项目中的内容类型、页面结构、数据等暴露为可被 AI 代理访问和查询的资源。
- 工具注册与执行: 定义和注册特定于 Xperience 开发的工具,例如用于查询内容结构的工具,允许 AI 代理调用这些工具来执行任务。
- 增强 AI 代理能力: 为 LLM 客户端提供结构化的项目信息和操作能力,使 AI 能够提供更精确、相关的帮助和建议。
安装步骤
-
添加 NuGet 包: 在你的 Xperience by Kentico 项目的根目录中,使用 .NET CLI 添加此包:
dotnet add package XperienceCommunity.MCPServer -
配置 ASP.NET Core 应用: 打开你的 Xperience by Kentico 项目的 'Program.cs' 文件。在 'builder.Services' 配置中添加 MCP 依赖,并在 'app' 配置中添加 MCP 端点。通常建议在开发环境中启用:
// Program.cs // ... (using directives and existing code) var builder = WebApplication.CreateBuilder(args); // ... (existing service configuration) // Adds the MCP dependencies (typically in development) if (builder.Environment.IsDevelopment()) { builder.Services.AddXperienceMCPServer(); } // ... (existing service configuration) var app = builder.Build(); // ... (existing middleware configuration like app.UseStaticFiles(), app.UseKentico(), etc.) // Adds the MCP endpoint (typically in development) if (app.Environment.IsDevelopment()) { app.UseXperienceMCPServer(); } // ... (existing endpoint mapping like app.Kentico().MapRoutes(), app.MapControllerRoute(), etc.) await app.RunAsync(); // ... (static methods like ConfigureMembershipServices if they exist)请注意:如果你的应用使用 HTTPS 并带有自签名证书,并且你的 MCP 客户端(如当前版本的 VS Code)不支持自签名证书,你需要在 'launchSettings.json' 中添加一个 HTTP 绑定,并在下一步的客户端配置中使用该 HTTP URL。
服务器配置(MCP 客户端配置)
MCP 服务器部署并运行在你的 Xperience 应用中。AI 代理(例如 VS Code Copilot)需要配置如何连接到你的 MCP 服务器。这通常在客户端(如 VS Code)的设置中完成,而不是在你的 Xperience 项目代码中。
以下是一个示例 JSON 配置,用于告诉 MCP 客户端在哪里找到你的 MCP 服务器:
{ "servers": { "xperience-mcp-server": { // 服务器连接类型,http 表示通过 HTTP/HTTPS 连接 "type": "http", // MCP 服务器的 URL 端点。这应该是你的 Xperience 应用运行的地址加上 MCP 端点路径。 // 默认路径是 /xperience-mcp。请将 <your-port-here> 替换为你的应用实际监听的端口。 "url": "http://localhost:<your-port-here>/xperience-mcp" } } }
将上述 JSON 添加到你的 MCP 客户端(如 VS Code)的 MCP 配置中(通常是在一个名为 '.vscode/mcp.json' 的文件中)。确保 'url' 指向你的 Xperience 应用实际运行并启用 MCP 端点的地址和端口。
基本使用方法
-
启动 Xperience 应用: 运行你的 Xperience by Kentico 应用程序。
-
连接 MCP 服务器: 在配置了 MCP 客户端(如 VS Code)后,使用客户端提供的功能连接并启动配置好的 MCP 服务器。在 VS Code 中,你通常可以通过命令面板(Command Palette)查找并启动 MCP 服务器。
-
与 AI 代理交互: 使用 AI 代理(如 GitHub Copilot Chat)提出与你的 Xperience 项目相关的问题,AI 代理现在可以使用 MCP 服务器提供的工具和上下文来回答你的问题或执行任务。例如,你可以询问有关内容类型结构的问题:
Tell me about some of the web page content types in this project and a summary of their structure and relationships. For example, let me know if some of these web page content types have references to content items of other types as part of their field definition.AI 代理将通过 MCP 服务器调用相应的工具来获取这些信息。
信息
分类
开发者工具