Skip to content

feat(workspace): support mcp configuration from workspace.json#89

Open
feloy wants to merge 4 commits into
openkaiden:mainfrom
feloy:mcp
Open

feat(workspace): support mcp configuration from workspace.json#89
feloy wants to merge 4 commits into
openkaiden:mainfrom
feloy:mcp

Conversation

@feloy

@feloy feloy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
  • Add set_mcp_servers to the Agent trait (default no-op) so any agent can opt in to MCP configuration from .kaiden/workspace.json
  • Implement set_mcp_servers for Claude: command-based servers become stdio entries, URL-based servers become sse entries, both merged into .claude.json under mcpServers
  • Implement set_mcp_servers for OpenCode: command-based servers become local entries (command list = [cmd, ...args], environment map), URL-based servers become remote entries — merged into .config/opencode/config.json under mcp
  • Refactor the opencode sub-modules to use a shared OPENCODE_CONFIG_FILE constant instead of the repeated path literal

Fixes #88

feloy and others added 3 commits June 12, 2026 11:30
Reads the `mcp` block from `.kaiden/workspace.json` and writes MCP
server entries into agent settings during the image build. For Claude,
command-based servers become stdio entries and URL-based servers become
sse entries, both merged into `.claude.json` under `mcpServers`. The
`Agent` trait gets a default no-op `set_mcp_servers` so other agents
(e.g. OpenCode) are unaffected.

Closes openkaiden#88

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Implements set_mcp_servers for OpencodeAgent. Command-based servers
become local entries (type "local", command list = [cmd, ...args],
environment map) and URL-based servers become remote entries
(type "remote", url, headers). Both are merged into the "mcp" key
of .config/opencode/config.json, preserving all existing fields.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
Replace all hardcoded ".config/opencode/config.json" strings in the
opencode sub-modules with a shared pub(crate) constant defined in
mod.rs, imported via `use super::OPENCODE_CONFIG_FILE` in each module.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@feloy, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 7 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e9a79d3-2012-497c-9e0e-24f6b689aec9

📥 Commits

Reviewing files that changed from the base of the PR and between bfcf92c and f8d2792.

📒 Files selected for processing (1)
  • src/agent/opencode/mod.rs
📝 Walkthrough

Walkthrough

Adds MCP server configuration support to the agent settings pipeline. A new set_mcp_servers method is added to the Agent trait with implementations for ClaudeAgent (stdio/sse format in .claude.json) and OpencodeAgent (local/remote format in the opencode config). The opencode config path is consolidated into an OPENCODE_CONFIG_FILE constant. stage_agent_settings is updated to accept and thread MCP config from the workspace.

Changes

MCP Server Configuration

Layer / File(s) Summary
Agent trait contract
src/agent/mod.rs
Adds set_mcp_servers as a default trait method on Agent, accepting optional McpConfiguration and returning files unchanged.
OPENCODE_CONFIG_FILE constant and submodule refactor
src/agent/opencode/mod.rs, src/agent/opencode/anthropic.rs, src/agent/opencode/ollama.rs, src/agent/opencode/openai.rs, src/agent/opencode/vertexai.rs
Defines OPENCODE_CONFIG_FILE constant in opencode/mod.rs and replaces all hardcoded config path strings across all opencode provider submodules and their tests.
ClaudeAgent MCP implementation and tests
src/agent/claude.rs
Implements set_mcp_servers for ClaudeAgent: reads/merges .claude.json, writes stdio entries for mcp.commands and sse entries for mcp.servers, and adds unit tests covering serialization, args/env mapping, optional headers, field preservation, and merging.
OpencodeAgent MCP implementation and tests
src/agent/opencode/mod.rs
Implements set_mcp_servers for OpencodeAgent: parses the opencode config, builds merged mcp object with "local" command entries and "remote" server entries (conditional environment/headers), writes back under OPENCODE_CONFIG_FILE, and adds a full test suite.
stage_agent_settings wiring and integration tests
src/main.rs
Adds mcp parameter to stage_agent_settings, calls agent.set_mcp_servers, passes workspace MCP config from run, updates all existing test call sites, and adds new integration tests asserting mcpServers and mcp output for Claude and Opencode agents.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding MCP configuration support from workspace.json files.
Description check ✅ Passed The description is detailed and directly related to the changeset, explaining the implementation across both Claude and OpenCode agents plus refactoring.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #88 by reading MCP services from workspace.json and updating agent settings to configure MCP services.
Out of Scope Changes check ✅ Passed All changes are within scope: adding set_mcp_servers to the Agent trait, implementing it for Claude and OpenCode agents, and refactoring OpenCode modules to use a shared constant.
Docstring Coverage ✅ Passed Docstring coverage is 83.72% which is sufficient. The required threshold is 80.00%.

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


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.

@feloy feloy changed the title Mcp feat(workspace): support mcp configuration from workspace.json Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.29060% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/agent/mod.rs 0.00% 7 Missing ⚠️
src/agent/opencode/mod.rs 99.41% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@feloy feloy assigned benoitf and jeffmaury and unassigned benoitf and jeffmaury Jun 12, 2026
@feloy feloy requested review from benoitf and jeffmaury June 12, 2026 12:01
@feloy

feloy commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/agent/opencode/mod.rs`:
- Around line 99-100: The JSON parsing fallback at the serde_json::from_str call
in the config initialization is using an empty JSON object, which loses the
$schema field when parsing fails. Instead of falling back to an empty json!({})
on parse error, identify what schema-bearing fallback is used elsewhere in the
code for missing files and apply that same fallback pattern here. Replace the
unwrap_or call to use the proper schema object instead of an empty object so the
config maintains schema consistency even when the existing content is malformed.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 74a13d3c-250d-47b8-a3f3-b9bec8e74839

📥 Commits

Reviewing files that changed from the base of the PR and between 3aef14c and bfcf92c.

📒 Files selected for processing (8)
  • src/agent/claude.rs
  • src/agent/mod.rs
  • src/agent/opencode/anthropic.rs
  • src/agent/opencode/mod.rs
  • src/agent/opencode/ollama.rs
  • src/agent/opencode/openai.rs
  • src/agent/opencode/vertexai.rs
  • src/main.rs

Comment thread src/agent/opencode/mod.rs Outdated
Signed-off-by: Philippe Martin <phmartin@redhat.com>
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.

add mcp services to image

3 participants