Skip to content

Add OpenCode MCP installer support#54

Merged
mohanagy merged 1 commit intomohanagy:mainfrom
spacethree:opencode
May 5, 2026
Merged

Add OpenCode MCP installer support#54
mohanagy merged 1 commit intomohanagy:mainfrom
spacethree:opencode

Conversation

@jamemackson
Copy link
Copy Markdown
Contributor

@jamemackson jamemackson commented May 4, 2026

Summary

This updates graphify-ts opencode install so OpenCode gets the same MCP-backed graph access as the other first-class assistant integrations.

  • Registers a native OpenCode mcp.graphify local server in opencode.json, alongside the existing AGENTS.md and OpenCode plugin setup.
  • Starts the MCP server with the current Node executable and the resolved installed package CLI path, instead of assuming graphify-ts is on PATH; this supports global installs, linked installs, and project installs through package managers like pnpm.
  • Preserves existing OpenCode config, including unrelated plugins, unrelated MCP servers, and existing graphify.environment values.
  • Removes only graphify-owned OpenCode plugin and MCP config during graphify-ts opencode uninstall.
  • Routes serve --stdio readiness output to stderr so MCP stdout remains JSON-RPC-only.

Testing

  • npm run test:run -- tests/unit/stdio-server.test.ts tests/unit/install.test.ts tests/unit/cli.test.ts
  • npm run test:run
  • npm run typecheck
  • npm run build
  • npm pack --dry-run (if packaging or install behavior changed)

Checklist

  • I updated docs for any user-visible change
  • I added or updated tests when behavior changed
  • I did not commit secrets, private corpora, or accidental generated artifacts
  • I kept this PR focused on a single change or tightly related set of changes

Related issues

None.

Summary by CodeRabbit

  • New Features

    • Added OpenCode MCP server install/uninstall and OpenCode plugin install support (JSONC-aware, preserves existing config formatting).
    • Agent install now accepts an option to resolve a local CLI entrypoint.
    • CLI help text updated to mention OpenCode platform actions.
  • Documentation

    • Quickstart updated to include the OpenCode install command.
  • Tests

    • Expanded coverage for OpenCode install/uninstall flows and stdio server readiness handling.

@jamemackson jamemackson requested a review from mohanagy as a code owner May 4, 2026 21:05
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 795685dd-7596-4481-b24f-e31f9e6dc3c8

📥 Commits

Reviewing files that changed from the base of the PR and between c50c2c1 and c28836f.

📒 Files selected for processing (7)
  • README.md
  • src/cli/main.ts
  • src/infrastructure/install.ts
  • src/runtime/stdio-server.ts
  • tests/unit/cli.test.ts
  • tests/unit/install.test.ts
  • tests/unit/stdio-server.test.ts
✅ Files skipped from review due to trivial changes (4)
  • README.md
  • src/runtime/stdio-server.ts
  • tests/unit/stdio-server.test.ts
  • src/cli/main.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/cli.test.ts
  • src/infrastructure/install.ts

📝 Walkthrough

Walkthrough

Adds OpenCode JSON/JSONC-aware install/uninstall for plugins and MCP graphify servers (resolving package CLI and wiring a local stdio server command), updates CLI help and README to list opencode install, and routes stdio server startup output to stderr.

Changes

OpenCode MCP Server + JSONC Config Handling

