MCP Server in Practice
Give OpenCode real-world reach by connecting an MCP (Model Context Protocol) server — query a database, drive a browser, or call an external API directly from the agent.
When to use this recipe
- You want the agent to act on live data (DB, browser, API) instead of pasted text.
- You’re building an automation that spans multiple tools.
- You need the agent to read, then decide, then act.
Prerequisites
- OpenCode installed.
- A target MCP server (for example Playwright for browser control, or a Postgres MCP for queries).
Steps
-
Add the MCP server config
Register the server in your OpenCode config.
{ "mcp": { "playwright": { "type": "local", "command": ["npx", "@playwright/mcp@latest"] } } } -
Confirm the tools loaded
Start OpenCode and ask it to list available tools — you should see the server’s tools (e.g.
browser_navigate,browser_click). -
Define the task with a goal
Open the staging site, log in with the test account, navigate to Settings, and tell me whether the new toggle is visible.
-
Supervise the tool calls
Watch each tool call. Approve sensitive actions (writes, deletes) and reject anything unexpected.
-
Iterate on results
If the agent misreads the page, point it at the right selector or ask it to dump the DOM first.
Key prompt
Using the playwright MCP server, open [URL], perform the login flow, then check whether the “Export data” button is present in Settings. Report what you see at each step.
Common pitfalls
- Over-permissioned servers: Grant the minimum tools the task needs; remove destructive tools when not in use.
- Flaky selectors: UI automation breaks when markup changes — instruct the agent to verify state after each action.
- Long tool chains: Ask for one logical step at a time so you stay in control of a multi-tool workflow.
Related recipes
- browser-automation —
reason.mcp.to-browser - custom-skill —
reason.mcp.to-skill - project-scaffold —
reason.mcp.to-scaffold
Related docs
Next up
- browser-automation —
next.mcp.to-browser