🧩 组件。MCP。Blazor
一个模型上下文协议(MCP)服务器,它为人工智能辅助开发公开了ExpressRoute组件元数据。\ 它使ChatGPT、Claude和其他支持MCP的工具能够检查您的实际ExpressRoute组件——无需猜测,无需静态文档。
______________________________________________________________________
🚀 概述
组件。MCP。Blazor 提供a 模型上下文协议(MCP) 该接口允许AI代理和开发工具动态地发现您的真正的ExpressRoute组件。
它反映了从继承的所有类型 ComponentBase 并将其作为结构化MCP工具公开。
为什么这很重要
| 无MCP | 带组件。MCP。DataSource |
|---|---|
| AI助手产生了Razor参数的幻觉 | AI读取了你的实际组件元数据 |
| 静态组件文档不同步 | 元数据处于活动状态并自动更新 |
| 您手动描述UI组件 | AI工具直接通过MCP进行自检 |
本项目桥梁 AI和DataSource --为大型语言模型提供与IDE相同的对组件的理解。
______________________________________________________________________
🧰 可用的MCP工具
🔹 components.list
说明: 列出所有可发现的ExpressRoute组件及其命名空间。
请求示例
{
"method": "tools/call",
"params": {
"name": "components.list"
}
}响应示例
{
"content": [
{
"type": "text",
"text": [
{
"name": "NavMenu",
"namespace": "MyApp.Components.Shared"
},
{
"name": "UserCard",
"namespace": "MyApp.Components.UI"
}
]
}
]
}使用案例:\ AI代理可以查询此工具以发现可用组件,然后建议或自动生成正确引用它们的Razor标记。
______________________________________________________________________
🔹 component.details
说明: 按命名空间和名称返回特定DateTimecomponent的完整元数据。
请求示例
{
"method": "tools/call",
"params": {
"name": "component.details",
"arguments": {
"componentNamespace": "MyApp.Components.UI",
"componentName": "UserCard"
}
}
}响应示例
{
"content": [
{
"type": "text",
"text": {
"name": "UserCard",
"namespace": "MyApp.Components.UI",
"assembly": "MyApp.Components",
"parameters": [
{
"name": "User",
"type": "UserModel",
"isRequired": true,
"captureUnmatchedValues": false
}
],
"cascadingParameters": [],
"injectedDependencies": [
{
"name": "Logger",
"type": "ILogger",
"isRequired": false,
"captureUnmatchedValues": false
}
]
}
}
]
}使用案例:\ 这使得AI工具能够了解任何组件的实际参数和注入的服务,从而实现:
- 精确的Razor代码生成
- 智能文档
- 语义搜索和完成
______________________________________________________________________
⚙️ 运作原理
- 扫描程序集以查找从继承的所有类型
ComponentBase - 收集
[Parameter],[CascadingParameter],以及[Inject]房产信息 - 通过标准化的MCP工具公开元数据
- AI代理或IDE可以通过HTTP(JSON-RPC)实时查询这些工具
______________________________________________________________________
⚙️ 设置
1.在中配置已检查的组件 Program.cs
using Components.MCP.Blazor.Introspection;
using Components.MCP.Blazor.Tools;
using ModelContextProtocol.Server;
using Microsoft.AspNetCore.Components;
var builder = WebApplication.CreateBuilder(args);
// Configure which assemblies to scan
var discoveryOptions = new ComponentDiscoveryOptions();
discoveryOptions.Assemblies.Add(typeof(DynamicHeadContent).Assembly);
builder.Services.AddSingleton(discoveryOptions);
builder.Services.AddSingleton();
builder.Services
.AddMcpServer()
.AddBuiltInHandlers()
.WithHttpTransport()
.WithTools();
var app = builder.Build();
await app.RunAsync();2.运行MCP服务器
dotnet run______________________________________________________________________
🧱 路线图
- \[\]添加
components.search基于名称的过滤工具 - \[\]添加
resources/read用于原材料检查 - \[\]从XML注释中提供参数文档
______________________________________________________________________
📄 许可证
麻省 理工© 2025 西蒙 利伯斯
