Skip to content

security: Swift MCPRouter adds ToolAnnotations to all 11 tools (cyberMaster H1)#253

Merged
EtanHey merged 1 commit intomainfrom
security/swift-mcp-tool-annotations
Apr 24, 2026
Merged

security: Swift MCPRouter adds ToolAnnotations to all 11 tools (cyberMaster H1)#253
EtanHey merged 1 commit intomainfrom
security/swift-mcp-tool-annotations

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Apr 23, 2026

Summary

  • add MCP annotations to all 11 Swift BrainBar tool declarations exposed by tools/list
  • mirror the Python server taxonomy for overlapping tools and classify Swift-only transport tools by their implemented semantics
  • lock the contract down with router-level and socket-level annotation assertions

Why

Swift BrainBar is the default brainlayer transport via .mcp.json.example (socat UNIX-CONNECT:/tmp/brainbar.sock). It previously exposed tools with no ToolAnnotations, so MCP clients on the primary transport could not distinguish read-only, write, or idempotent operations.

Tool Annotation Matrix

Tool readOnlyHint destructiveHint idempotentHint openWorldHint Notes
brain_search true false true false Matches Python READ_ONLY
brain_store false false false false Matches Python WRITE
brain_recall true false true false Matches Python READ_ONLY
brain_entity true false true false Matches Python READ_ONLY
brain_digest false false false false Matches Python WRITE
brain_update false false true false Matches Python WRITE_IDEMPOTENT
brain_expand true false true false Matches Python READ_ONLY
brain_tags true false true false Matches Python READ_ONLY
brain_subscribe false false false false Swift transport-only; classified as WRITE because subscribe mutates live subscription state/generation
brain_unsubscribe false false true false Swift transport-only; classified as WRITE_IDEMPOTENT because repeated unsubscribe is a no-op
brain_ack false false true false Swift transport-only; classified as WRITE_IDEMPOTENT because ack uses monotonic MAX(...) updates

Validation

  • swift build --package-path brain-bar
  • swift test --package-path brain-bar

Runtime Verify

  • Manual BrainBar daemon restart + ad hoc tools/list verification skipped to avoid disrupting the local daemon.
  • Coverage was added instead at the socket transport layer: SocketIntegrationTests.testMCPToolsListOverSocket now asserts annotations over the actual MCP socket path.

Note

Low Risk
Low risk: this is an additive schema/metadata change to tools/list plus new assertions in unit and socket integration tests; it doesn’t alter tool execution paths.

Overview
Adds MCP annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint) to all 11 Swift MCPRouter tool definitions returned by tools/list, using shared helper constants to classify tools as read-only, write, or idempotent-write.

Locks the contract in with new tests that verify the expected annotation matrix both at the router level (MCPRouterTests) and end-to-end over the Unix socket transport (SocketIntegrationTests).

Reviewed by Cursor Bugbot for commit 10525d8. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add MCP ToolAnnotations to all 11 tools in MCPRouter

  • Adds three precomputed annotation constants (readOnlyAnnotations, writeAnnotations, writeIdempotentAnnotations) in MCPRouter.swift, each encoding readOnlyHint, destructiveHint, idempotentHint, and openWorldHint.
  • Attaches the appropriate annotation constant to all 11 tool definitions: read tools (brain_search, brain_recall, brain_entity, brain_expand, brain_tags) are marked read-only/idempotent; write tools use write or write-idempotent annotations.
  • Extends MCPRouterTests.swift and SocketIntegrationTests.swift to assert correct annotation values for every tool.

Macroscope summarized 10525d8.

…Master H1)

Swift is the primary brainlayer transport (.mcp.json.example defaults
to socat UNIX-CONNECT:/tmp/brainbar.sock). It shipped with zero tool
annotations while the Python server has 12/12. LLM clients couldn't
distinguish destructive from read-only tools on the default transport.

Now every Swift tool carries readOnlyHint, destructiveHint,
idempotentHint, openWorldHint matching the Python server's
READ_ONLY / WRITE / WRITE_IDEMPOTENT / DESTRUCTIVE taxonomy.

Per cyberMaster OSS audit 2026-04-23, finding H1 in
~/Gits/cyber/docs.local/security/MASTER-findings-2026-04-23.md.
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 21 minutes and 24 seconds.

⌛ 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: ASSERTIVE

Plan: Pro

Run ID: f1995524-37a2-47be-bb61-b64036cf080b

📥 Commits

Reviewing files that changed from the base of the PR and between 05b2eaf and 10525d8.

📒 Files selected for processing (3)
  • brain-bar/Sources/BrainBar/MCPRouter.swift
  • brain-bar/Tests/BrainBarTests/MCPRouterTests.swift
  • brain-bar/Tests/BrainBarTests/SocketIntegrationTests.swift
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/swift-mcp-tool-annotations

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10525d8836

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[
"name": "brain_search",
"description": "Search through past conversations and learnings. Hybrid semantic + keyword search.",
"annotations": MCPRouter.readOnlyAnnotations,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Mark brain_search as non-read-only for unread flow

brain_search is now advertised with readOnlyHint=true, but this tool performs writes when unread_only=true is used with an agent ID: handleBrainSearch passes those flags into db.search(...), and the DB path updates delivery state via markDelivered(...) (last_delivered_seq). This misclassification can cause MCP clients to schedule it as side-effect-free (including concurrent execution with write-heavy tools), which risks lock contention and incorrect subscription state tracking.

Useful? React with 👍 / 👎.

@EtanHey EtanHey merged commit f60974f into main Apr 24, 2026
7 checks passed
@EtanHey EtanHey deleted the security/swift-mcp-tool-annotations branch April 24, 2026 13:23
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