Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 10 of 30
❮Prev Next❯

Agent Mode, MCP Servers and Sub-Agents

Module 2: Copilot Features ⏱ 12 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    Agent mode lets Copilot take a whole task: it plans, finds and edits files, runs terminal commands after you approve them, reads the output and iterates until the task is done. Copilot Edits (Edit mode) only changes the files you choose. MCP (Model Context Protocol) servers give the agent extra tools, such as the GitHub MCP server at https://api.githubcopilot.com/mcp/, configured in .vscode/mcp.json and allowed or blocked by an organization's MCP policy. Agent sessions keep separate pieces of work apart, and a sub-agent does a side task in its own context and returns only a summary, so the main conversation's context window stays focused.

    Simulate it » No Azure account needed

    Exam objective: 2.3.1 Use Agent Mode, Copilot Edits, and MCP for enhanced development and workflows; manage Agent Sessions and delegate tasks to Sub-Agents for optimized context usage. (Skills measured as of August 7, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    VS Code & GitHub: Agent mode with tools and an MCP server Run a task in agent mode, approve a command and add an MCP server.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading…

    Switch the chat to <strong>Agent</strong>. Describe the outcome, not the steps.

    👆 Click the glowing item on screen to continue

    Read the steps as text
    1. Switch the chat to Agent. Describe the outcome, not the steps.
    2. Agent mode plans, edits files and wants to run a command. It asks first; you can allow once, for the session, or skip.
    3. It reads the test output and iterates until the task passes. Keep or Undo the changes, and review the diffs either way.
    4. MCP servers add tools. In VS Code, list them in .vscode/mcp.json (shared with the repo) or your user settings. This one is the GitHub MCP server for issues, pull requests and Actions.
    5. The agent calls an MCP tool, after asking. For long tasks, separate sessions and sub-agents keep each piece of work in its own context, so the main conversation stays focused.

    🧪 Simulation for learning. Screens are simplified versions of Visual Studio Code and github.com with GitHub Copilot; names, files and suggestions are examples. Not affiliated with GitHub or Microsoft, and nothing here touches your real account.

    😟 THE PROBLEM

    Copilot can’t see your issues, and big tasks fill up the context.

    😊 THE SOLUTION

    Give agent mode tools with MCP and split work with sessions and sub-agents.

    • No access to issues or docs✓ An MCP server
    • Context window fills up✓ Sub-agents with their own context
    • Long task blocks your editor✓ Delegate to the coding agent
    🛠️ Solved with: Agent mode + MCP

    Start with a question

    If you hire a contractor to redo your kitchen, do you want them to just give advice, or plan the job, fetch tools, ask before cutting into a wall, and keep going until it's done?

    For a full kitchen, you want the second one. But you also want them to check with you before anything loud, and you don’t want them rifling through every room of the house to figure out where the fuse box is.

    That’s agent mode. Copilot plans the job, edits files and asks before running commands. MCP servers are the extra tools in its van: a GitHub tool for issues, a browser, a docs search. And a sub-agent is the apprentice sent to find the fuse box, who comes back with one sentence (“it’s under the stairs”) instead of a tour of the house.

    Explain it like I’m 10

    Visual: agent mode in motion

    Watch one request go through plan, edit, an approved test run, a failure, a fix, an MCP tool call and a sub-agent.

    ▶ Explainer video See it in motion 8 steps · 1 min 54 sec

    An animation of GitHub Copilot agent mode in VS Code. A developer asks for a FREE discount code with tests. The agent searches the codebase, edits src/discount.js and creates a test file, then asks before running npm test. One test fails, so it fixes the code and runs the tests again until all pass. It asks before calling the list_issues tool on the GitHub MCP server, sends a research question to a sub-agent that works in its own context and returns a short summary, and finishes with diffs the developer can keep or undo.
    Read the video script
    1. Ask for the outcomeSwitch the chat to agent mode and ask for the result you want: a FREE code that gives a hundred percent off, totals that never go below zero, and tests.
    2. It plans and finds the filesFirst it plans. It searches the codebase for discount code and works out which files matter. You didn't have to list them, which is the big difference from edit mode.
    3. It edits, and you see each diffNext it edits. It changes discount dot js, creates a test file, and only reads cart dot js. Every change shows up as a diff you can review.
    4. It asks before it runs a commandNow it wants to run npm test. It asks first. You can allow it once, allow it for the rest of the session, or skip it. Here we allow it once, and one test fails.
    5. It reads the failure and iteratesThis is the loop. The agent reads the failing test, fixes the code, and runs the tests again. Now all five pass. Edit mode can't do this part: it never runs anything.
    6. MCP gives it new toolsTo check related bugs, it calls a tool from the GitHub MCP server, set up in dot vscode slash mcp dot json. Again it asks first. You allow it, and the open issues come back.
    7. A sub-agent keeps context leanOne more question: where else is the discount applied? A sub-agent goes off and reads the files in its own context. Its meter fills up, but the main one barely moves, because only a one-line summary comes back.
    8. You keep or undoFinally it reports back. You read the diffs, then keep or undo them. The agent did the legwork, but every command, every tool call and every change went past you.

    The technical explanation

    Agent mode vs Copilot Edits

    Both live in the Chat view’s mode picker in VS Code.

    Edit mode (Copilot Edits)Agent mode
    Which filesThe ones you add to the working setFinds them itself
    Runs commandsNoYes, after you approve
    Reads errors and testsNoYes, and iterates
    Uses tools / MCPNoYes
    You reviewEach diff: Keep or UndoEach diff, each command, each tool call

    Ask agent mode for an outcome, not steps: “Add a FREE code that gives 100% off, make sure totals never go negative, and add tests.” It searches for discount, edits src/discount.js, creates tests/discount.test.js, then asks:

    ⌨️ Run in terminal: npm test
       [Allow]  [Allow for this session]  [Skip]

    If a test fails it reads the assertion, fixes the code and runs the tests again. When it’s done you get a summary and the diffs to Keep or Undo. “Allow for this session” saves clicks but means it won’t ask again for that command, so use it in repos you know.

    MCP servers add tools

    The Model Context Protocol is an open standard for connecting AI apps to tools and data. An MCP server exposes tools (functions the agent can call) and sometimes resources. In VS Code you list servers in .vscode/mcp.json, which you can commit so the whole team gets the same setup:

    {
      "servers": {
        "github": {
          "type": "http",
          "url": "https://api.githubcopilot.com/mcp/"
        }
      }
    }

    That’s the GitHub MCP server: tools for issues, pull requests, Actions and more. Ask “Which open issues are labelled bug?” and the agent calls list_issues, after asking you. Other servers can run locally ("type": "stdio" with a command) for a browser, a database or your own API. In Copilot CLI, /mcp lists and adds servers and they’re saved in ~/.copilot/mcp-config.json; the GitHub MCP server is built in.

    Two controls matter. You can switch individual tools on or off in the tools picker, and an organization with Copilot Business or Enterprise has an MCP servers in Copilot policy that allows or blocks MCP for its members. If the policy blocks it, no mcp.json file will bring it back.

    1. 1 Ask

      You ask about open bugs.

    2. 2 Choose

      The agent picks the github server's list_issues tool.

    3. 3 Approve

      You allow the call (once or for the session).

    4. 4 Call

      The MCP server queries GitHub and returns the issues.

    5. 5 Answer

      The agent uses the result in its reply or next step.

    An MCP tool call from agent mode

    Sessions and sub-agents: managing context

    Every file the agent reads, every command output and every turn of chat goes into its context window. Long tasks fill it, and a crowded window means slower, vaguer answers.

    • Agent sessions keep separate pieces of work apart. Start a new session for a new task instead of piling everything into one, and you can come back to an earlier session later. In the CLI that’s /session, /resume and --continue.
    • A sub-agent runs a side task in its own context: “find every place we log user emails” or “research how the report module is used”. It reads what it needs and returns a summary, and only that summary enters the main conversation.
    • Delegating a whole task to Copilot coding agent (/delegate in the CLI, or assigning an issue on github.com) moves the work off your machine entirely; it comes back as a draft pull request.
    Architect level Custom agents, tools lists and trust

    A custom agent (.github/agents/<name>.agent.md in a repo, or ~/.copilot/agents/ for your own CLI agents) is a named persona with its own instructions and a tools list. A “test-writer” agent that can only read and edit files, with no shell access, is a neat way to limit what an agent can do. MCP servers run with whatever access you give them, so treat third-party servers like any dependency: check who publishes them, prefer OAuth over tokens pasted into config, and keep secrets out of a committed mcp.json (VS Code supports input variables for that). Tool approvals stay on by default for a reason.

    Real-world business scenario

    Online retail

    Contoso (fictional)

    The problem
    Contoso's developers copied issue details from github.com into chat by hand, and long agent conversations that mixed research with coding kept running out of context and giving muddled answers.
    What they used
    A committed .vscode/mcp.json with the GitHub MCP server, the organization's MCP policy enabled for the shop team, agent mode for implementation with command approvals left on, and sub-agents for research tasks.
    Why that choice
    The agent reads issues itself through MCP, every tool call and command is approved by a person, and research stays out of the main context.
    The result
    Bug fixes started from the real issue text, and agent sessions stayed on task long enough to finish with passing tests.

    When to use it and when not to

    ✓ Use it when…

    • Agent mode for tasks that need searching, multi-file edits, running tests and a few rounds of fixing.
    • Copilot Edits when you know the files and want no commands run.
    • MCP servers when the agent needs data or actions outside your repo, such as issues or docs.
    • Sub-agents or new sessions to keep research and side tasks out of the main context.

    ✕ Think twice when…

    • Approving every command for the session in an unfamiliar repository.
    • Adding MCP servers from unknown publishers, or committing tokens in mcp.json.
    • Merging agent changes without reading the diffs and running the tests yourself.

    ↔ Alternatives to consider

    • Copilot coding agent to work on an issue in the background and open a draft pull request.
    • Copilot CLI for the same agent loop in the terminal, scriptable with copilot -p.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the GH-300 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    You want GitHub Copilot in Visual Studio Code to query issues in your GitHub repositories by using the GitHub MCP server. The configuration must be shared with everyone who opens the workspace. What should you do?

    Question 2

    Question 2 of 5

    A developer needs Copilot to update three specific files that the developer selects and to show each change for review. Copilot must not run any terminal commands. Which feature should the developer use?

    Question 3

    Question 3 of 5

    An agent mode conversation has read many files while researching how logging is implemented, and answers about the main task are becoming less accurate. You want the research to be done without adding all of the files it reads to the main conversation. What should you use?

    Question 4

    Question 4 of 5 · Select 2

    Developers in an organization that uses Copilot Business report that MCP tools are unavailable in Copilot, even though .vscode/mcp.json is configured correctly. Which TWO actions should you check? Each correct answer presents part of the solution.

    Question 5

    Question 5 of 5

    In agent mode, Copilot proposes running npm test to verify its changes. What happens before the command runs?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What does agent mode do that Ask mode doesn't?

    Model answer

    Ask answers. Agent acts: it searches the codebase, edits files, asks to run commands like npm test, reads the results and keeps fixing until the task passes. I still review the diffs and decide what to keep.

    Intermediate How do you give agent mode access to your GitHub issues?

    Model answer

    Add the GitHub MCP server. In VS Code that's a .vscode/mcp.json file with a servers entry pointing at https://api.githubcopilot.com/mcp/. Then the agent can call tools like list_issues, and it asks me before each tool call unless I've approved it.

    Interviewer follows up

    And if the tool never shows up?

    You

    Check that the server started, that my organization's MCP servers in Copilot policy allows MCP, and that the tool is enabled in the tools picker.

    Experienced developer Why would you use a sub-agent rather than just asking the main agent?

    Model answer

    Context. If the main agent reads twenty files to research how logging works, all of that sits in its context window and crowds out the actual task. A sub-agent does the research in its own context and hands back a short summary, so the main thread stays lean and focused.

    Architecture & design How would you let a team use MCP servers safely across many repositories?

    Model answer

    Set the organization's MCP policy deliberately, keep approved servers in a checked-in .vscode/mcp.json so everyone uses the same ones, prefer remote servers with OAuth over tokens pasted into config, and leave tool approvals on so a person sees each call. Anything that writes, like creating issues, deserves an extra look.

    Quick revision

    Key points

    • Agent mode plans, edits files, runs terminal commands after approval and iterates until done.
    • Copilot Edits (Edit mode) changes only the files you add and shows diffs to Keep or Undo.
    • MCP servers add tools. VS Code reads .vscode/mcp.json with a "servers" object; the CLI uses /mcp and ~/.copilot/mcp-config.json.
    • The GitHub MCP server's remote URL is https://api.githubcopilot.com/mcp/.
    • Organizations control MCP with the "MCP servers in Copilot" policy.
    • Agent sessions keep work separate; sub-agents run side tasks in their own context and return a summary.
    • You can approve a command once or for the session; review every diff either way.

    Important terminology

    Agent mode
    A Copilot Chat mode where Copilot plans a task, edits files, runs commands after approval and iterates on the results.
    Copilot Edits
    Edit mode, which applies changes to a working set of files you choose and lets you Keep or Undo each diff.
    Model Context Protocol (MCP)
    An open standard that lets AI apps connect to servers offering tools and data, such as GitHub, a browser or a docs search.
    GitHub MCP server
    GitHub's MCP server for issues, pull requests, Actions and more. Remote URL https://api.githubcopilot.com/mcp/.
    Agent session
    One piece of agent work with its own history and context, kept separate from other sessions.
    Sub-agent
    A helper agent that runs a side task in its own context window and returns a summary to the main agent.

    Common mistakes

    • Thinking Edit mode runs tests. Only Agent mode runs commands.
    • Putting a personal access token in a shared mcp.json.
    • Letting one agent conversation do research and implementation until the context window overflows.

    Exam tips

    • "Connect Copilot to an external tool or data source" = MCP server.
    • "Multi-file change you review, no commands" = Copilot Edits.
    • "Do a side task without filling the main context" = sub-agent.

    Five quick revision questions

    1. 1.Which file configures MCP servers for a VS Code workspace?Show

      .vscode/mcp.json

    2. 2.Which top-level key holds the servers in that file?Show

      "servers"

    3. 3.What is the GitHub MCP server's remote URL?Show

      https://api.githubcopilot.com/mcp/

    4. 4.Which chat mode can run npm test?Show

      Agent mode

    5. 5.What does a sub-agent return to the main agent?Show

      A summary of its result, not its whole context.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Custom Instructions and Prompt Files

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.