How to write your own Copilot agent with a .agent.md file and optional MCP server connections.
AuthorNeexoCore
Updated
agentscustomizationintermediate
Overview
Custom agents let you create specialized Copilot personas with specific instructions, tools, and behaviors. This recipe shows you how to create one from scratch.
Steps
1. Create the agent file
Create .github/agents/my-agent.agent.md:
---
name: my-agent
description: "Helps with database migrations and schema design"
tools:
- name: github
- name: postgres
---
You are an expert database engineer. When asked about schema design:
- Always suggest migrations, never direct ALTER TABLE
- Use snake_case for column names
- Add created_at and updated_at to every table
- Prefer UUID over auto-increment for primary keys
Ask: "Design a schema for a blog with posts and comments"
Best Practices
Keep the system prompt focused on one domain
List specific do's and don'ts
Reference MCP servers only when the agent needs external data
Test with real scenarios before sharing
Raw content
Copy this into your project — e.g. .instructions.md, .agent.md, or SKILL.md
## Overview
Custom agents let you create specialized Copilot personas with specific instructions, tools, and behaviors. This recipe shows you how to create one from scratch.
## Steps
### 1. Create the agent file
Create `.github/agents/my-agent.agent.md`:
```markdown
---
name: my-agent
description: "Helps with database migrations and schema design"
tools:
- name: github
- name: postgres
---
You are an expert database engineer. When asked about schema design:
- Always suggest migrations, never direct ALTER TABLE
- Use snake_case for column names
- Add created_at and updated_at to every table
- Prefer UUID over auto-increment for primary keys
```
### 2. Add MCP server connections (optional)
Reference MCP servers in the `tools` frontmatter:
```yaml
tools:
- name: github
- name: postgres
config:
connectionString: "${DATABASE_URL}"
```
### 3. Test the agent
1. Open Copilot Chat in VS Code
2. Type `@my-agent` to invoke it
3. Ask: "Design a schema for a blog with posts and comments"
## Best Practices
- Keep the system prompt focused on one domain
- List specific do's and don'ts
- Reference MCP servers only when the agent needs external data
- Test with real scenarios before sharing