fix(mcp): пометить MCP-инструменты как read-only#4227
Conversation
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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughAll ten MCP tool classes gain ChangesMCP Tool Read-Only Hints
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Drop the (#4226) issue links from the read-only annotation comments; the issue is tracked via the PR/commit, not in the source.
|



Описание
В режиме 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
Чеклист
Общие
gradlew precommit)Для диагностик
Дополнительно
Локально пройден
McpStreamableServerTest(3/3),compileJava/compileTestJavaбез ошибок.🤖 Generated with Claude Code
Generated by Claude Code
Summary by CodeRabbit