Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/copilot.generate-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:

- name: Analyze and generate tests with Copilot
env:
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
GH_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }} # Personal PAT for Copilot API authentication
GITHUB_MCP_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Workflow token for MCP GitHub operations (issues)
run: |
echo "Analyzing commit ${{ github.sha }} for test coverage..."
echo "Source files changed: ${{ steps.changes.outputs.source_count }}"
Expand All @@ -46,10 +47,12 @@ jobs:
PROMPT="${PROMPT//\{REPOSITORY\}/${{ github.repository }}}"

echo "Delegating to GitHub Copilot for test analysis..."
echo "- Copilot will examine the commit diff"
echo "- Copilot will use MCP to examine the commit diff"
echo "- Copilot will check for corresponding test files"
echo "- Copilot will assess if new tests are needed"
echo "- Copilot will create an issue if tests are recommended"
echo "- Copilot will create an issue and assign it to itself if needed"
echo ""

copilot -p "$PROMPT" --enable-all-github-mcp-tools --allow-all-tools --no-ask-user
copilot -p "$PROMPT" \
--mcp-config .github/mcp.json \
--allow-all-tools
148 changes: 148 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,154 @@ az billing invoice list --output table

---

## 🤖 Agentic Workflows with MCP

### What is MCP?

The **Model Context Protocol (MCP)** is a standard protocol that enables AI models like GitHub Copilot to interact with external tools and services. This repository leverages MCP to create autonomous workflows that can manage documentation, tests, and other development tasks.

### MCP in This Repository

This project includes MCP-enabled workflows that autonomously:

- 📖 **Analyze code changes** - Examine commits for documentation or test needs
- ✍️ **Create GitHub issues** - Automatically track required work
- 👤 **Assign tasks** - Delegate to Copilot Coding Agent or team members
- 🏷️ **Manage workflow** - Label, track, and close issues automatically

### Available Agentic Workflows

#### 1. Generate Documentation (`copilot.generate-docs.yml`)

**What it does:**
- Monitors code changes for documentation needs
- Analyzes commit diffs using MCP GitHub integration
- Creates issues when public APIs or complex logic is added
- Assigns documentation tasks to Copilot

**When it runs:**
- Every push to the repository
- Excludes changes to docs and markdown files

**Learn more:** [labs/agentic-ci-workflows/copilot.generate-docs.md](../labs/agentic-ci-workflows/copilot.generate-docs.md)

#### 2. Generate Tests (`copilot.generate-tests.yml`)

**What it does:**
- Identifies code lacking test coverage
- Creates issues for missing or incomplete tests
- Assigns test implementation to Copilot

**When it runs:**
- On push to main and pull requests
- Excludes non-code changes

**Learn more:** [labs/agentic-ci-workflows/copilot.generate-tests.md](../labs/agentic-ci-workflows/copilot.generate-tests.md)

### Local MCP Setup

To use MCP-enabled tools locally with Copilot CLI:

#### Prerequisites

```bash
# Install GitHub CLI with Copilot extension
gh auth login
gh extension install github/gh-copilot

# Or install standalone Copilot CLI
curl -fsSL https://gh.io/copilot-install | bash
```

#### Configuration

The MCP configuration file is already included in the repository:

```bash
# View the configuration
cat .github/mcp.json
```

#### Usage Example

```bash
# Set up authentication tokens
export GH_TOKEN="your_personal_access_token" # Token with 'copilot' scope
export GITHUB_MCP_TOKEN="$GH_TOKEN" # Use same token locally

# Run Copilot with MCP
copilot -p "Analyze the latest commit for documentation needs" \
--mcp-config .github/mcp.json \
--allow-all-tools
```

**Flags explained:**
- `--mcp-config .github/mcp.json` - Path to MCP configuration file (replaces deprecated `--enable-all-github-mcp-tools`)
- `--allow-all-tools` - Allow Copilot to use all available MCP tools

**Note:** The `--enable-all-github-mcp-tools` flag is deprecated. Always use `--mcp-config` with a configuration file instead.

#### What You Can Do with MCP Locally

- **Analyze code changes:** Ask Copilot to review commits and suggest improvements
- **Generate documentation:** Request docs for specific functions or modules
- **Create issues:** Have Copilot create GitHub issues for follow-up work
- **Query repository:** Ask questions about codebase structure and history

#### Example Prompts

```bash
# Analyze a specific commit
copilot -p "Analyze commit abc1234 and determine if documentation is needed" \
--mcp-config .github/mcp.json --allow-all-tools

# Generate documentation for a file
copilot -p "Review src/app.ts and create API documentation" \
--mcp-config .github/mcp.json --allow-all-tools

# Check test coverage
copilot -p "Identify functions in src/utils.ts that lack unit tests" \
--mcp-config .github/mcp.json --allow-all-tools
```

### MCP Token Requirements

When using MCP locally or in CI/CD:

| Environment | Token Source | Required Scopes |
|------------|--------------|-----------------|
| **Local development** | Personal Access Token | `copilot`, `repo` |
| **GitHub Actions** | `COPILOT_CLI_TOKEN` secret + `GITHUB_TOKEN` | `copilot` (PAT), `contents: read`, `issues: write` (workflow) |

### Troubleshooting MCP Locally

**Problem:** `Error: MCP authentication failed`

**Solutions:**
1. Check token is set: `echo $GH_TOKEN`
2. Verify token has correct scopes (Settings → Developer settings → PAT)
3. Ensure `.github/mcp.json` exists and is valid JSON

**Problem:** `Cannot find mcp.json`

**Solutions:**
1. Verify file path: `ls .github/mcp.json`
2. Use absolute path: `--mcp-config /full/path/to/.github/mcp.json`

**Problem:** `Permission denied when creating issues`

**Solutions:**
1. Ensure token has `repo` scope (not just `copilot`)
2. Verify you have write access to the repository

### Learn More

- **MCP Configuration Details:** [github-deployment.md - MCP Configuration](github-deployment.md#mcp-model-context-protocol-configuration)
- **Workflow Setup:** [labs/agentic-ci-workflows/](../labs/agentic-ci-workflows/)
- **Copilot CLI Docs:** [GitHub Copilot CLI Documentation](https://docs.github.com/en/copilot/github-copilot-in-the-cli)

---

**Last Updated:** December 2024

**Version:** 1.0.0
Expand Down
Loading
Loading