mcplinker 2.0.1

dotnet tool install --global mcplinker --version 2.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local mcplinker --version 2.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=mcplinker&version=2.0.1
                    
nuke :add-package mcplinker --version 2.0.1
                    

McpHelper.Linker

MCP Server CLI 工具,动态加载工具 from CS scripts, DLLs, and CSProj projects。

功能特性

  • 多源加载 - 支持 CS 脚本、DLL、CSProj 项目三种工具源
  • 后端代理 - 支持 HTTP 和 Stdio 后端服务代理
  • 灵活配置 - 支持 JSON 配置文件和命令行参数
  • 权限控制 - 支持文件系统和网络访问权限限制
  • 多种传输 - 支持 Stdio 和 SSE 两种传输模式

安装

全局安装

dotnet tool install -g mcplinker

本地安装

dotnet tool install mcplinker

从源码编译

git clone https://github.com/csvkse/mcphelper.git
cd mcphelper
dotnet pack src/McpHelper.Linker -c Release
dotnet tool install -g ./src/McpHelper.Linker/nupkg/McpHelper.Linker.1.0.1.nupkg

依赖

包名 版本 说明
ModelContextProtocol.AspNetCore 1.2.0 MCP 协议实现
Microsoft.CodeAnalysis.CSharp.Scripting 5.3.0 CS 脚本编译
Buildalyzer 8.0.0 CSProj 项目分析
System.CommandLine 2.0.5 CLI 参数解析

目标框架

  • .NET 10.0

快速开始

1. 创建配置文件

mcplinker.json:

{
  "McpLinker": {
    "ServerName": "MyMcpServer",
    "ServerVersion": "1.0.0",
    "Transport": {
      "Mode": "Stdio"
    },
    "Sources": [
      {
        "Type": "CsScript",
        "Path": "tools/*.cs"
      }
    ]
  }
}

2. 创建工具脚本

tools/SimpleTools.cs:

using System.ComponentModel;
using ModelContextProtocol.Server;
using System.Text.Json;

[McpServerToolType]
public class SimpleTools
{
    [McpServerTool]
    [Description("计算两个数的和。参数 a:第一个数,参数 b:第二个数。")]
    public Task<string> Add(double a, double b)
    {
        return Task.FromResult(JsonSerializer.Serialize(new { a, b, result = a + b }));
    }
}

3. 启动服务

mcplinker serve --config mcplinker.json

CLI 命令

serve

启动 MCP Server:

# Stdio 模式(默认)
mcplinker serve --config mcplinker.json

# SSE 模式
mcplinker serve --config mcplinker.json --transport sse --port 5000

