Skip to Content

How Can GitHub Copilot Prompt Files Supercharge Your Coding Workflow With MCP Integration?

Are GitHub Copilot Prompt Files the Secret to Effortless Automation in VS Code?

GitHub Copilot prompt files are custom Markdown templates designed to automate coding tasks using AI-powered slash commands in Visual Studio Code. These templates enable developers to create personalized commands that interact with both built-in and third-party tools, including those provided by MCP (Machine Control Protocol) servers. Unlike instruction files, which set general behavioral rules for the AI, prompt files let you define specific, reusable actions you can trigger on demand.

Key Features and Purposes

  • Custom Slash Commands: Prompt files let you create unique slash commands (e.g., /websearch) that execute specific tasks within the Copilot chat interface.
  • Tool Integration: They support integration with both native VS Code tools and third-party extensions or MCP servers, vastly expanding automation possibilities.
  • Template Variables: Use variables like ${selection} or ${file} to dynamically reference code, files, or user input, making prompts highly adaptable.
  • Natural Language Support: Prompts are written in Markdown, allowing clear, human-readable instructions that the AI interprets and executes.

Supported Template Variables

Workspace Variables

  • ${workspaceFolder}: Full path to the open workspace.
  • ${workspaceFolderBasename}: Name of the workspace folder only.

Code Selection

${selection} or ${selectedText}: Currently selected code.

File Context

  • ${file}: Full path of the active file.
  • ${fileBasename}: File name with extension.
  • ${fileDirname}: Directory path of the file.
  • ${fileBasenameNoExtension}: File name without extension.

User Input

  • ${input:variableName}: Prompts for user input.
  • ${input:variableName:placeholder}: Prompts for input with a placeholder hint.

Prompt Template Structure

A prompt file is a YAML-formatted Markdown file with two main sections:

Header

  • mode: Defines the chat mode (ask, edit, or agent).
  • tools: Lists the tool commands used (comma-separated).
  • description: Brief summary of the prompt’s purpose (optional).

Body

Contains the main instructions, written in Markdown, using variables and referencing the tools from the header.

Creating and Storing Prompt Files

Creation

Use the command palette in VS Code (Cmd+Shift+P on Mac, Ctrl+Shift+P on Windows) and select “Chat: New Prompt File.”

Storage

  • Workspace-specific: .github/prompts within your project folder.
  • User-wide (Mac): ~/Library/Application Support/Code/User/prompts/
  • User-wide (Windows): %APPDATA%Code\User\prompts\

Naming

Files must follow the format <your_prompt_file_name>.prompt.md.

Execution

Trigger with /your_prompt_file_name in the Copilot chat.

Example: Using an MCP Server With a Prompt File

Suppose you want to search the web for information about selected code using the Tavily MCP server:

Prompt Template Example

---
mode: 'agent'
tools: ['tavily-search']
description: 'Search the web for information about the selected code.'
---
Use Tavily to find info on the web for ${selectedText}

How it works

  1. Select code in the editor.
  2. Type /websearch in Copilot chat.
  3. The AI uses Tavily’s MCP server to search the web and returns relevant information about the selected code.

Benefits and Considerations

  • Flexibility: Integrate any tool or service that supports MCP, making prompt files highly versatile.
  • Non-Deterministic: Results may vary since AI interprets the natural language instructions, so thorough testing is recommended.
  • Community Growth: As the feature matures, expect a growing library of community-created prompt templates and MCP integrations.

GitHub Copilot prompt files enable powerful, customizable automation in VS Code, leveraging both built-in and third-party tools, including MCP servers. By combining natural language instructions, dynamic variables, and tool integrations, developers can streamline repetitive tasks and tailor their coding environment for maximum productivity.