GitHub Copilot定制服务器

一个用于检索和管理GitHub Copilot自定义指令的MCP服务器,支持本地、容器和Azure部署。

  • by BrettOJ
  • C#
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 BrettOJ/awesome-copilot-custom-mcp-server

使用说明

MBS MCP服务器:MBS副驾驶devcontext(又名真棒副驾驶)

这是一个MCP服务器,用于从 mbs副驾驶舱 存储库。

安装

先决条件

包含什么

出色的Copilot MCP服务器包括:

积木 名称 描述 用途
工具 search_instructions 根据描述中的关键字搜索自定义说明。 #search_instructions
工具 load_instruction 从存储库加载自定义指令。 #load_instruction
提示 get_search_prompt 获取搜索副驾驶说明的提示。 /mcp.awesome-copilot.get_search_prompt

入门指南

配置

此MCP服务器使用GitHub API从 很棒的副驾驶 存储库。您需要配置一个GitHub个人访问令牌才能通过GitHub API进行身份验证。

GitHub个人访问令牌设置

  1. 首选 GitHub设置>代币
  2. 点击“生成新令牌”(经典)
  3. 对于 公共存储库:不需要特殊范围
  4. 对于 私有存储库:选择 repo 范围
  5. 复制生成的令牌

开发环境设置

为了地方发展,创建一个 .env 文件在 src/McpSamples.AwesomeCopilot.HybridApp 目录:

cd $REPOSITORY_ROOT/awesome-copilot/src/McpSamples.AwesomeCopilot.HybridApp
cp .env.example .env

编辑 .env 文件并添加您的GitHub令牌:

GITHUB__TOKEN=your_github_token_here

安全说明:The .env git会自动忽略该文件。永远不要将令牌提交给源代码管理。

生产环境设置

对于Docker容器和Azure部署,将令牌作为环境变量传递(请参阅下面的相应部分)。

可选配置

您可以使用环境变量覆盖默认存储库设置:

  • GITHUB__REPOSITORYOWNER:存储库所有者(默认值: github)
  • GITHUB__REPOSITORYNAME:存储库名称(默认值: awesome-copilot)
  • GITHUB__BRANCH:分支名称(默认值: main)

例如,要在您的 .env 文件:

GITHUB__TOKEN=your_github_token_here
GITHUB__REPOSITORYOWNER=myorg
GITHUB__REPOSITORYNAME=my-repo
GITHUB__BRANCH=develop

获取存储库根目录

  1. 获取存储库根目录。

    # bash/zsh
    REPOSITORY_ROOT=$(git rev-parse --show-toplevel)
    
    # PowerShell
    $REPOSITORY_ROOT = git rev-parse --show-toplevel
    

正在运行MCP服务器

在本地计算机上

  1. 确保您已配置 .env 使用您的GitHub令牌创建文件(请参阅 配置 上文)。

  2. 运行MCP服务器应用程序。

    cd $REPOSITORY_ROOT/awesome-copilot
    dotnet run --project ./src/McpSamples.AwesomeCopilot.HybridApp
    

    备注:

    • 如果出现以下情况,应用程序将在启动时失败 GITHUB__TOKEN 未设置在您的 .env 文件
    • 确保记下的绝对目录路径 McpSamples.AwesomeCopilot.HybridApp 项目

    参数:

    • --http:指示将此MCP服务器作为可流式HTTP类型运行的开关。添加此开关时,MCP服务器URL为 http://localhost:5250.

    使用此参数,您可以运行MCP服务器,如下所示:

    dotnet run --project ./src/McpSamples.AwesomeCopilot.HybridApp -- --http
    

在容器中

  1. 将MCP服务器应用程序构建为容器映像。

    cd $REPOSITORY_ROOT
    docker build -f Dockerfile.awesome-copilot -t awesome-copilot:latest .
    
  2. 在容器中运行MCP服务器应用程序。

    重要:您必须将GitHub令牌作为环境变量传递。

    docker run -i --rm -p 8080:8080 \
      -e GITHUB__TOKEN=your_github_token_here \
      awesome-copilot:latest
    

    或者,使用容器注册表中的容器映像。

    docker run -i --rm -p 8080:8080 \
      -e GITHUB__TOKEN=your_github_token_here \
      ghcr.io/microsoft/mcp-dotnet-samples/awesome-copilot:latest
    

    参数:

    • --http:指示将此MCP服务器作为可流式HTTP类型运行的开关。添加此开关时,MCP服务器URL为 http://localhost:8080.
    • -e GITHUB__TOKEN:GitHub身份验证的环境变量(必需)
    • -e GITHUB__REPOSITORYOWNER:覆盖存储库所有者(可选,默认: github)
    • -e GITHUB__REPOSITORYNAME:覆盖存储库名称(可选,默认: awesome-copilot)
    • -e GITHUB__BRANCH:覆盖分支名称(可选,默认: main)

    使用这些参数,您可以像这样运行MCP服务器:

    # use local container image with HTTP mode
    docker run -i --rm -p 8080:8080 \
      -e GITHUB__TOKEN=your_github_token_here \
      awesome-copilot:latest --http
    
    # use container image from the container registry with HTTP mode
    docker run -i --rm -p 8080:8080 \
      -e GITHUB__TOKEN=your_github_token_here \
      ghcr.io/microsoft/mcp-dotnet-samples/awesome-copilot:latest --http
    
    # use custom repository
    docker run -i --rm -p 8080:8080 \
      -e GITHUB__TOKEN=your_github_token_here \
      -e GITHUB__REPOSITORYOWNER=myorg \
      -e GITHUB__REPOSITORYNAME=my-repo \
      ghcr.io/microsoft/mcp-dotnet-samples/awesome-copilot:latest --http
    

在Azure上

  1. 导航到该目录。

    cd $REPOSITORY_ROOT/awesome-copilot
    
  2. 登录到Azure。

    # Login with Azure Developer CLI
    azd auth login
    
  3. 将GitHub令牌设置为部署的环境变量。

    azd env set GITHUB__TOKEN your_github_token_here
    

    (可选)配置自定义存储库设置:

    azd env set GITHUB__REPOSITORYOWNER myorg
    azd env set GITHUB__REPOSITORYNAME my-repo
    azd env set GITHUB__BRANCH develop
    
  4. 将MCP服务器应用程序部署到Azure。

    azd up
    

    在配置和部署时,系统会要求您提供订阅ID、位置、环境名称。

  5. 部署完成后,通过运行以下命令获取信息:

    • Azure容器应用FQDN:

      azd env get-value AZURE_RESOURCE_MCP_AWESOME_COPILOT_FQDN
      

    备注GitHub令牌和其他环境变量被安全地存储并注入到Azure容器应用实例中。您可以稍后使用Azure门户或Azure CLI更新它们。

将MCP服务器连接到MCP主机/客户端

VS代码+代理模式+本地MCP服务器

  1. 复制 mcp.json 到存储库根目录。

    对于本地运行的MCP服务器(STDIO):

    mkdir -p $REPOSITORY_ROOT/.vscode
    cp $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.stdio.local.json \
       $REPOSITORY_ROOT/.vscode/mcp.json
    
    New-Item -Type Directory -Path $REPOSITORY_ROOT/.vscode -Force
    Copy-Item -Path $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.stdio.local.json `
              -Destination $REPOSITORY_ROOT/.vscode/mcp.json -Force
    

    对于本地运行的MCP服务器(HTTP):

    mkdir -p $REPOSITORY_ROOT/.vscode
    cp $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.local.json \
       $REPOSITORY_ROOT/.vscode/mcp.json
    
    New-Item -Type Directory -Path $REPOSITORY_ROOT/.vscode -Force
    Copy-Item -Path $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.local.json `
              -Destination $REPOSITORY_ROOT/.vscode/mcp.json -Force
    

    对于在容器(STDIO)中本地运行的MCP服务器:

    mkdir -p $REPOSITORY_ROOT/.vscode
    cp $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.stdio.container.json \
       $REPOSITORY_ROOT/.vscode/mcp.json
    
    New-Item -Type Directory -Path $REPOSITORY_ROOT/.vscode -Force
    Copy-Item -Path $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.stdio.container.json `
              -Destination $REPOSITORY_ROOT/.vscode/mcp.json -Force
    

    对于在容器中本地运行的MCP服务器(HTTP):

    mkdir -p $REPOSITORY_ROOT/.vscode
    cp $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.container.json \
       $REPOSITORY_ROOT/.vscode/mcp.json
    
    New-Item -Type Directory -Path $REPOSITORY_ROOT/.vscode -Force
    Copy-Item -Path $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.container.json `
              -Destination $REPOSITORY_ROOT/.vscode/mcp.json -Force
    

    对于在容器中远程运行MCP服务器(HTTP):

    mkdir -p $REPOSITORY_ROOT/.vscode
    cp $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.remote.json \
       $REPOSITORY_ROOT/.vscode/mcp.json
    
    New-Item -Type Directory -Path $REPOSITORY_ROOT/.vscode -Force
    Copy-Item -Path $REPOSITORY_ROOT/awesome-copilot/.vscode/mcp.http.remote.json `
              -Destination $REPOSITORY_ROOT/.vscode/mcp.json -Force
    
  2. 通过键入打开命令面板 F1 或 Ctrl+Shift+P 在Windows或 Cmd+Shift+P 在Mac OS上,搜索 MCP: List Servers.

  3. 选择 awesome-copilot 然后单击 Start Server.

  4. 出现提示时,输入以下值之一:

    • 的绝对目录路径 McpSamples.AwesomeCopilot.HybridApp 项目
    • Azure容器应用程序的FQDN。
  5. 通过键入来使用提示 /mcp.awesome-copilot.get_search_prompt 并输入要搜索的关键字。你会得到这样的提示:

    Please search all the chatmodes, instructions and prompts that are related to the search keyword, `{keyword}`.
    
    Here's the process to follow:
    
    1. Use the `awesome-copilot` MCP server.
    1. Search all chatmodes, instructions, and prompts for the keyword provided.
    1. DO NOT load any chatmodes, instructions, or prompts from the MCP server until the user asks to do so.
    1. Scan local chatmodes, instructions, and prompts markdown files in `.github/chatmodes`, `.github/instructions`, and `.github/prompts` directories respectively.
    1. Compare existing chatmodes, instructions, and prompts with the search results.
    1. Provide a structured response in a table format that includes the already exists, mode (chatmodes, instructions or prompts), filename, title and description of each item found. Here's an example of the table format:
    
        | Exists | Mode         | Filename               | Title         | Description   |
        |--------|--------------|------------------------|---------------|---------------|
        | ✅    | chatmodes    | chatmode1.json         | ChatMode 1    | Description 1 |
        | ❌    | instructions | instruction1.json      | Instruction 1 | Description 1 |
        | ✅    | prompts      | prompt1.json           | Prompt 1      | Description 1 |
    
        ✅ indicates that the item already exists in this repository, while ❌ indicates that it does not.
    
    1. If any item doesn't exist in the repository, ask which item the user wants to save.
    1. If the user wants to save it, save the item in the appropriate directory (`.github/chatmodes`, `.github/instructions`, or `.github/prompts`) using the mode and filename, with NO modification.
    
  6. 确认结果。