Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计通过

mcp-csharp-testMCP csharp 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

4,163

周安装

177

GitHub Stars

1,527

下载量

1,458
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:mcp-csharp-test(MCP csharp 测试)
来源仓库:https://github.com/dotnet/skills
仓库路径:skills/mcp-csharp-test
安装命令:
npx skills add https://github.com/dotnet/skills --skill mcp-csharp-test
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dotnet/skills --skill mcp-csharp-test

简介

用于辅助测试设计、用例整理和回归验证,适合编写单元测试或分析失败日志。

  • 适用于需要自动化测试、端到端测试或测试计划支持的场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 使用时需确认测试框架、运行命令和夹具数据,避免误改逻辑。
  • 涉及浏览器或外部服务时应区分本地模拟与生产环境。

SKILL.md

C# MCP Server Testing

Test MCP servers at two levels: unit tests for individual tool methods, and integration tests that exercise the full MCP protocol in-memory.

When to Use

  • Adding automated tests to an MCP server
  • Testing individual tool methods with mocked dependencies
  • Writing integration tests that validate tool listing and invocation via MCP protocol
  • Setting up CI test pipelines for MCP servers

Stop Signals

  • No server yet? → Use mcp-csharp-create first
  • Server not running? → Use mcp-csharp-debug
  • Just need manual/interactive testing? → Use mcp-csharp-debug for MCP Inspector

Inputs

InputRequiredDescription
MCP server project pathYesPath to the server .csproj being tested
Test frameworkRecommendedDefault: xUnit. Also supports NUnit or MSTest
Transport typeRecommendedDetermines integration test approach (stdio vs HTTP)

Workflow

Step 1: Create the test project

dotnet new xunit -n <ServerName>.Tests
cd <ServerName>.Tests
dotnet add reference ../<ServerName>/<ServerName>.csproj
dotnet add package ModelContextProtocol
dotnet add package Moq
dotnet add package FluentAssertions

Step 2: Write unit tests for tool methods

Test tool methods directly — fastest and most isolated:

public class MyToolTests
{
    [Fact]
    public void Echo_ReturnsFormattedMessage()
    {
        var result = MyTools.Echo("Hello");
        result.Should().Be("Echo: Hello");
    }

    [Theory]
    [InlineData("")]
    [InlineData("   ")]
    public void Echo_HandlesEdgeCases(string input)
    {
        var result = MyTools.Echo(input);
        result.Should().StartWith("Echo:");
    }
}

For tools with DI dependencies, mock the dependency:

public class ApiToolTests
{
    [Fact]
    public async Task FetchData_ReturnsApiResponse()
    {
        var handler = new MockHttpMessageHandler("""{"id": 1}""");
        var httpClient = new HttpClient(handler);

        var result = await ApiTools.FetchData(httpClient, "resource-1");
        result.Should().Contain("id");
    }
}

Step 3: Write integration tests with MCP client

Test the full MCP protocol using a client-server connection:

using ModelContextProtocol.Client;

public class ServerIntegrationTests : IAsyncLifetime
{
    private McpClient _client = null!;

    public async Task InitializeAsync()
    {
        var transport = new StdioClientTransport(new StdioClientTransportOptions
        {
            Name = "TestClient",
            Command = "dotnet",
            Arguments = ["run", "--project", "../<ServerName>/<ServerName>.csproj"]
        });
        _client = await McpClient.CreateAsync(transport);
    }

    public async Task DisposeAsync() => await _client.DisposeAsync();

    [Fact]
    public async Task Server_ListsExpectedTools()
    {
        var tools = await _client.ListToolsAsync();
        tools.Should().Contain(t => t.Name == "echo");
    }

    [Fact]
    public async Task Tool_ReturnsExpectedResult()
    {
        var result = await _client.CallToolAsync("echo",
            new Dictionary<string, object?> { ["message"] = "Test" });
        var text = result.Content.OfType<TextContentBlock>().First().Text;
        text.Should().Contain("Test");
    }
}

For the SDK's ClientServerTestBase (in-memory testing) and HTTP testing with WebApplicationFactory, see references/test-patterns.md.

Step 4: Run tests

# Run all tests
dotnet test

# Run a specific test class
dotnet test --filter "FullyQualifiedName~MyToolTests"

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

Step 5: Write evaluations

Evaluations measure how well an LLM uses your tools. Good evaluation questions should be:

  • Read-only and non-destructive — never modify data as a side effect
  • Deterministic — have a single verifiable correct answer
  • Multi-step — require the LLM to call multiple tools or reason across results

For the evaluation format, example questions, and detailed guidance, see references/evaluations.md.

Validation

  • Unit tests cover all tool methods, including edge cases
  • Integration tests verify tool listing via ListToolsAsync()
  • Integration tests verify tool invocation via CallToolAsync()
  • All tests pass: dotnet test
  • Tests run in CI without manual setup

Common Pitfalls

PitfallSolution
Integration test hangs on CreateAsyncServer fails to start. Verify dotnet build succeeds first. For stdio, ensure no stdout logging
StdioClientTransport not finding projectUse the correct relative path to .csproj from the test project directory
Tests pass locally but fail in CIRun dotnet build before test execution. Use --no-build only after an explicit build step
Mocking HttpClient is awkwardMock HttpMessageHandler, not HttpClient directly. See references/test-patterns.md
Full test suite runs are slowUse --filter for development. Run the full suite only for CI verification

Related Skills

  • mcp-csharp-create — Create a new MCP server project
  • mcp-csharp-debug — Running and interactive debugging
  • mcp-csharp-publish — NuGet, Docker, Azure deployment

Reference Files

  • references/test-patterns.md — Complete test code examples: ClientServerTestBase in-memory pattern, WebApplicationFactory for HTTP, MockHttpMessageHandler helper, test categorization, coverage reporting. Load when: writing integration tests or need detailed mock patterns.
  • references/evaluations.md — Evaluation format, question design principles, and example eval questions. Load when: user asks about evaluations, eval questions, or measuring tool quality.

More Info

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.66%
按下载量换算520

Claude

30.45%
按下载量换算444

Cursor

16.91%
按下载量换算247

Gemini CLI

9.28%
按下载量换算135

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills