|
| 1 | +## Step 1: Introduction to MCP and environment setup |
| 2 | + |
| 3 | +<img width="150" align="right" alt="copilot logo" src="https://github.com/user-attachments/assets/4d22496d-850b-4785-aafe-11cba03cd5f2" /> |
| 4 | + |
| 5 | +In the [Getting Started with GitHub Copilot](https://github.com/skills/getting-started-with-github-copilot) exercise, we were introduced to the Mergington High School's extracurricular activities website, which allowed students to sign up for events. |
| 6 | + |
| 7 | +And now we have a problem... but.. it's a good one! More teachers are asking to use it! 🎉 |
| 8 | + |
| 9 | +Our fellow teachers have lots of ideas but we can't seem to keep up with all the requests! 😮 To fix this issue, lets give GitHub Copilot an upgrade by enabling Model Context Protocol (MCP). To be more specific, we will add the GitHub MCP server, which will enable a combined workflow of issue management and website upgrades. 🧑🚀 |
| 10 | + |
| 11 | +Let's get started! |
| 12 | + |
| 13 | +### What is Model Context Protocol (MCP)? |
| 14 | + |
| 15 | +[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is often referred to as "USB-C for AI" - a universal connector that allows GitHub Copilot (and other AI tools) to seamlessly interact with other services. |
| 16 | + |
| 17 | +Essentially, it is a way to describe the capabilities and requirements of a service, so AI tools can easily determine what methods to use and to accurately provide the parameters. An MCP server is providing that interface. |
| 18 | + |
| 19 | +```mermaid |
| 20 | +graph LR |
| 21 | + A[Developer] -->|Uses| B[GitHub Copilot] |
| 22 | + B -->|Unified API| MCP[Model Context Protocol] |
| 23 | +
|
| 24 | + MCP <-->|Unique API| C[(GitHub)] |
| 25 | + MCP <-->|Unique API| D[(Slack)] |
| 26 | + MCP <-->|Unique API| E[(Figma)] |
| 27 | +
|
| 28 | + style B fill:#4CAF50,stroke:#333,stroke-width:2px |
| 29 | +
|
| 30 | + subgraph "Less Context Switching, More Coding" |
| 31 | + B |
| 32 | + MCP |
| 33 | + C |
| 34 | + D |
| 35 | + E |
| 36 | +
|
| 37 | + end |
| 38 | +``` |
| 39 | + |
| 40 | +### :keyboard: Activity: Get to know your environment |
| 41 | + |
| 42 | +Before we dive into MCP, let's start up our development environment and refamiliarize ourself with the extracurricular activity application. |
| 43 | + |
| 44 | +1. Right-click the below button to open the **Create Codespace** page in a new tab. Use the default configuration. |
| 45 | + |
| 46 | + [](https://codespaces.new/{{full_repo_name}}?quickstart=1) |
| 47 | + |
| 48 | +1. Validate the **Copilot Chat** and **Python** extensions are installed and enabled. |
| 49 | + |
| 50 | + <img width="300" alt="copilot extension for VS Code" src="https://github.com/user-attachments/assets/ef1ef984-17fc-4b20-a9a6-65a866def468" /><br/> |
| 51 | + <img width="300" alt="python extension for VS Code" src="https://github.com/user-attachments/assets/3040c0f5-1658-47e2-a439-20504a384f77" /> |
| 52 | + |
| 53 | +1. Verify our application runs before modification. In the left sidebar, select the **Run and Debug** tab and then press the **Start Debugging** icon. |
| 54 | + |
| 55 | + <details> |
| 56 | + <summary>📸 Show screenshot</summary><br/> |
| 57 | + |
| 58 | + <img width="300" alt="run and debug" src="https://github.com/user-attachments/assets/50b27f2a-5eab-4827-9343-ab5bce62357e" /> |
| 59 | + |
| 60 | + </details> |
| 61 | + |
| 62 | + <details> |
| 63 | + <summary>🤷 Having trouble?</summary><br/> |
| 64 | + |
| 65 | + If the **Run and Debug** area is empty, try reloading VS Code: Open the command palette (`Ctrl`+`Shift`+`P`) and search for `Developer: Reload Window`. |
| 66 | + |
| 67 | + <img width="300" alt="empty run and debug panel" src="https://github.com/user-attachments/assets/0dbf1407-3a97-401a-a630-f462697082d6" /> |
| 68 | + |
| 69 | + </details> |
| 70 | + |
| 71 | +1. Use the **Ports** tab to find the webpage address, open it, and verify it is running. |
| 72 | + |
| 73 | + <details> |
| 74 | + <summary>📸 Show screenshot</summary><br/> |
| 75 | + |
| 76 | + <img width="350" alt="ports tab" src="https://github.com/user-attachments/assets/8d24d6b5-202d-4109-8174-2f0d1e4d8d44" /> |
| 77 | + |
| 78 | +  |
| 79 | + |
| 80 | + </details> |
| 81 | + |
| 82 | +### :keyboard: Activity: Add the GitHub MCP server |
| 83 | + |
| 84 | +1. Inside your codespace, open the **Copilot Chat** panel and verify **Agent** mode is selected. |
| 85 | + |
| 86 | + <img width="200" alt="image" src="https://github.com/user-attachments/assets/201e08ab-14a0-48bf-824e-ba4f8f43f8ab" /> |
| 87 | + |
| 88 | + <details> |
| 89 | + <summary>Agent mode missing?</summary><br/> |
| 90 | + |
| 91 | + - Verify VS Code is at least `v1.99.0`. |
| 92 | + - Verify the Copilot extension is at least `v1.296.0`. |
| 93 | + - Check if Agent mode is enabled in your [user or workspace settings](https://code.visualstudio.com/docs/configure/settings#_workspace-settings). |
| 94 | + |
| 95 | + <img width="300" alt="image" src="https://github.com/user-attachments/assets/407a79dd-707e-471b-b56b-1938aece4ad8" /> |
| 96 | + |
| 97 | + </details> |
| 98 | + |
| 99 | +1. Inside your codespace, create a new file named `mcp.json` in the `.vscode` directory and paste the following contents: |
| 100 | + |
| 101 | + 📄 **.vscode/mcp.json** |
| 102 | + |
| 103 | + ```json |
| 104 | + { |
| 105 | + "servers": { |
| 106 | + "github": { |
| 107 | + "command": "docker", |
| 108 | + "args": [ |
| 109 | + "run", |
| 110 | + "-i", |
| 111 | + "--rm", |
| 112 | + "-e", |
| 113 | + "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 114 | + "ghcr.io/github/github-mcp-server:v0.1.1" |
| 115 | + ], |
| 116 | + "env": { |
| 117 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}" |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | + "inputs": [ |
| 122 | + { |
| 123 | + "type": "promptString", |
| 124 | + "id": "github_token", |
| 125 | + "description": "GitHub Personal Access Token", |
| 126 | + "password": true |
| 127 | + } |
| 128 | + ] |
| 129 | + } |
| 130 | + ``` |
| 131 | + |
| 132 | + > :placard: **Note:** Entering a hard-coded token is never recommended, you should use input variables or envFiles when an MCP server requires credentials. |
| 133 | +
|
| 134 | +1. Expand the VS Code terminal panel. Run the following command to view and **make a copy** of your codespace's GitHub Token. |
| 135 | + |
| 136 | + ```bash |
| 137 | + echo $GITHUB_TOKEN |
| 138 | + ``` |
| 139 | + |
| 140 | + <details> |
| 141 | + <summary>Why do I need this?</summary><br/> |
| 142 | + |
| 143 | + The MCP server is a separate background process and needs credentials to perform operations. In this case, we use the temporary [codespace authorization](https://docs.github.com/en/enterprise-cloud@latest/codespaces/reference/security-in-github-codespaces#authentication) credential which becomes invalid when the codespace stops. |
| 144 | + |
| 145 | + </details> |
| 146 | + |
| 147 | +1. In the `.vscode/mcp.json` file, click the **Start** button and provide the token. This has just informed GitHub Copilot of the MCP server's capabilities. |
| 148 | + |
| 149 | +  |
| 150 | + |
| 151 | +  |
| 152 | + |
| 153 | +1. In the Copilot side panel, click the **🛠️ Select Tools...** icon to show the additional capabilities. |
| 154 | + |
| 155 | + <img width="250" alt="image" src="https://github.com/user-attachments/assets/95af044c-3f26-4f5c-b933-7630db72eb67" /> |
| 156 | + |
| 157 | + <img width="250" alt="image" src="https://github.com/user-attachments/assets/99178d1b-adbe-4cf4-ab9c-3a4d29918a13" /> |
| 158 | + |
| 159 | +1. **Commit** and **push** the `.vscode/mcp.json` file to the `main` branch. |
| 160 | + |
| 161 | + > 🪧 **Note:** Pushing directly to `main` is not a recommended practice. It is only to simplify this exercise. |
| 162 | +
|
| 163 | +1. Now that your MCP server configuration is pushed to GitHub, Mona should already be busy checking your work. Give her a moment and keep watch in the comments. You will see her respond with progress info and the next lesson. |
| 164 | + |
| 165 | +> [!NOTE] |
| 166 | +> The next steps will involve creating GitHub issues. If you would like to avoid notification emails, you can unwatch the repository. |
| 167 | +
|
| 168 | +<details> |
| 169 | +<summary>Having trouble?</summary><br/> |
| 170 | + |
| 171 | +Make sure: |
| 172 | + |
| 173 | +- Your `.vscode/mcp.json` file is similar to the example provided. |
| 174 | +- You pushed the changes to the `main` branch. |
| 175 | + |
| 176 | +</details> |
0 commit comments