-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathGetComponentDocsTool.cs
More file actions
54 lines (46 loc) · 2.47 KB
/
GetComponentDocsTool.cs
File metadata and controls
54 lines (46 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.ComponentModel;
using System.Diagnostics;
using Havit.Blazor.Documentation.Mcp.Diagnostics;
using Havit.Blazor.Documentation.Model;
using Havit.Blazor.Documentation.Services;
using ModelContextProtocol.Server;
namespace Havit.Blazor.Documentation.Mcp.Tools;
/// <summary>
/// MCP tool that provides component API documentation (including list of available demo samples) in Markdown format.
/// </summary>
internal class GetComponentDocsTool
{
private readonly IApiDocModelProvider _modelProvider;
private readonly IDocMarkdownRenderer _renderer;
private readonly IComponentDemosProvider _componentDemosProvider;
public GetComponentDocsTool(IApiDocModelProvider modelProvider, IDocMarkdownRenderer renderer, IComponentDemosProvider componentDemosProvider)
{
_modelProvider = modelProvider;
_renderer = renderer;
_componentDemosProvider = componentDemosProvider;
}
/// <summary>
/// Returns the API documentation for a HAVIT Blazor component in Markdown format, including demo samples.
/// </summary>
[McpServerTool(Name = "get_component_docs", Title = "Get component documentation", Destructive = false, Idempotent = true, ReadOnly = true)]
[Description("Returns the API documentation (parameters, properties, events, methods) for a HAVIT Blazor component or type. Provide the component name, e.g. 'HxButton', 'HxGrid', 'HxInputText'.")]
public string GetComponentDocs(
[Description("Name of the component or type to get documentation for, e.g. 'HxButton', 'HxGrid', 'HxInputText'.")] string componentName)
{
using Activity activity = McpToolActivitySource.Source.StartActivity("get_component_docs");
activity?.SetTag("mcp.tool.parameter.componentName", componentName);
Type type = ApiTypeHelper.GetType(componentName, includeTypesContainingTypeName: true);
if (type is null)
{
activity?.SetTag("mcp.tool.result", "not_found");
return $"Component '{componentName}' not found. Make sure the name matches a HAVIT Blazor component (e.g. HxButton, HxGrid, HxInputText). For supporting types (enums, settings), use the get_type_doc tool.";
}
ApiDocModel model = _modelProvider.GetApiDocModel(type);
IReadOnlyList<string> sampleNames = _componentDemosProvider.GetComponentDemoFileNames(componentName);
string markdown = _renderer.RenderComponentDoc(model, sampleNames);
activity?.SetTag("mcp.tool.result", "success");
activity?.SetTag("mcp.tool.resolvedType", type.FullName);
activity?.SetTag("mcp.tool.sampleCount", sampleNames.Count);
return markdown;
}
}