Blazor组件元数据服务

一个通过Model Context Protocol(MCP)暴露Blazor组件元数据的服务,用于AI辅助开发,使AI工具能够动态发现和检查实际的Blazor组件。

  • by SimonLiebers-Dev
  • C#
  • 本地部署
  • 10 星标
  • 更新于
在 GitHub 查看 SimonLiebers-Dev/Components.MCP.Blazor

使用说明

🧩 组件。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<UserCard>",
            "isRequired": false,
            "captureUnmatchedValues": false
          }
        ]
      }
    }
  ]
}

使用案例:
这使得AI工具能够了解任何组件的实际参数和注入的服务,从而实现:

  • 精确的Razor代码生成
  • 智能文档
  • 语义搜索和完成

⚙️ 运作原理

  1. 扫描程序集以查找从继承的所有类型 ComponentBase
  2. 收集 [Parameter], [CascadingParameter],以及 [Inject] 房产信息
  3. 通过标准化的MCP工具公开元数据
  4. 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<ComponentMetadataProvider>();

builder.Services
    .AddMcpServer()
    .AddBuiltInHandlers()
    .WithHttpTransport()
    .WithTools<ComponentTool>();

var app = builder.Build();
await app.RunAsync();

2.运行MCP服务器

dotnet run

🧱 路线图

  • []添加 components.search 基于名称的过滤工具
  • []添加 resources/read 用于原材料检查
  • []从XML注释中提供参数文档

📄 许可证

麻省 理工© 2025 西蒙 利伯斯