@startuml
actor "Copilot Chat (client)" as copilot
box "MCP Server" #LightBlue
  participant "Controller" as controller
  participant "Tool Handler" as toolHandler
  participant "Rule Fetchers" as ruleFetchers
  participant "Logger" as logger
end box
participant "Storage" as storage #yellow
participant "External Server" as extServer #orange

autonumber
copilot -> controller : call_tool (fetch_misra_rule, arguments)
controller -> toolHandler : fetch_misra_rule(arguments)
toolHandler -> ruleFetchers : fetch_misra_rule(url)
alt Rule in storage
  ruleFetchers -> storage : read MISRA rule file
  storage --> ruleFetchers : return rule content
else Rule from external
  ruleFetchers -> extServer : fetch MISRA rule (url)
  extServer --> ruleFetchers : return rule content
end
ruleFetchers -> logger : log fetch
ruleFetchers --> toolHandler : return MISRA rule content
toolHandler --> controller : return result
controller --> copilot : return MISRA rule content
@enduml