# 命令行参数方式
mcplinker serve --script tools/*.cs --dll plugins/MyPlugin.dll --csproj ../MyProject/MyProject.csproj

list

列出已发现的工具:

mcplinker list --config mcplinker.json
mcplinker list --script tools/*.cs --output json

verify

验证工具源配置:

mcplinker verify --config mcplinker.json
mcplinker verify --dll plugins/MyPlugin.dll --validate-deps

interactive

交互模式:

mcplinker interactive --config mcplinker.json

CLI 参数

传输配置

参数 简写 说明 示例
--transport -t 传输模式:stdio、sse --transport sse
--port -p SSE 模式端口 --port 5000
--ip -i SSE 模式监听 IP --ip 0.0.0.0

工具源配置

参数 简写 说明 示例
--config -c 配置文件路径 --config mcplinker.json
--script -s CS 脚本路径(支持通配符) --script tools/*.cs
--dll -d DLL 文件路径(支持通配符) --dll plugins/*.dll
--csproj CSProj 项目路径 --csproj ../MyProject/MyProject.csproj

服务注册

参数 说明 示例
--service 注册服务(格式:类型,程序集:生命周期) --service "MyService,MyDll:Singleton"
--service-config 服务注册配置文件 --service-config services.json

其他配置

参数 说明 示例
--log-level 日志级别:trace/debug/info/warn/error --log-level debug
--output 输出格式:text、json --output json
--tool-prefix 工具名称前缀 --tool-prefix myapp_
--dry-run 仅验证配置不启动服务 --dry-run

配置文件

完整配置示例

{
  "McpLinker": {
    "ServerName": "MyMcpServer",
    "ServerVersion": "1.0.0",

    "Transport": {
      "Mode": "Stdio",
      "Port": 5000,
      "Ip": "127.0.0.1"
    },

    "Sources": [
      {
        "Type": "CsScript",
        "Path": "tools/*.cs",
        "AdditionalUsings": ["System", "System.IO", "System.Text.Json"],
        "References": ["lib/Helper.dll"]
      },
      {
        "Type": "Dll",
        "Path": "plugins/MyPlugin.dll",
        "DependencySearchPaths": ["./lib"],
        "UseIsolatedContext": true
      },
      {
        "Type": "Csproj",
        "Path": "../MyProject/MyProject.csproj",
        "BuildConfiguration": "Release",
        "TargetFramework": "net10.0",
        "RestoreNuGetPackages": true
      },
      {
        "Type": "Backend",
        "BackendTransportType": "Http",
        "Url": "http://localhost:5000/mcp",
        "Name": "remote",
        "ApiKey": "your-key",
        "ToolPrefix": "remote_"
      }
    ],

    "ServiceRegistrations": [
      {
        "ServiceType": "IMyService, MyAssembly",
        "ImplementationType": "MyService, MyAssembly",
        "Lifetime": "Singleton"
      }
    ],

    "ToolPrefix": "",
    "ToolNameConflict": "Error",
    "LogLevel": "info"
  }
}

工具源类型

1. CS 脚本 (CsScript)

{
  "Type": "CsScript",
  "Path": "tools/*.cs",
  "AdditionalUsings": ["System", "System.IO"],
  "References": ["path/to/dependency.dll"],
  "PreprocessorSymbols": ["DEBUG"]
}
字段 说明
Path 脚本路径,支持通配符
AdditionalUsings 额外的 using 命名空间
References 引用的 DLL 路径
PreprocessorSymbols 预处理器符号

2. DLL 程序集 (Dll)

{
  "Type": "Dll",
  "Path": "path/to/tools.dll",
  "DependencySearchPaths": ["./lib"],
  "UseIsolatedContext": true
}
字段 说明
Path DLL 路径,支持通配符
DependencySearchPaths 依赖搜索路径
UseIsolatedContext 是否使用隔离上下文加载

3. CSProj 项目 (Csproj)

{
  "Type": "Csproj",
  "Path": "path/to/project.csproj",
  "BuildConfiguration": "Release",
  "TargetFramework": "net10.0",
  "RestoreNuGetPackages": true
}
字段 说明
Path CSProj 文件路径
BuildConfiguration 编译配置(Debug/Release)
TargetFramework 目标框架
RestoreNuGetPackages 是否还原 NuGet 包

4. HTTP 后端 (Backend - HTTP)

{
  "Type": "Backend",
  "BackendTransportType": "Http",
  "Url": "http://localhost:5000/mcp",
  "ApiKey": "your-api-key",
  "McpEndpoint": "/mcp",
  "TransportMode": "Auto",
  "ToolPrefix": "remote_"
}

5. Stdio 后端 (Backend - Stdio)

{
  "Type": "Backend",
  "BackendTransportType": "Stdio",
  "Name": "local_stdio_server",
  "StdioCommand": "dotnet",
  "StdioArguments": "path/to/server.dll",
  "StdioWorkingDirectory": "./",
  "StdioStartupTimeoutMs": 10000,
  "ToolPrefix": "stdio_"
}

工具开发规范

基本规则

规则 说明
必须标记类 使用 [McpServerToolType] 特性标记工具类
必须标记方法 使用 [McpServerTool] 特性标记工具方法
添加描述 使用 [Description("...")] 为工具和参数添加描述
返回类型 方法返回 Task<string> 或 string,返回 JSON 格式字符串
命名规范 方法名使用 PascalCase,自动转换为 snake_case 工具名

示例工具

using System.ComponentModel;
using ModelContextProtocol.Server;
using System.Text.Json;

[McpServerToolType]
public class MyTools
{
    private readonly IMyService _service;
    private readonly ILogger<MyTools> _logger;

    // 构造函数注入
    public MyTools(IMyService service, ILogger<MyTools> logger)
    {
        _service = service;
        _logger = logger;
    }

    [McpServerTool]
    [Description("获取数据。参数 id:数据标识。返回数据内容。")]
    public async Task<string> GetData(
        [Description("数据标识")] string id)
    {
        _logger.LogInformation("GetData called with id: {Id}", id);
        var data = await _service.GetDataAsync(id);
        return JsonSerializer.Serialize(new { id, data });
    }
}

服务注册

方式 1:配置文件

{
  "McpLinker": {
    "Sources": [...],
    "ServiceRegistrations": [
      {
        "ServiceType": "IMyService, MyAssembly",
        "ImplementationType": "MyService, MyAssembly",
        "Lifetime": "Singleton"
      }
    ]
  }
}

方式 2:命令行

mcplinker serve \
  --script tools/*.cs \
  --service "MyService,MyDll:Singleton"

Claude Desktop 配置

Stdio 模式

{
  "mcpServers": {
    "my-server": {
      "command": "mcplinker",
      "args": ["serve", "--config", "/path/to/mcplinker.json"]
    }
  }
}

SSE 模式

{
  "mcpServers": {
    "my-server": {
      "url": "http://127.0.0.1:5000/sse"
    }
  }
}

相关文档

许可证

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
2.0.1 78 10/12/2026
2.0.0 80 10/12/2026
1.1.0 70 10/12/2026
1.0.9 155 4/19/2026
1.0.8 137 4/5/2026