OpenCode is a powerful AI coding agent built for the terminal by SST.
Edit the configuration file located at:
- Global:
~/.config/opencode/opencode.json - Project:
opencode.jsonin your project root
Add the server to the mcp object in your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"smart-coding-mcp": {
"type": "local",
"command": ["npx", "-y", "smart-coding-mcp", "--workspace", "/absolute/path/to/your/project"],
"enabled": true
}
}
}{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"smart-coding-mcp": {
"type": "local",
"command": ["npx", "-y", "smart-coding-mcp", "--workspace", "/path/to/project"],
"environment": {
"SMART_CODING_VERBOSE": "true",
"SMART_CODING_MAX_RESULTS": "10"
},
"enabled": true
}
}
}Note: OpenCode does NOT support
${workspaceFolder}. You must use absolute paths.
OpenCode uses AGENTS.md files for custom instructions, similar to CLAUDE.md or Cursor's rules.
| Scope | Location |
|---|---|
| Global | ~/.config/opencode/AGENTS.md |
| Project | AGENTS.md in project root |
-
Create an
AGENTS.mdfile in your project root:# Smart Coding MCP Usage Rules You must prioritize using the **Smart Coding MCP** tools for the following tasks. ## 1. Dependency Management **Trigger:** When checking, adding, or updating package versions (npm, python, go, rust, etc.). **Action:** - **MUST** use the `d_check_last_version` tool. - **DO NOT** guess versions or trust internal training data. - **DO NOT** use generic web search unless `d_check_last_version` fails. ## 2. Codebase Research **Trigger:** When asking about "how" something works, finding logic, or understanding architecture. **Action:** - **MUST** use `a_semantic_search` as the FIRST tool for any codebase research - **DO NOT** use `Glob` or `Grep` for exploratory searches - Use `Grep` ONLY for exact literal string matching (e.g., finding a specific error message) - Use `Glob` ONLY when you already know the exact filename pattern ## 3. Environment & Status **Trigger:** When starting a session or debugging the environment. **Action:** - Use `e_set_workspace` if the current workspace path is incorrect. - Use `f_get_status` to verify the MCP server is healthy and indexed.
You can reference external instruction files using glob patterns:
{
"$schema": "https://opencode.ai/config.json",
"instructions": [
"AGENTS.md",
"docs/guidelines.md",
".cursor/rules/*.md"
],
"mcp": {
"smart-coding-mcp": {
"type": "local",
"command": ["npx", "-y", "smart-coding-mcp", "--workspace", "/path/to/project"],
"enabled": true
}
}
}For rules that apply to all projects, edit ~/.config/opencode/AGENTS.md:
# Global Agent Rules
- Always verify package versions before installing using `d_check_last_version`
- Prefer semantic search (`a_semantic_search`) when available
- Check MCP server status with `f_get_status` at session startOpenCode provides CLI commands for managing MCP servers:
# List all configured MCP servers
opencode mcp list
# Authenticate with a server (if required)
opencode mcp auth smart-coding-mcp
# Remove credentials
opencode mcp logout smart-coding-mcp- Start OpenCode in your project directory.
- Run
opencode mcp listto verify the server is connected. - Ask the AI: "Check the status of the smart coding MCP server" - it should use
f_get_status.