Host { # Host Application
  n1: circle label="User sends prompt"
  n2: rectangle label="Agent builds tool call"
  n3: rectangle label="Send request to gateway"
  n4: rectangle label="Receive gateway response"
  n5: rectangle label="Agent responds to user"
  n1.handle(right) -> n2.handle(left)
  n2.handle(right) -> n3.handle(left)
  n3.handle(bottom) -> Gateway.n6.handle(top) [label="Tool request"]
  n4.handle(right) -> n5.handle(left)
}

Gateway { # MCP Gateway
  n6: rectangle label="Receive and log request"
  n7: diamond label="Authorized?"
  n8: rectangle label="Forward to MCP server"
  n9: rectangle label="Receive MCP response"
  n10: rectangle label="Log response and return"
  n6.handle(right) -> n7.handle(left)
  n7.handle(right) -> n8.handle(left) [label="Yes"]
  n7.handle(top) -> Host.n4.handle(left) [label="401 Unauthorized"]
  n8.handle(bottom) -> MCPServer.n11.handle(top) [label="Forwarded request"]
  n9.handle(right) -> n10.handle(left)
  n10.handle(top) -> Host.n4.handle(bottom) [label="Authorized response"]
}

MCPServer { # MCP Server
  n11: rectangle label="Execute tool"
  n12: rectangle label="Return result"
  n11.handle(right) -> n12.handle(left)
  n12.handle(top) -> Gateway.n9.handle(bottom) [label="Tool result"]
}
