Skip to content

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

  1. Add the MCP server config

    Register the server in your OpenCode config.

    {
      "mcp": {
        "playwright": {
          "type": "local",
          "command": ["npx", "@playwright/mcp@latest"]
        }
      }
    }
  2. 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).

  3. 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.

  4. Supervise the tool calls

    Watch each tool call. Approve sensitive actions (writes, deletes) and reject anything unexpected.

  5. 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.

Next up