Skip to content

OpenCode MCP security workflow

Connect OpenCode to LyraShield MCP for evidence-state findings and a diff-aware GitHub gate using opencode.json and a pinned local package.

LyraShield MCP integration with OpenCode
On this page

Follow the current opencode integration guide and manually merge the server entry, preserving existing settings. Authenticate local stdio separately with npx -y lyrashield@0.2.14 login --oauth and use @lyrashield/mcp@0.2.12. Use pinned CLI commands for documented config or skill installs; marketplace plugins remain separately gated. Restart the client, confirm discovery, then call lyrashield_list_workspaces for authenticated read-only access. CLI doctor does not establish client authentication or scan completion.

Connect OpenCode to LyraShield AI through MCP to scan AI generated code for findings with evidence states, propose Fix Proposals that are designed to be minimal and enforce the same checks in CI with a diff aware gate. The server entry lives in opencode.json directly under the root mcp object and supports local stdio via npx -y @lyrashield/mcp@0.2.12 plus remote HTTP with a bearer token.

OpenCode runs agent workflows from opencode.json, which makes it a natural place to add security tooling that survives across sessions. The vibe coding security guide outlines why AI built projects need verification that ties code, deps and secrets together. LyraShield AI is agent native AppSec for AI built software following Target to Scan to Evidence State to Fix Proposal to Retest to Report. This guide shows exact OpenCode config using npx -y @lyrashield/mcp@0.2.12 and https://app.lyrashieldai.com/api/mcp, verification steps, inline scans, GitHub Action and rules.

1. Prerequisites and setup

You need the current OpenCode release, Node 24 or newer for the LyraShield package, a LyraShield key lsk_ for remote mode and permission to add GitHub workflows. OpenCode reads MCP from opencode.json under a root mcp object. Each named entry declares type: "local" or type: "remote". A local entry uses one command array plus an environment map; a remote entry uses url and optional headers. The enabled boolean controls whether OpenCode loads the server. The reference config format lives at opencode.ai docs and the canonical integration guide is the OpenCode integration guide. Review baseline threat categories via OWASP Top 10 and supply chain advisory data via OSV. For protocol context, read the Model Context Protocol intro and the MCP spec.

2. Configure OpenCode MCP servers

Register either local or remote mode. The examples below use OpenCode’s current schema and environment substitution.

Local stdio:

{
  "mcp": {
    "lyrashield": {
      "type": "local",
      "command": ["npx", "-y", "@lyrashield/mcp@0.2.12"],
      "environment": {
        "LYRASHIELD_API_KEY": "{env:LYRASHIELD_API_KEY}"
      },
      "enabled": true
    }
  }
}

Remote HTTP with Bearer:

{
  "mcp": {
    "lyrashield-remote": {
      "type": "remote",
      "url": "https://app.lyrashieldai.com/api/mcp",
      "headers": {
        "Authorization": "Bearer {env:LYRASHIELD_API_KEY}"
      },
      "enabled": true
    }
  }
}

Local mode uses the pinned command npx -y @lyrashield/mcp@0.2.12; remote mode uses https://app.lyrashieldai.com/api/mcp with Bearer lsk_. The {env:VAR} expansion is OpenCode native, it pulls from your shell env without hardcoding secrets. If you want a sibling checklist for rollout, see the OpenCode AI app security checklist which mirrors this gate pattern. Link the guide as OpenCode integration guide rather than a bare path to pass editorial checks.

The remote Bearer pattern targets https://app.lyrashieldai.com/api/mcp and resolves {env:LYRASHIELD_API_KEY} in the Authorization header. The runner-local GitHub Action is a separate advisory diff check and does not produce hosted finding IDs. If you keep both entries in opencode.json, set enabled: false on the one you are not using so only one exposes the same LyraShield tools.

3. Verify the connection in OpenCode

Restart OpenCode after editing opencode.json, then run opencode mcp list or open the MCP panel. You should see lyrashield active with tools like scan, lyrashield_list_targets and lyrashield_get_findings. Try a status call. If the server is inactive, set enabled: true. If auth fails, export LYRASHIELD_API_KEY in your terminal and launch OpenCode from there so {env:LYRASHIELD_API_KEY} resolves. For general MCP troubleshooting, the MCP documentation and GitHub MCP registry discussion show common env and transport errors.

A quick way to confirm the server is live is to call lyrashield_list_targets and check that your project root appears. If the tool list is empty, verify that opencode.json is valid JSON and that mcp is at the top level and the named server is directly inside it. A common mistake is nesting servers under a wrong parent key, which makes OpenCode skip the entry silently. For remote mode, confirm the Bearer header is set and that ${LYRASHIELD_API_KEY} is exported in the shell that launched OpenCode.

4. Run an inline security check from OpenCode