Layer / File(s) Summary
Data Shape / Constants
src/infrastructure/install.ts (lines 226–230)
Adds OpenCode constants: config filenames, local plugin path, CLI binary name, and MCP key.
JSONC Parsing Utilities
src/infrastructure/install.ts (lines 301–436)
Implements JSONC tolerant parsing: stripJsonc, removeTrailingCommas, readJsoncObject, and config resolution for opencode.json/opencode.jsonc.
Range-based JSONC Editors
src/infrastructure/install.ts (lines 437–944)
Adds structural range helpers and in-place JSONC edit writers/readers for registering/deregistering plugin and updating/removing mcp.graphify.
Package CLI Resolution
src/infrastructure/install.ts (lines 1088–1123)
Adds resolvePackageCliPath(packageRoot?) to read package.json bin and resolve the CLI entry file.
Core Install/Uninstall Logic
src/infrastructure/install.ts (lines 1357–1452)
Updates OpenCode plugin install/uninstall to target resolved .json/.jsonc and adds MCP server install/uninstall that configures mcp.graphify to run the resolved CLI via process.execPath ... serve --stdio graphify-out/graph.json, preserving environment.
Wiring / Public API
src/infrastructure/install.ts (lines 1652–1687)
Wires OpenCode MCP server changes into agentsInstall/agentsUninstall; agentsInstall gains optional options.packageRoot.
CLI Help Update
src/cli/main.ts (line 348)
Help text changed to “OpenCode plugin/MCP rules”.
StdIO Runtime Output Routing
src/runtime/stdio-server.ts (lines 650–657)
serveGraphStdio emits readiness message to errorOutput (defaults to stderr) with newline instead of using logger.
Docs & Tests
README.md (line 45), tests/unit/cli.test.ts, tests/unit/install.test.ts, tests/unit/stdio-server.test.ts
README lists opencode install; CLI tests expect help and run opencode install; install tests add JSONC support, package fixture, and assert plugin + mcp.graphify behavior (install, idempotency, uninstall, JSON vs JSONC handling); stdio tests capture readiness on errorOutput and assert no console.log usage.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Installer
    participant ConfigFile as OpenCode Config (JSON/JSONC)
    participant PackageJSON as package.json (bin)
    participant MCP as mcp.graphify

    User->>CLI: opencode install
    CLI->>Installer: agentsInstall(platform='opencode', packageRoot?)
    Installer->>ConfigFile: resolveOpencodeConfigPath()
    ConfigFile-->>Installer: config path (.json or .jsonc)
    Installer->>ConfigFile: readOpencodeConfig()
    ConfigFile-->>Installer: parsed config
    Installer->>Installer: resolvePackageCliPath(packageRoot)
    PackageJSON-->>Installer: CLI entrypoint path
    Installer->>ConfigFile: writeOpencodePluginRegistration()
    Installer->>MCP: writeOpencodeMcpServerConfig(command: [process.execPath, cliPath, "serve","--stdio","graphify-out/graph.json"])
    Installer->>ConfigFile: persist changes (JSON or JSONC ranges)
    Installer-->>CLI: "opencode local rules installed"
    CLI-->>User: exit 0
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 With a twitch and a tiny hop,

