Enhancing OpenCode with Real-Time Documentation š
If you are using OpenCode, you've likely realized that even the most advanced AI models have a "knowledge cutoff." They often suggest deprecated libraries or outdated syntax. To fix this, we use the Model Context Protocol (MCP) with Context7āa bridge that brings the latest documentation directly into your AI's context.
On macOS, setting this up can be tricky because configuration files are hidden. Here is how I solved it using two different methods.
Method 1: The Interactive CLI (Quickest)
OpenCode provides a built-in helper to guide you. This is the best approach if you want the tool to handle the folder creation for you.
- Open your Terminal.
- Run:
opencode mcp add - Fill in the prompts:
- Name:
context7 - Command:
npx - Arguments:
-y @upstash/context7-mcp@latest --api-key YOUR_API_KEY
- Name:
Method 2: Manual JSON Configuration (The "Pro" Way)
Sometimes the CLI doesn't create the global directory automatically. If opencode mcp list returns nothing, you need to go manual.
- Locate the Hidden Config: OpenCode looks for a global config at
~/.config/opencode/opencode.json. - Create the Folder: Use
mkdir -p ~/.config/opencodein your terminal. - Edit the File: Use a text editor like Nano to create the configuration:
nano ~/.config/opencode/opencode.json- Paste the Configuration:
{
"mcp": {
"context7": {
"type": "local",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"enabled": true
}
}
}Why Choose "Local" over "Remote"?
In both methods, we set the type to local. This runs the MCP server directly on your Mac using stdio (Standard Input/Output). It's faster, more secure, and allows the AI to "talk" to the server without needing to host a separate web service.
Verification
Once you've saved your settings, verify the connection with: opencode mcp list
You should see a green checkmark next to context7. Your AI now has access to the most up-to-date tech stack info on the web!