docs/src/course/02-agent-tools-mcp/14-getting-github-mcp-url.md
To connect your agent to GitHub, we'll use the official GitHub MCP server. GitHub hosts this server remotely at https://api.githubcopilot.com/mcp/, and authentication is done with a GitHub Personal Access Token passed in the request headers.
You'll need a GitHub Personal Access Token (PAT) to authenticate with the server.
Add the token to your .env file:
# Add this to your .env file
GITHUB_PERSONAL_ACCESS_TOKEN=your_github_token
Using an environment variable keeps your token secure and prevents it from being committed to your repository.
:::note
If you prefer to run the GitHub MCP server locally instead of using the hosted endpoint, you can use npx as a stdio transport:
github: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
env: { GITHUB_PERSONAL_ACCESS_TOKEN: process.env.GITHUB_PERSONAL_ACCESS_TOKEN },
}
This does not require access to api.githubcopilot.com and works the same way as the hosted option.
:::