I stitched JSONC without a stop—
graphify wakes on a stdio shore,
plugins nest where they were before,
stderr hums and the config's top.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add OpenCode MCP installer support' clearly and specifically summarizes the main change: introducing MCP (Message Communication Protocol) installer support for OpenCode.
Description check ✅ Passed The PR description includes all required template sections: a comprehensive Summary explaining the changes, Testing section with completed checklist items, a Checklist section with all items marked complete, and Related issues noted as None.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/infrastructure/install.ts`:
- Around line 843-857: The code reads opencode.jsonc via readOpencodeConfig but
always calls writeJson (which uses JSON.stringify) and thus strips
comments/formatting; change the flow so we only mutate the file when necessary
and preserve JSONC formatting: use the original file text (obtainable via
readOpencodeConfig or by reading resolveOpencodeConfigPath) and apply a
JSONC-aware edit (e.g., jsonc.modify or a writeOpencodeJsonc helper) to insert
OPENCODE_PLUGIN_RELATIVE_PATH into the plugin array; then write the modified
text back (via writeFile) instead of writeJson. Update the branch that currently
calls writeJson (and the similar block around the other mentioned lines) to
perform a JSONC-aware modify-and-write only when plugins were actually changed,
referencing resolveOpencodeConfigPath, readOpencodeConfig,
OPENCODE_PLUGIN_RELATIVE_PATH and replacing writeJson with the JSONC-preserving
write.
- Around line 584-609: resolvePackageCliPath currently trusts package.json#bin
without verifying the target exists; after computing relativeBinPath and before
returning join(packageRoot, relativeBinPath), resolve the full path and validate
it actually exists and is a regular file (and optionally is executable) using
Node fs methods (e.g., existsSync/statSync or accessSync). If the file is
missing or not a file, throw a clear Error referencing CLI_BIN_NAME, the
resolved path, and packageJsonPath so install fails fast instead of persisting a
broken MCP command; keep existing behavior of using findPackageRoot() and
CLI_BIN_NAME to locate entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6047779b-30bf-41a6-8904-665cb3190a0f

📥 Commits

Reviewing files that changed from the base of the PR and between e23309e and c50c2c1.

📒 Files selected for processing (7)
  • README.md
  • src/cli/main.ts
  • src/infrastructure/install.ts
  • src/runtime/stdio-server.ts
  • tests/unit/cli.test.ts
  • tests/unit/install.test.ts
  • tests/unit/stdio-server.test.ts

Comment thread src/infrastructure/install.ts
Comment thread src/infrastructure/install.ts
@jamemackson
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in c28836f:

  • Validate the resolved package CLI bin path before writing OpenCode MCP config, including missing/non-file targets.
  • Preserve existing opencode.jsonc comments/trailing-comma formatting with targeted JSONC edits instead of round-tripping through JSON.stringify.
  • Avoid rewriting opencode.jsonc when the OpenCode plugin is already registered.
  • Added regression coverage for missing CLI bin handling and JSONC install/reinstall/uninstall preservation.

Validation:

  • npm run typecheck
  • npm run test:run -- tests/unit/install.test.ts tests/unit/cli.test.ts tests/unit/stdio-server.test.ts
  • npm run test:run
  • npm run build
  • npm pack --dry-run

@mohanagy
Copy link
Copy Markdown
Owner

mohanagy commented May 5, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mohanagy mohanagy merged commit 8bbfe5e into mohanagy:main May 5, 2026
7 checks passed
@mohanagy mohanagy mentioned this pull request May 5, 2026
5 tasks
mohanagy added a commit that referenced this pull request May 5, 2026
* feat(ci): auto-update contributors list via GitHub Actions

Replace the static README "Credit" handling for contributors with a
self-maintaining list driven by akhilmhdh/contributors-readme-action.

- Add .github/workflows/contributors.yml: runs on push to main,
  weekly cron, and workflow_dispatch; uses contents:write to commit
  the regenerated table back; pinned to v2.3.10.
- Swap the contrib.rocks image in README.md for the
  <!-- readme: contributors -start/-end --> markers the action
  populates with a real HTML table (clickable avatars + usernames).
- Add a one-line shout-out to @jamemackson for #54, the first
  community-contributed feature in graphify-ts.

* chore: release v0.11.0

This release bundles the first community-contributed feature
(OpenCode MCP installer support, #54 by @jamemackson) with the new
auto-updating contributors workflow.

- Bump version to 0.11.0 (minor: new agent integration, backward compatible).
- Add CHANGELOG section for 0.11.0 covering OpenCode installer support
  and the contributors automation, with credit to @jamemackson.

* chore(ci): pin contributors workflow actions to immutable SHAs

Replace mutable tag refs with full 40-character commit SHAs so the
workflow cannot be silently retargeted by upstream tag movement.
Matches the hardening already applied to .github/workflows/pages.yml
(see CHANGELOG entry for v0.10.9).

- actions/checkout@v4 -> @de0fac2e4500dabe0009e67214ff5f5447ce83dd
  (same canonical SHA already used by pages.yml)
- akhilmhdh/contributors-readme-action@v2.3.10 -> @1ff4c56187458b34cd602aee93e897344ce34bfc
  (resolved from the v2.3.10 tag at review time)

Addresses CodeRabbit review comment on PR #55.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants