Model Context Protocol (MCP) Tips and Best Practices
LocalAbout Model Context Protocol (MCP) Tips and Best Practices
A reference guide for configuring and troubleshooting GitHub MCP servers with Docker and VS Code. It is aimed at developers setting up server access and maintaining a secure configuration.
Key features
- 01Docker-based server setup
- 02VS Code configuration guidance
- 03GitHub token security practices
- 04Connection and authentication troubleshooting
- 05Logging and resource tuning
Use cases
- 01Set up a GitHub MCP server in VS Code
- 02Keep a GitHub token out of version control
- 03Diagnose Docker or authentication failures
MCP support
Provides setup and operational guidance for configuring MCP servers, including the GitHub MCP server; it does not describe an MCP service implementation.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-serverGITHUB_PERSONAL_ACCESS_TOKENSecretLocal servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.
ghcr.io/github/github-mcp-serverstdioTools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEModel Context Protocol (MCP) Tips and Best Practices
What is MCP?
The Model Context Protocol (MCP) is a protocol that enables AI models to communicate with development environments and tools. It allows AI assistants to gather context, execute commands, and make changes to codebases in a structured and secure way. MCP servers act as intermediaries between AI models and development environments, providing a standardized interface for interactions.
Setup Guide
Prerequisites
- Docker installed on your system
- GitHub Personal Access Token (PAT) with appropriate permissions
- VS Code with the necessary extensions
Basic Setup Steps
-
Environment Configuration
- Set up your GitHub token as an environment variable:
export GITHUB_TOKEN=your_token_here
- Set up your GitHub token as an environment variable:
-
Docker Image
- The MCP server runs in a Docker container
- The official image is available at:
ghcr.io/github/github-mcp-server
-
VS Code Settings
- Configure the MCP server in your VS Code settings.json
- Basic configuration example:
{ "mcp": { "servers": { "github": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN=${env:GITHUB_TOKEN}", "ghcr.io/github/github-mcp-server" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_TOKEN" } } } } }
Configuration Tips
Best Practices
-
Token Security
- Never commit your GitHub token to version control
- Use environment variables for sensitive information
- Regularly rotate your PAT for security
-
Docker Configuration
- Use the
--rmflag to automatically remove containers after they stop - Consider using volume mounts for persistent data
- Keep your Docker image updated to the latest version
- Use the
-
VS Code Integration
- Keep your VS Code and extensions updated
- Configure logging levels appropriately
- Use workspace-specific settings when needed
Troubleshooting
Common Issues and Solutions
-
Connection Issues
- Verify Docker is running
- Check if your GitHub token is valid and properly set
- Ensure proper network connectivity to GitHub
-
Authentication Problems
- Verify your PAT has the required scopes
- Check environment variable configuration
- Ensure the token hasn't expired
-
Docker-related Issues
- Clear Docker cache if experiencing image problems
- Check Docker logs for detailed error messages
- Verify Docker has sufficient system resources
-
VS Code Integration Issues
- Reset VS Code settings to default if needed
- Check VS Code's extension logs
- Verify MCP configuration syntax in settings.json
Debugging Tips
- Enable verbose logging in VS Code
- Check Docker container logs
- Verify environment variable availability
- Monitor system resource usage
Advanced Configuration
Custom Server Configuration
- Configure multiple MCP servers
- Set up custom environment variables
- Configure resource limits
Performance Optimization
- Configure caching settings
- Optimize Docker container resources
- Set appropriate timeout values
Additional Resources
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.