Skip to content

feat(config): add mcp_inherit flag to control global MCP inheritance#28900

Open
herjarsa wants to merge 9 commits into
anomalyco:devfrom
herjarsa:feat/mcp-inherit
Open

feat(config): add mcp_inherit flag to control global MCP inheritance#28900
herjarsa wants to merge 9 commits into
anomalyco:devfrom
herjarsa:feat/mcp-inherit

Conversation

@herjarsa
Copy link
Copy Markdown

Issue for this PR

Improves MCP server management workflow — no related issue.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a mcp_inherit config field (defaults to true) that lets projects opt out of inheriting global MCP servers. Currently every project inherits all globally configured MCPs, and disabling them per-server is tedious. This field gives a clean escape hatch.

When mcp_inherit: false is set in project-level opencode.jsonc, the config layer skips merging global MCP entries — only servers defined locally (project or .opencode/) survive. The existing behavior is unchanged when the field is omitted.

Also adds mcp_provenance derived state (like plugin_origins) so the CLI and UI can show where each server came from. The opencode mcp list command now displays (global) or (local) tags.

How did you verify your code works?

  • Verified with lsp_diagnostics on both modified files — zero errors
  • TypeScript compilation passes from the package directory

Screenshots / recordings

N/A — config layer change, no UI.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

herjarsa and others added 9 commits April 25, 2026 15:07
- Checkpoint WAL before closing to prevent corruption on crash
- Wrap PRAGMA journal_mode=WAL in try-catch with fallback to DELETE mode
- Fixes crash on open when WAL is in inconsistent state from previous crash
- Add SIGTERM handler in exit.tsx alongside existing SIGHUP handler
- Add SIGTERM handler in thread.ts to gracefully stop worker
- Add Effect.ensuring to abort AbortController in prompt.ts execRead
- Replace unbounded Map with LRU cache in instance.ts (max 20 entries)

Fixes anomalyco#15348

This addresses the critical issue where:
1. Processes spawned by opencode on Linux become orphaned when terminal closes
2. AbortController instances accumulate in session prompts causing heap growth
3. Instance cache grows without bound holding references to contexts

Closes anomalyco#15348
Apply LRU cache and cleanup logic from PRs anomalyco#9141 and anomalyco#16346:
- Add createLruCache utility with maxEntries: 20
- Replace unbounded Map in instance.ts with LRU cache
- Clear LSP diagnostics maps and file entries on shutdown
- Clean up LSP clients/broken/spawning on teardown

Fixes: anomalyco#12513 (200% CPU + 92.5GB memory on empty session)
fix(storage): add WAL checkpoint on close and fallback for corrupted WAL
fix(memory): prevent unbounded cache growth causing 92GB leak (closes anomalyco#12513)
…t_id not in stream

When filterCompacted encounters a compaction part with tail_start_id pointing
to a message older than available history, it previously included ALL messages
in the result, causing context to inflate to 1.7M tokens instead of ~161k.

This fix:
1. Tracks all messages in an 'all' array during iteration
2. When retain is set but not found, returns only the recent messages after
   retain was encountered (all.slice(-result.length)), not everything
3. Adds safety check in compaction.ts to skip overflow mode when selected.head
   is empty (which indicates tail_start_id is not in available history)

Fixes anomalyco#24249
fix(session): prevent context inflation to 1.7M tokens when tail_start_id not in stream
Adds a mcp_inherit config field (defaults to true) that lets projects
opt out of inheriting global MCP servers. When set to false, only MCP
servers defined in project/local config are loaded.

Also tracks mcp_provenance (derived state) to show origin scope in
the CLI: 'opencode mcp list' now displays (global) or (local) tags.

This solves the workflow of having many MCPs globally available
without needing to manually disable them per project.
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.

1 participant