Skip to content

fix(mcp): пометить MCP-инструменты как read-only#4227

Merged
nixel2007 merged 2 commits into
developfrom
claude/github-issue-4226-muqngh
Jun 28, 2026
Merged

fix(mcp): пометить MCP-инструменты как read-only#4227
nixel2007 merged 2 commits into
developfrom
claude/github-issue-4226-muqngh

Conversation

@nixel2007

@nixel2007 nixel2007 commented Jun 28, 2026

Copy link
Copy Markdown
Member

Описание

В режиме MCP все 10 инструментов помечались клиентом (например, Claude) как потенциально разрушающие (destructive), из-за чего при каждом вызове запрашивалось подтверждение. Причина — у @McpTool-методов отсутствовали аннотации, а по спецификации MCP при отсутствии readOnlyHint инструмент считается потенциально изменяющим данные.

Изменения:

  • Добавлена аннотация @McpTool.McpAnnotations(readOnlyHint = true, destructiveHint = false, idempotentHint = true, openWorldHint = false) ко всем 10 инструментам (AnalyzeFileTool, DocumentSymbolsTool, FindReferencesTool, CallHierarchyTool, HoverTool, DefinitionTool, TypeInfoTool, TypeAtPositionTool, GlobalMemberInfoTool, GlobalMemberSearchTool). Все они только читают код 1С/OneScript и ничего не изменяют, детерминированы и работают в рамках анализируемого проекта.
  • В McpStreamableServerTest добавлен тест allToolsAreMarkedReadOnly, который поднимает реальный MCP-сервер, получает список зарегистрированных инструментов и проверяет, что у каждого readOnlyHint = true и destructiveHint = false — то есть подсказки доходят до клиента сквозь Spring AI, а не просто присутствуют в исходниках. Тест также служит защитой для будущих инструментов.

Связанные задачи

Closes #4226

Чеклист

Общие

  • Ветка PR обновлена из develop
  • Отладочные, закомментированные и прочие, не имеющие смысла участки кода удалены
  • Изменения покрыты тестами
  • Обязательные действия перед коммитом выполнены (запускал команду gradlew precommit)

Для диагностик

  • Описание диагностики заполнено для обоих языков (изменение не связано с диагностиками)

Дополнительно

Локально пройден McpStreamableServerTest (3/3), compileJava/compileTestJava без ошибок.

🤖 Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • MCP tools now advertise clearer client-facing behavior hints, indicating they are read-only, non-destructive, idempotent, and closed-world.
  • Tests
    • Added a test to confirm every exposed MCP tool includes these read-only and non-destructive markings.

All 10 MCP tools only inspect 1C/OneScript code and never mutate
anything, but they lacked tool annotations. Without a readOnlyHint,
clients (e.g. Claude) treat them as potentially destructive and prompt
for confirmation on every call.

Add @McpTool.McpAnnotations(readOnlyHint = true, destructiveHint = false,
idempotentHint = true, openWorldHint = false) to every tool, and assert
the hints reach the registered tool specs in McpStreamableServerTest.

Closes #4226
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d7c89285-1295-473f-a0ef-d5527b67b52d

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0bac9 and 92c6085.

📒 Files selected for processing (11)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/AnalyzeFileTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/CallHierarchyTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/DefinitionTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/DocumentSymbolsTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/FindReferencesTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/GlobalMemberInfoTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/GlobalMemberSearchTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/HoverTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/TypeAtPositionTool.java
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/TypeInfoTool.java
  • src/test/java/com/github/_1c_syntax/bsl/languageserver/mcp/McpStreamableServerTest.java

📝 Walkthrough

Walkthrough

All ten MCP tool classes gain @McpTool.McpAnnotations hints for read-only, non-destructive, idempotent, and closed-world behavior. A new test checks that every registered tool exposes those annotations.

Changes

MCP Tool Read-Only Hints

Layer / File(s) Summary
McpAnnotations added to all tools
src/main/java/com/github/_1c_syntax/bsl/languageserver/mcp/tools/AnalyzeFileTool.java, CallHierarchyTool.java, DefinitionTool.java, DocumentSymbolsTool.java, FindReferencesTool.java, GlobalMemberInfoTool.java, GlobalMemberSearchTool.java, HoverTool.java, TypeAtPositionTool.java, TypeInfoTool.java
Each tool's @McpTool annotation is extended with annotations = @McpTool.McpAnnotations(readOnlyHint=true, destructiveHint=false, idempotentHint=true, openWorldHint=false).
Test asserting all tools are read-only
src/test/java/com/github/_1c_syntax/bsl/languageserver/mcp/McpStreamableServerTest.java
New test allToolsAreMarkedReadOnly retrieves all tools from mcpSyncServer and asserts each has non-null annotations with readOnlyHint=true and destructiveHint=false.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 Hops of code in a gentle stream,
Read-only tools now fit the dream.
No destructive flags in sight,
Closed-world hints shining bright.
A rabbit nods: “Yes, this is neat!”

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: marking MCP tools as read-only.
Linked Issues check ✅ Passed All 10 MCP tools were updated with read-only/non-destructive hints, and the new test verifies the client sees them.
Out of Scope Changes check ✅ Passed The changes are focused on MCP tool annotations and the supporting test, with no unrelated code paths altered.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/github-issue-4226-muqngh

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.

Drop the (#4226) issue links from the read-only annotation comments;
the issue is tracked via the PR/commit, not in the source.
@nixel2007
nixel2007 merged commit 141c63a into develop Jun 28, 2026
20 of 21 checks passed
@nixel2007
nixel2007 deleted the claude/github-issue-4226-muqngh branch June 28, 2026 11:17
@sonarqubecloud

Copy link
Copy Markdown

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.

MCP: все tool помечаются как destructive (не хватает read-only аннотаций)

2 participants