Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ExcelMcp.McpServer/Tools/ExcelPivotTableTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ namespace Sbroenne.ExcelMcp.McpServer.Tools;
/// <summary>
/// MCP tool for Excel PivotTable operations
/// </summary>
[McpServerToolType]
public static partial class ExcelPivotTableTool
{
private static readonly JsonSerializerOptions JsonOptions = ExcelToolsBase.JsonOptions;

[McpServerTool]
[McpServerTool(Name = "excel_pivottable")]
[Description(@"Excel PivotTable operations - interactive data analysis and summarization.

DATA SOURCES:
Expand Down
93 changes: 93 additions & 0 deletions tests/ExcelMcp.McpServer.Tests/Unit/ToolDiscoveryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Reflection;
using ModelContextProtocol.Server;
using Sbroenne.ExcelMcp.McpServer.Tools;
using Xunit;

namespace Sbroenne.ExcelMcp.McpServer.Tests.Unit;

/// <summary>
/// Tests to verify that all MCP tools are properly decorated with required attributes
/// for discovery by the MCP SDK's WithToolsFromAssembly() method.
/// </summary>
[Trait("Category", "Unit")]
[Trait("Speed", "Fast")]
[Trait("Layer", "McpServer")]
[Trait("Feature", "ToolDiscovery")]
public class ToolDiscoveryTests
{
[Fact]
public void ExcelPivotTableTool_HasMcpServerToolTypeAttribute()
{
// Arrange
var toolType = typeof(ExcelPivotTableTool);

// Act
var attribute = toolType.GetCustomAttribute<McpServerToolTypeAttribute>();

// Assert
Assert.NotNull(attribute);
}

[Fact]
public void ExcelPivotTableTool_HasMcpServerToolAttributeWithName()
{
// Arrange
var toolType = typeof(ExcelPivotTableTool);
var method = toolType.GetMethod("ExcelPivotTable", BindingFlags.Public | BindingFlags.Static);
Assert.NotNull(method);

// Act
var attribute = method!.GetCustomAttribute<McpServerToolAttribute>();

// Assert
Assert.NotNull(attribute);
Assert.Equal("excel_pivottable", attribute!.Name);
}

[Theory]
[InlineData(typeof(ExcelConnectionTool), "ExcelConnection", "excel_connection")]
[InlineData(typeof(ExcelDataModelTool), "ExcelDataModel", "excel_datamodel")]
[InlineData(typeof(ExcelFileTool), "ExcelFile", "excel_file")]
[InlineData(typeof(ExcelNamedRangeTool), "ExcelParameter", "excel_namedrange")]
[InlineData(typeof(ExcelPivotTableTool), "ExcelPivotTable", "excel_pivottable")]
[InlineData(typeof(ExcelPowerQueryTool), "ExcelPowerQuery", "excel_powerquery")]
[InlineData(typeof(ExcelQueryTableTool), "ExcelQueryTable", "excel_querytable")]
[InlineData(typeof(ExcelRangeTool), "ExcelRange", "excel_range")]
[InlineData(typeof(TableTool), "Table", "excel_table")]
[InlineData(typeof(ExcelVbaTool), "ExcelVba", "excel_vba")]
[InlineData(typeof(ExcelWorksheetTool), "ExcelWorksheet", "excel_worksheet")]
public void AllTools_HaveMcpServerToolAttributeWithCorrectName(Type toolType, string methodName, string expectedToolName)
{
// Arrange
var method = toolType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
Assert.NotNull(method);

// Act
var attribute = method!.GetCustomAttribute<McpServerToolAttribute>();

// Assert
Assert.NotNull(attribute);
Assert.Equal(expectedToolName, attribute!.Name);
}

[Theory]
[InlineData(typeof(ExcelConnectionTool))]
[InlineData(typeof(ExcelDataModelTool))]
[InlineData(typeof(ExcelFileTool))]
[InlineData(typeof(ExcelNamedRangeTool))]
[InlineData(typeof(ExcelPivotTableTool))]
[InlineData(typeof(ExcelPowerQueryTool))]
[InlineData(typeof(ExcelQueryTableTool))]
[InlineData(typeof(ExcelRangeTool))]
[InlineData(typeof(TableTool))]
[InlineData(typeof(ExcelVbaTool))]
[InlineData(typeof(ExcelWorksheetTool))]
public void AllTools_HaveMcpServerToolTypeAttribute(Type toolType)
{
// Act
var attribute = toolType.GetCustomAttribute<McpServerToolTypeAttribute>();

// Assert
Assert.NotNull(attribute);
}
}
Loading