Jetson & 머신러닝

gemini 에서 github MCP연결하기

아크리엑터 2025. 7. 26. 14:32
반응형

 

1. github  Access Token 발급

  • https://github.com 접속한다. (당연히, 로그인해야 함)
  • 우측 상단의 내 프로필 아이콘을 선택 --> Settings 선택
  • 좌측 메뉴의 맨 아래에 있는 "Developer settings" --> "Personal access token" --> "tokens (classic)" --> "generate new token" --> "Generate new token (classic) " 선택
  • "Note"에 Token 이름을 지정한다.  "gemini cli"로 입력했다.
  • 토큰의 사용 기간을 선택한다. 주기적으로 연장하도록 한다. 잘 관리할 것 같으면 expired안되게 설정하면 된다.
  • 사용할 권한은 모두 선택하고, 맨 아래의 "generate token"을 선택하여 토큰을 생성한다.
  • 생성된 토큰 값은 복사를 해둔다.  잊어버리면, 동일 메뉴에 접속해서 재생성하면 된다.
  • 토큰은 ghp_W2cajkjkfjksalfjkqekfjfjdfjkdsjlfdsjl. 이런 형태로 만들어진다.

 

2. github MCP 서버를 전역으로 설치한다.

% sudo npm install -g @modelcontextprotocol/server-github
 
npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead
npm warn deprecated @modelcontextprotocol/server-github@2025.4.8: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

added 46 packages in 1s

9 packages are looking for funding
  run `npm fund` for details

 

3. gemini 설정 파일 변경

  • 홈디렉토리에 '.gemini' 폴더가 있을 텐데, 없다면 만들어준다. 그리고, settings.json 파일도 있을텐데, 없으면 만들어준다.
  • ~/.gemini/settings.json 에 아래의 내용이 추가되게 한다.

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "발급된 github 토큰"
      },
      "timeout": 10000,
      "trust": false
    }
  }
}

 

  • 실제 등록한 내용이다. 기존에 다른 것이 있어서, 맨 아래에 추가를 하였다. 추가할 때는 전체를 감싸고 있는 {}에 들어가도록 해야 한다. 그리고, 기존 항목에 ','를 붙여 두어야 한다. 아래 처럼.(아래의 토큰 정보는 사용 만료된 토큰을 넣어두었다)
{
  "selectedAuthType": "oauth-personal",
  "theme": "Default Light",

  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_W4c2mO1SDFgINjWkHxe43CtFElmY9Y2Fd2xj"
      },
      "timeout": 10000,
      "trust": false
    }
  }
}

 

4. 이제 gemini를 실행한다.  실행이 되면, 하나의 MCP 서버를 사용한다는 메시지가 표시되어있다.

Using: 1 MCP server (ctrl+t to view)

 

5. gemini에 아래의 프롬프트를 입력하여, githjub에 등록되어 있는 내 저장소 목록을 가져오게 시험해보았다.


╭──────────────────────────────────────────────╮
│  > github에 내 저장소에 있는 목록을 보여줘.          │
╰──────────────────────────────────────────────╯

✦ 어떤 기준으로 목록을 보여드릴까요? 예를 들어, 생성일, 업데이트일, 이름순으로 정렬할
  수 있고 오름차순, 내림차순으로 정렬할 수 있습니다.

╭────────╮
│  > 예  │
╰────────╯

 ╭────────────────────────────────────────────────────────────────────────────────────╮
 │ ?  search_repositories (github MCP Server) {"query":"user:igi"} ←                  │
 │                                                                                    │
 │   MCP Server: github                                                               │
 │   Tool: search_repositories                                                        │
 │                                                                                    │
 │ Allow execution of MCP tool "search_repositories" from server "github…             │
 │                                                                                    │
 │ ● 1. Yes, allow once                                                               │
 │   2. Yes, always allow tool "search_repositories" from server "github"             │
 │   3. Yes, always allow all tools from server "github"                              │
 │   4. No (esc)                                                                      │
 │                                                                                    │
 ╰────────────────────────────────────────────────────────────────────────────────────╯
 
 
 ╭─────────────────────────────────────────────────────────────────────────────╮
 │ x  search_repositories {"query":"user:igi"}                                 │
 │                                                                             │
 │    MCP error -32603: Validation Error: Validation Failed                    │
 │    Details: {"message":"Validation Failed","errors":[{"message":"The        │
 │    listed users and repositories cannot be searched either because the      │
 │    resources do not exist or you do not have permission to view             │
 │    them.","resource":"Search","field":"q","code":"invalid"}],"documentatio  │
 │    n_url":"https://docs.github.com/v3/search/","status":"422"}              │
 ╰─────────────────────────────────────────────────────────────────────────────╯
✦ Github ID를 알려주시겠어요?

╭────────────╮
│  > xxxxxx  │
╰────────────╯

✦ 다음은 xxxxxx 님의 GitHub 저장소 목록입니다.

   * trashfolder: Trash Folder For Linux/Unix
       * URL: https://github.com/xxxxxx/trashfolder
   * xavier_initial_install:
       * URL: https://github.com/xxxxxxx/xavier_initial_install
   * bot: torrentbot, safeshutdown, etc
       * URL: https://github.com/xxxxxxx/bot
   * wips11:
       * URL: https://github.com/xxxxxx/wips11
   * wips10:
       * URL: https://github.com/xxxxxx/wips10

 

반응형