DD

daxian-dbw/mcpserverps

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

13 stars 7 forks 质量 59 趋势 28

执行 MCP 服务器作为 PowerShell 模块

概览

该项目创建了PowerShell模块,作为"模型背景协议"(MCP)服务器. 该模块曝光了启动-MyMCP的cmdlet,它开启了MCP服务器并动态地曝光了基于如何被引用的工具. - 小尺寸:5.17 MB。 只需要.NET MCP SDK组件. - 可用性:易于通过PowerShell Gallery跨平台分发和安装。 - 弹性:暴露 C#工具,.ps1脚本工具,或模块函数工具. - 对于一个需要PowerShell特性的MCP服务器来说,运行时间自然是可用的(运行于pwsh.exe),所以不需要运送PowerShell SDK组件. 已出版的模块将在.\out\MCPServerPS提供。 在将模块部署到您 PowerShell 模块路径后, 您可以使用 Start- MyMCP CMDlet启动 MCP 服务器 。 Sart-MyMCP cmdlet支持三个参数集: -(强制的,所有参数集):服务器报告的名称作为其MCP服务器Info.name. 由于MCP客户端(例如.

概述(AI 翻译)

该项目创建了PowerShell模块,作为"模型背景协议"(MCP)服务器. 该模块会暴露出Start-MyMCPcmdlet,它开启了MCP服务器并动态地暴露基于如何被引用的工具.

□ MCP 服务器作为 PowerShell 模块

** 作为PowerShell模块运送MCP服务器的好处:**

  • 小尺寸:5.17 MB。 只需要.NET MCP SDK组件.
  • 可用性:易于通过PowerShell Gallery跨平台分发和安装。
  • 灵活:曝光 C#工具,.ps1脚本工具,或模块函数工具.
  • 对于一个需要PowerShell特性的MCP服务器,运行时间自然是可用的(运行于pwsh.exe),所以不需要运送PowerShell SDK组件.

□ 构建模块

为建设项目,运行:

已出版的单元将在[[T3] 提供。

在将模块部署到您的PowerShell模块路径后,您可以使用 Start-MyMCP cmdlet启动MCP服务器.

□ 启动- MyMCP 模块参数集

Start-MyMCP cmdlet支持三个参数集:

  • ** Name**(强制性,所有参数集):服务器报告的名称作为其MCP serverInfo.name. 由于MCP客户端(例如.

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

MCPServerPS

This project creates a PowerShell module that serves as a Model Context Protocol (MCP) server. The module exposes the Start-MyMCP cmdlet, which starts the MCP server and dynamically exposes tools based on how it is invoked.

MCP server as a PowerShell Module

Benefits of shipping an MCP server as a PowerShell module:

  • Small size: 5.17 MB. Only the .NET MCP SDK assemblies are required.
  • Availability: easy to distribute and install via PowerShell Gallery across platforms.
  • Flexible: expose C# tools, .ps1 script tools, or module function tools.
  • For an MCP server that needs PowerShell features, the runtime is naturally available (runs in pwsh.exe), so no need to ship PowerShell SDK assemblies.

Building the Module

To build the project, run:

dotnet publish .\src\MCPServerPS.csproj

The published module will be available at .\out\MCPServerPS.

After deploying the module to your PowerShell module path, you can start the MCP server using the Start-MyMCP cmdlet.

Start-MyMCP Cmdlet Parameter Sets

The Start-MyMCP cmdlet supports three parameter sets:

Start-MyMCP -Name  []
Start-MyMCP -Name  -ScriptRoot  []
Start-MyMCP -Name  -Module  []
  • Name (mandatory, all parameter sets): the name the server reports as its MCP serverInfo.name. Since MCP clients (e.g. VS Code) prefer this self-reported name over the mcp.json config key for tool grouping/naming, use a distinct -Name per configured instance so multiple instances of this module remain distinguishable.
  • Default: Start-MyMCP -Name exposes all MCP tools defined in the C# code of this assembly.
  • ScriptRoot: Start-MyMCP -Name -ScriptRoot exposes each .ps1 script file in the specified directory as an MCP tool.
  • Module: Start-MyMCP -Name -Module exposes each function within the specified module as an MCP tool.

Examples of script tools and module function tools can be found in the ./scripts folder.

Both script tools and module function tools use comment-based help to define the description and parameters for each tool. This ensures that tool metadata is discoverable and user-friendly.

Runspace Behavior

  • Each script tool runs in its own dedicated Runspace, so they are isolated from each other.
  • Module function tools share the same Runspace for the module, allowing changes to module state made by one function tool to be visible to others. This is because module functions are considered related and may need to share state.

Using MCPServerPS in VSCode

1. Exposing C# MCP Tools

{
    "servers": {
        "MCPServerPS": {
            "type": "stdio",
            "command": "pwsh",
            "args": [
                "-noprofile",
                "-c",
                "MCPServerPS\\Start-MyMCP -Name MCPServerPS"
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →