Skip to content

Add five new fields to MCPServiceConfig and mcpKnownKeys to support#384

Open
moizpgedge wants to merge 4 commits into
mainfrom
Feat/PLAT-590/Add-KB-fields-to-MCPServiceConfig
Open

Add five new fields to MCPServiceConfig and mcpKnownKeys to support#384
moizpgedge wants to merge 4 commits into
mainfrom
Feat/PLAT-590/Add-KB-fields-to-MCPServiceConfig

Conversation

@moizpgedge
Copy link
Copy Markdown
Contributor

@moizpgedge moizpgedge commented May 11, 2026

feat: add knowledgebase support to MCP service

Enables the search_knowledgebase tool in MCP service deployments.
Operators place a SQLite KB file on the host once; the Control Plane
validates it, bind-mounts it read-only into every MCP container on
that host, and wires up the knowledgebase: section in config.yaml.

Summary

  • PLAT-590 — KB config fields on MCPServiceConfig with
    parse-time validation
  • PLAT-607 — Reject kb_enabled: true +
    disable_search_knowledgebase: true together
  • PLAT-591knowledgebase: section emitted in config.yaml
  • PLAT-592 — Read-only /app/kb bind mount in the MCP container
  • PLAT-593 — Deployment blocked when KB file is missing on the host
  • PLAT-608 — Documentation (docs/services/mcp.md)

Changes

PLAT-590 — KB fields on MCPServiceConfig

Five new config fields added to MCPServiceConfig and mcpKnownKeys:

Field Type Description
kb_enabled bool Opt-in. When false or absent, stale kb_* fields are rejected (matching the llm_enabled pattern).
kb_embedding_provider string Required when kb_enabled is true. Accepted: voyage, openai.
kb_embedding_model string Required when kb_enabled is true. Must match the model used to build the KB file.
kb_embedding_api_key string Required for voyage and openai. Scrubbed from API responses automatically via the existing api_key sensitive-field policy.
kb_database_host_path string Optional override for the KB file path on the host. Defaults to {DataDir}/kb/nla-kb.db.

Validation rules enforced in ParseMCPServiceConfig:

  • kb_embedding_provider and kb_embedding_model are required when
    kb_enabled: true
  • kb_embedding_api_key is required for voyage and openai
  • ollama is explicitly rejected — the MCP KB config requires a
    separate embedding_ollama_url field and there is no matching CP
    field yet; accepting it would silently write an empty URL
  • Unknown providers are rejected with "must be one of: voyage, openai"
  • Stale KB fields (kb_embedding_provider, kb_embedding_model,
    kb_embedding_api_key, kb_database_host_path) are rejected
    when kb_enabled is false or absent, matching the same pattern
    used by llm_enabled

PLAT-607 — kb_enabled + disable_search_knowledgebase conflict

Setting kb_enabled: true together with
disable_search_knowledgebase: true is rejected at parse time.
The combination would deploy a running container with no
search_knowledgebase tool registered — a silently broken setup.

This validation lives in the same block as the KB field validation and
is included here to close the gap between merging PLAT-590 and a
hypothetical standalone PLAT-607 ticket.

PLAT-591 — knowledgebase: section in config.yaml

GenerateMCPConfig now emits a knowledgebase: block when
kb_enabled is true. The database_path uses the container-side
path (/app/kb/<basename>), derived from the host path basename.
The API key field name varies by provider:
embedding_voyage_api_key or embedding_openai_api_key.

Example output for OpenAI:

knowledgebase:
  enabled: true
  database_path: /app/kb/nla-kb.db
  embedding_provider: openai
  embedding_model: text-embedding-3-small
  embedding_openai_api_key: sk-...

When kb_enabled is absent or false, no knowledgebase: key is
emitted and behavior is identical to before this change.

PLAT-592 — Read-only /app/kb bind mount

ServiceContainerSpec adds a read-only bind mount from the host KB
directory to /app/kb when KBDirPath is non-empty. The mount is on
the directory, not the file. A file bind mount ties the container
to the original inode — an atomic rename (write to temp file, rename
into place) creates a new inode, so the container would keep reading
the old file. A directory mount tracks by name, so the renamed file is
visible immediately. When kb_enabled is absent or false, no extra
mount is added.

PLAT-593 — Deployment blocked when KB file is missing

MCPConfigResource.Refresh checks for the KB file before checking
for config.yaml. This ordering is intentional: a new service has no
config.yaml yet, so checking config.yaml first would return
ErrNotFound (triggering Create) before the KB check ran, silently
allowing a container to start with a broken bind mount.

By checking KB first, a missing file returns a plain fmt.Errorf,
which blocks both initial creates and subsequent updates. ErrNotFound
is never returned for a missing KB file.

PLAT-608 — Documentation

docs/services/mcp.md gains:

  • Configuration Reference → Knowledgebase — intro, !!! warning
    admonition (staging requirement and default path), 5-field table
  • Examples → Knowledgebase Search (Voyage AI) — pre-staging shell
    block, complete curl request body, custom path note

Tests

Unit tests

go test \
  ./server/internal/database/... \
  ./server/internal/orchestrator/swarm/... \
  -run "TestParseMCPServiceConfig/knowledgebase_config|TestGenerateMCPConfig_KB|TestServiceContainerSpec_MCP|TestMCPConfigResource" \
  -v
Ticket Test Count
PLAT-590 + 607 TestParseMCPServiceConfig/knowledgebase_config 26
PLAT-591 TestGenerateMCPConfig_KB 7
PLAT-592 TestServiceContainerSpec_MCP 2
PLAT-593 TestMCPConfigResource 9

Key PLAT-593 cases:

Test Scenario Must return
Refresh_KBDisabled KBHostPath="" nil
Refresh_KBFilePresent File exists nil
Refresh_KBFileMissing File missing, config.yaml present plain error, NOT ErrNotFound
Refresh_KBFileMissing_NoConfigYet File missing, no config.yaml plain error, NOT ErrNotFound

Manual — validation errors (all return HTTP 400)

# Missing kb_embedding_provider
# Expected: kb_embedding_provider is required when kb_enabled is true
restish control-plane-local-1 create-database '{
  "id": "kb-err-1", "spec": { "database_name": "kb-err-1",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_model":"text-embedding-3-small","kb_embedding_api_key":"x"}
  }]}}'

# Missing kb_embedding_model
# Expected: kb_embedding_model is required when kb_enabled is true
restish control-plane-local-1 create-database '{
  "id": "kb-err-2", "spec": { "database_name": "kb-err-2",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_provider":"openai","kb_embedding_api_key":"x"}
  }]}}'

# Missing kb_embedding_api_key
# Expected: kb_embedding_api_key is required when kb_embedding_provider is "openai"
restish control-plane-local-1 create-database '{
  "id": "kb-err-3", "spec": { "database_name": "kb-err-3",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_provider":"openai","kb_embedding_model":"text-embedding-3-small"}
  }]}}'

# Ollama rejected
# Expected: kb_embedding_provider "ollama" is not yet supported; use "voyage" or "openai"
restish control-plane-local-1 create-database '{
  "id": "kb-err-4", "spec": { "database_name": "kb-err-4",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_provider":"ollama","kb_embedding_model":"nomic-embed-text"}
  }]}}'

# Unknown provider
# Expected: kb_embedding_provider must be one of: voyage, openai
restish control-plane-local-1 create-database '{
  "id": "kb-err-5", "spec": { "database_name": "kb-err-5",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_provider":"bedrock","kb_embedding_model":"some-model","kb_embedding_api_key":"x"}
  }]}}'

# kb_enabled + disable_search_knowledgebase conflict (PLAT-607)
# Expected: kb_enabled and disable_search_knowledgebase cannot both be true
restish control-plane-local-1 create-database '{
  "id": "kb-err-6", "spec": { "database_name": "kb-err-6",
  "database_users": [{"username":"app","password":"password","attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"connect_as":"app",
    "config":{"kb_enabled":true,"kb_embedding_provider":"openai","kb_embedding_model":"text-embedding-3-small","kb_embedding_api_key":"x","disable_search_knowledgebase":true}
  }]}}'

Manual — successful deployment

Stage the KB file first:

mkdir -p docker/control-plane-dev/data/host-1/kb
gh release download kb-2026-04-27 --repo pgEdge/pgedge-postgres-mcp \
  --pattern "kb.db"
mv kb.db docker/control-plane-dev/data/host-1/kb/nla-kb.db

Deploy:

restish control-plane-local-1 create-database '{
  "id": "kb-ok", "spec": { "database_name": "kb-ok",
  "database_users": [{"username":"app","password":"password","db_owner":true,"attributes":["LOGIN"]}],
  "nodes": [{"name":"n1","host_ids":["host-1"]}],
  "services": [{"service_id":"mcp-1","service_type":"mcp","version":"latest",
    "host_ids":["host-1"],"port":8080,"connect_as":"app",
    "config":{
      "kb_enabled":true,
      "kb_embedding_provider":"openai",
      "kb_embedding_model":"text-embedding-3-small",
      "kb_embedding_api_key":"'"$OPENAI_API_KEY"'",
      "init_token":"my-token"
    }
  }]}}'

Verify (PLAT-591): config.yaml contains a knowledgebase: block with
database_path: /app/kb/nla-kb.db.

Verify (PLAT-592): docker inspect shows a read-only bind mount at
/app/kb.

Verify (PLAT-590): restish control-plane-local-1 get-database kb-ok
kb_embedding_api_key is absent from services[0].config.

Verify (PLAT-593): Remove the KB file and redeploy — task fails with
KB database file not found at .../nla-kb.db.

Notes for Reviewers

PLAT-607 is included in this PR — it lives in the same validation
block as the KB field checks. Splitting it out would leave a window
where a user could configure a silently broken setup.

kb_embedding_api_key scrubbing requires no code change — the
existing isSensitiveConfigKey function matches any key containing the
substring api_key, so kb_embedding_api_key is covered automatically.

The KB file check ordering in Refresh is load-bearing — the
comment in the code explains why it must come before the config.yaml
check. Do not reorder.

SIGHUP does not reload KB — SIGHUP triggers
clientManager.UpdateDatabaseConfigs() only. KB state is initialized
once at startup. Any KB config change (provider, model, credentials,
or path) requires a container restart via a Control Plane service
update.

Checklist

  • Tests added (unit)
  • Documentation updated (docs/services/mcp.md)
  • Issues linked

Issues

knowledgebase search configuration for the MCP service:

- `kb_enabled` — opt-in bool; when false or absent all other KB fields
  are ignored and no validation runs
- `kb_embedding_provider` — required when KB is enabled; `voyage` and
  `openai` are the only accepted values for V1
- `kb_embedding_model` — required when KB is enabled
- `kb_embedding_api_key` — required for `voyage` and `openai`; scrubbed
  from API output automatically via the existing `api_key` sensitive-field
  policy
- `kb_database_host_path` — optional override for the KB file path on the
  host; defaults to `{DataDir}/kb/nla-kb.db` in downstream tickets

Validation rules enforced at `ParseMCPServiceConfig` call time:

- `ollama` is rejected with an explicit "not yet supported in V1" error;
  full ollama support is blocked on the `embedding_ollama_url` field
  mapping question (see PLAT-607)
- Setting `kb_enabled: true` together with `disable_search_knowledgebase:
  true` is rejected — the combination would silently produce a running
  container with no `search_knowledgebase` tool registered
- All KB fields are silently ignored when `kb_enabled` is false or absent,
  matching the same opt-in pattern used by `llm_enabled`

PLAT-590
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Review Change Stack

Warning

Rate limit exceeded

@moizpgedge has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 53 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4597eb51-a21e-4d81-bc2b-08292da3dd18

📥 Commits

Reviewing files that changed from the base of the PR and between dd215cd and 6ffa366.

📒 Files selected for processing (1)
  • docs/services/mcp.md
📝 Walkthrough

Walkthrough

MCPServiceConfig adds knowledgebase (KB) configuration support, with parsing and validation. The change emits a knowledgebase section in generated YAML, requires staged KB files during resource Refresh, propagates KB host/dir paths through orchestrator and service specs to add a read-only /app/kb mount for RAG containers, and adds tests and docs.

Changes

Knowledgebase Configuration

Layer / File(s) Summary
Data Shape
server/internal/database/mcp_service_config.go
MCPServiceConfig adds KBEnabled, KBEmbeddingProvider, KBEmbeddingModel, KBEmbeddingAPIKey, and KBDatabaseHostPath optional fields.
Configuration Allowlists
server/internal/database/mcp_service_config.go
mcpKnownKeys is extended to recognize KB configuration keys; validKBEmbeddingProviders is introduced to restrict supported embedding providers (excluding ollama).
Parsing Logic
server/internal/database/mcp_service_config.go
ParseMCPServiceConfig parses KB fields (kb_enabled, embedding provider/model/API key, database host path) from raw config into local variables.
Validation Rules
server/internal/database/mcp_service_config.go
When kb_enabled is true, validation enforces: conflict check (KB enabled + disable_search_knowledgebase), required embedding provider and model, provider allowlist membership, forbidden ollama, API key requirements for voyage and openai, and absolute/clean host-path validation; when false, KB-only fields are rejected.
Struct Assignment
server/internal/database/mcp_service_config.go
Parsed KB fields are assigned to the returned MCPServiceConfig instance on success.
YAML Generation
server/internal/orchestrator/swarm/mcp_config.go
Add mcpKBConfig and include Knowledgebase in generated YAML; derive container database path from host path basename when overridden and populate provider-specific API key fields.
MCP Config Resource
server/internal/orchestrator/swarm/mcp_config_resource.go
Add KBHostPath field and verify KB host file exists during Refresh before validating config.yaml.
MCPConfigResource Tests
server/internal/orchestrator/swarm/mcp_config_resource_test.go
Add tests for resource metadata and Refresh behavior with/without KBHostPath using in-memory FS helper.
Orchestrator Injection
server/internal/orchestrator/swarm/orchestrator.go
Compute kbHostPath and kbDirPath when KB enabled and inject into MCPConfigResource and ServiceInstanceSpecResource.
Service Instance Spec
server/internal/orchestrator/swarm/service_instance_spec.go
ServiceInstanceSpecResource adds KBDirPath and forwards it into ServiceContainerSpecOptions during Refresh.
Container Spec Mount
server/internal/orchestrator/swarm/service_spec.go
ServiceContainerSpecOptions adds KBDirPath; rag services append a read-only bind mount from KBDirPath to /app/kb when set.
Container Spec Tests
server/internal/orchestrator/swarm/service_spec_test.go
Tests confirm no KB mount when KBDirPath unset and an additional read-only /app/kb mount when set.
Tests / Documentation
server/internal/database/mcp_service_config_test.go, docs/services/mcp.md
Add KB parsing/validation tests and a docs section with a Voyage AI example and host-path override snippet.

Poem

A knowledge base hops into place, 🐇
With embeddings swift and provider grace,
Voyage and OpenAI take their stance,
While ollama sits out of the dance,
Validation ensures all fields align.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is incomplete and vague, ending with 'to support' without specifying what is being supported. Complete the title to clearly specify what the five fields support, e.g., 'Add knowledgebase configuration fields to MCPServiceConfig' or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Description check ✅ Passed The PR description is comprehensive and well-structured, following the provided template with all required sections completed.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Feat/PLAT-590/Add-KB-fields-to-MCPServiceConfig

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.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 11, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 duplication

Metric Results
Duplication 5

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@moizpgedge moizpgedge marked this pull request as draft May 11, 2026 13:33
…-608)

Enables the search_knowledgebase tool in MCP service deployments via a
host-placed SQLite KB file bind-mounted read-only into the container.

**PLAT-590 — KB fields on MCPServiceConfig (already committed)**
Five new config fields: kb_enabled, kb_embedding_provider,
kb_embedding_model, kb_embedding_api_key, kb_database_host_path.
Parse-time validation rejects unknown providers, missing credentials,
and the kb_enabled + disable_search_knowledgebase conflict (PLAT-607).
kb_embedding_api_key is scrubbed from API output.

**PLAT-591 — knowledgebase: section in config.yaml**
GenerateMCPConfig now emits a knowledgebase: block when kb_enabled is
true. The database_path uses the container-side path (/app/kb/<file>),
derived from the host path basename. The API key field name varies by
provider: embedding_voyage_api_key or embedding_openai_api_key.

**PLAT-592 — read-only /app/kb bind mount**
ServiceContainerSpec adds a read-only bind mount from the host KB
directory to /app/kb when KBDirPath is non-empty. The mount is on the
directory, not the file, so atomic renames of the KB file are visible
to the container immediately.

**PLAT-593 — deployment blocked when KB file is missing**
MCPConfigResource.Refresh checks for the KB file before checking for
config.yaml. This ordering is intentional: a new service has no
config.yaml yet, so checking config.yaml first would return ErrNotFound
(triggering Create) before the KB check runs. By checking KB first, a
missing file returns a plain error that blocks both initial creates and
updates. ErrNotFound is never returned for a missing KB file.

**PLAT-608 — documentation**
docs/services/mcp.md gains a Knowledgebase section under Configuration
Reference (5-field table, warning admonition for the staging requirement)
and a Knowledgebase Search (Voyage AI) example under Examples.

- 19 parse-time validation cases (PLAT-590 + PLAT-607)
- 7 config generation cases coveproviders and custom path (PLAT-591)
- 2 container spec cases confirming mount presence/absence (PLAT-592)
- 9 Refresh cases covering KB disabled, file present, file missing with
  and without existing config.yaml (PLAT-593)
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.

🧹 Nitpick comments (1)
server/internal/orchestrator/swarm/mcp_config_resource_test.go (1)

24-24: ⚡ Quick win

Handle the error from MkdirAll for consistency.

The error from fs.MkdirAll is silently discarded, while line 39 uses t.Fatalf for errors, and the test cases use require.NoError for file operations (lines 85, 105-107, 128). For consistency and fail-fast behavior on setup issues, use require.NoError here as well.

🛡️ Proposed fix
-	_ = fs.MkdirAll(dirPath, 0o700)
+	require.NoError(t, fs.MkdirAll(dirPath, 0o700))
🤖 Prompt for 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.

In `@server/internal/orchestrator/swarm/mcp_config_resource_test.go` at line 24,
The call to fs.MkdirAll currently discards its error; change it to check and
fail the test on error (consistent with other setup code) by capturing the error
from fs.MkdirAll(dirPath, 0o700) and calling require.NoError(t, err) (or
t.Fatalf on error) so the test setup fails fast; refer to the fs.MkdirAll call
and dirPath in mcp_config_resource_test.go and use the existing testing imports
(require) used elsewhere in the file.
🤖 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.

Nitpick comments:
In `@server/internal/orchestrator/swarm/mcp_config_resource_test.go`:
- Line 24: The call to fs.MkdirAll currently discards its error; change it to
check and fail the test on error (consistent with other setup code) by capturing
the error from fs.MkdirAll(dirPath, 0o700) and calling require.NoError(t, err)
(or t.Fatalf on error) so the test setup fails fast; refer to the fs.MkdirAll
call and dirPath in mcp_config_resource_test.go and use the existing testing
imports (require) used elsewhere in the file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dd5e577a-1ffb-40f0-bce1-b442d8283c6e

📥 Commits

Reviewing files that changed from the base of the PR and between 731d00f and 3006e2c.

📒 Files selected for processing (9)
  • docs/services/mcp.md
  • server/internal/orchestrator/swarm/mcp_config.go
  • server/internal/orchestrator/swarm/mcp_config_resource.go
  • server/internal/orchestrator/swarm/mcp_config_resource_test.go
  • server/internal/orchestrator/swarm/mcp_config_test.go
  • server/internal/orchestrator/swarm/orchestrator.go
  • server/internal/orchestrator/swarm/service_instance_spec.go
  • server/internal/orchestrator/swarm/service_spec.go
  • server/internal/orchestrator/swarm/service_spec_test.go

@moizpgedge moizpgedge marked this pull request as ready for review May 11, 2026 17:23
Address security and correctness issues raised in code review:

- Reject `kb_database_host_path` values that are not absolute or contain
  `..` components. An unsanitized host path could be used to bind-mount
  arbitrary host directories into the container via the CP API.
- Reject stale `kb_*` fields (provider, model, api_key, host_path) when
  `kb_enabled` is false or absent, matching the existing LLM pattern.
  Previously these were silently ignored, hiding typos and stale config.
- Make `ollama` provider check case-insensitive (`strings.ToLower`) so
  `"Ollama"` gets the explicit "not yet supported" error instead of the
  generic "must be one of" message.
- Replace defensive nil checks in `GenerateMCPConfig` with an invariant
  assertion. If KB fields are nil despite `kb_enabled=true`, the function
  now returns an error immediately rather than silently emitting empty
  strings into `config.yaml`. Fields are dereferenced unconditionally
  below the assertion.
- Fix discarded `MkdirAll` error in `mcpRCAndFs` test helper — use
  `require.NoError` instead of `_ =`.
- Add `!!! note` to `docs/services/mcp.md` stating that any `kb_*`
  config change requires a container restart, not just a SIGHUP reload.
- Add test cases: relative path, `..` path, case-insensitive ollama,
  and four cases for stale KB fields rejected when disabled.

PLAT-590
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: 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 `@docs/services/mcp.md`:
- Around line 87-90: The docs currently claim kb_* fields are ignored when
kb_enabled is false, but implementation rejects those fields; update the
phrasing around kb_enabled and kb_* (lines referencing "kb_enabled", "kb_*", and
the embedding providers "voyage" and "openai" and note about "Ollama") to state
that kb_* fields are invalid/rejected unless kb_enabled is true (also apply the
same change to the other occurrence mentioned around lines 109-110), and make
clear the validator will fail the config rather than silently ignoring those
fields.
🪄 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: 42cf1446-aff5-4f7d-bf4f-ccb485abcc5f

📥 Commits

Reviewing files that changed from the base of the PR and between 3006e2c and dd215cd.

📒 Files selected for processing (5)
  • docs/services/mcp.md
  • server/internal/database/mcp_service_config.go
  • server/internal/database/mcp_service_config_test.go
  • server/internal/orchestrator/swarm/mcp_config.go
  • server/internal/orchestrator/swarm/mcp_config_resource_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/internal/orchestrator/swarm/mcp_config.go
  • server/internal/orchestrator/swarm/mcp_config_resource_test.go
  • server/internal/database/mcp_service_config_test.go

Comment thread docs/services/mcp.md Outdated
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