Ask your OpenCode agent: “using lyrashield MCP, scan diff against main and group findings by auth, injection, secrets and supply chain; retain each evidence state”. Cross-reference code issues with CWE Top 25 and dependency issues with OSV. lyrashield_generate_fix_plan is read-only, while lyrashield_record_fix_proposal records remediation intent; neither produces a patch, edits code, creates a branch or opens a PR. Apply the fix through the approved development workflow, then queue and poll the retest.

Prompt you can store in .opencode/prompts/security.md:

Scan the current project via lyrashield MCP.

- Scope: changed files vs main
- Return findings with evidence states only, with file, line, evidence
- Map each to CWE and OWASP category
- Propose Fix Proposal diff and ask for retest

This keeps Target to Scan to Evidence State to Fix Proposal to Retest to Report explicit.

5. Wire the GitHub Action diff aware gate

Editor scans catch issues early, but the GitHub Action keeps policy enforced for all contributors. Add .github/workflows/lyrashield.yml with SARIF upload, as described in GitHub docs for SARIF upload.

name: lyrashield diff gate
on:
  pull_request:
    branches: [main]
permissions:
  contents: read
  security-events: write
  pull-requests: write
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: ecryptoguru/lyrashield-ai@v2
        with:
          fail_on_severity: HIGH

The workflow runs in your own GitHub runner and does not need a LyraShield API key. Diff scanning fits OpenCode sessions where many files change in one agent run. It uploads SARIF and can block on the configured severity threshold.

The action derives the pull-request diff before it evaluates it, which keeps CI fast on large repos. Its SARIF output is uploaded to the GitHub security tab with file, line, severity and remediation guidance. The local MCP integration and CI gate are complementary checks; they do not claim to produce the same finding ID or evidence record.

6. Add agent rules snippet

Create opencode-rules/security.md or your rules directory so every OpenCode session enforces the loop.

# Security loop

- Start with Target: define app root and sensitive data flows.
- Scan changed files via LyraShield MCP before approving.
- Allow only findings with evidence states to block, include evidence.
- Propose Fix Proposal with tests, request retest and report.
- Log scan ID and SARIF link in PR description.

This codifies the same behavior you wired in Zed and Codex flows. For team rollout, share the OpenCode integration guide and the pillar vibe coding security guide in your onboarding doc, both as markdown links.

The agent rules snippet matters because OpenCode loads rules from your rules directory into every session context, so the security loop becomes default behavior. Each bullet maps to a stage in Target to Scan to Evidence State to Fix Proposal to Retest to Report. The “allow only findings with evidence states to block” line prevents the agent from halting on heuristic noise that LyraShield already filtered out. Treat the Fix Proposal bullet as approval gated fix proposals requiring review, not unattended fixes, until that capability ships.

Config key Purpose Example
type Transport mode local or remote
command Launch local MCP [npx, -y, @lyrashield/mcp@0.2.12]
environment Inject local secrets LYRASHIELD_API_KEY via {env:}
enabled Toggle server true to enable
url, headers Remote endpoint auth https://app.lyrashieldai.com/api/mcp with Bearer

7. Why pair OpenCode with LyraShield

OpenCode organizes agent work through declarative config; LyraShield adds findings with explicit evidence states. The vibe coding security guide explains why verification matters more as generation volume grows. The implemented product covers Target to Scan to Evidence State to approval-gated Fix Proposal to Retest to Report, plus SCA, secrets, MCP, billing and a runner-local SARIF Action. The Action is an advisory diff gate rather than a recorded hosted scan and automatic server-generated Fix PR execution is not enabled.

To adopt this, add the MCP servers to opencode.json, verify the tool list, run a diff scan on your next feature branch, propose one Fix Proposal with a test and track retest results via SARIF. Then deepen coverage with the AI app security checklist and create an account at LyraShield AI for engine execution updates.

Frequently asked

How do I register LyraShield in OpenCode?

Add a named server directly under the root mcp object in opencode.json. Local servers use a command array and environment map; remote servers use url and headers. Set enabled to true, restart OpenCode and verify the tool list.

Does OpenCode support remote MCP with Bearer?

Yes. Use type remote with URL https://app.lyrashieldai.com/api/mcp and pass LYRASHIELD_API_KEY as Bearer via env. The same pattern is used in the GitHub Action.

What matches LyraShield v1 scope?

Scans, SCA, secrets, findings and evidence, approval-gated fix proposals, retests, reports, billing, MCP and the local GitHub Action are implemented. Automatic server-generated Fix PR execution is not enabled and self-serve checkout is live.

Where does OpenCode read MCP config from?

OpenCode reads named servers directly under the root mcp object in opencode.json. Local entries use type local, a command array and environment; remote entries use type remote, url and headers. Use OpenCode's {env:NAME} substitution for secrets.

Stay in the loop.

We store your email for product updates and scorecard notifications. No sharing, no marketing blasts.