Skip to content

Commit 7ab63ca

Browse files
Implement account users tool
will help us be able to see who's registered in a given plural account
1 parent 8ed0bed commit 7ab63ca

File tree

7 files changed

+68
-11
lines changed

7 files changed

+68
-11
lines changed

Diff for: apps/core/lib/core/mcp/server.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ defmodule Core.MCP.Server do
22
use MCPServer
33
alias Core.MCP.Tools.{
44
Account,
5+
AccountUsers,
56
Enterprise,
67
CloudConsole,
78
RemoveEnterprise
89
}
910

10-
@tools [Account, Enterprise, CloudConsole, RemoveEnterprise]
11+
@tools [Account, AccountUsers, Enterprise, CloudConsole, RemoveEnterprise]
1112
@by_name Map.new(@tools, & {&1.name(), &1})
1213

1314
@protocol_version "2024-11-05"

Diff for: apps/core/lib/core/mcp/tools/account_users.ex

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmodule Core.MCP.Tools.AccountUsers do
2+
@behaviour Core.MCP.Tool
3+
alias Core.Services.Accounts
4+
alias Core.Schema.{User, Account}
5+
6+
def name(), do: "account_users"
7+
8+
def description(), do: "Fetches the users associated with a Plural account"
9+
10+
def schema(), do: %{
11+
type: "object",
12+
required: ["account_id"],
13+
properties: %{
14+
account_id: %{
15+
type: "string",
16+
description: "The ID of the account you want to fetch users for"
17+
}
18+
}
19+
}
20+
21+
def invoke(%{"account_id" => id}) do
22+
with %Account{} = account <- Accounts.get_account(id) do
23+
User.for_account(account.id)
24+
|> Core.Repo.all()
25+
|> Enum.map(&Map.take(&1, ~w(id email name)a))
26+
|> Jason.encode()
27+
else
28+
_ -> {:ok, "no account with id #{id}"}
29+
end
30+
end
31+
def invoke(_), do: {:error, "account_id is required"}
32+
end

Diff for: apps/core/lib/core/mcp/tools/cloud_console.ex

+3-7
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ defmodule Core.MCP.Tools.CloudConsole do
2323
end
2424

2525
def invoke(%{"name" => name}) do
26-
with %ConsoleInstance{} = console <- Cloud.get_instance_by_name(name),
27-
console = Repo.preload(console, [:cluster, owner: [account: [subscription: :plan]]]) do
28-
format(console)
26+
with %ConsoleInstance{} = console <- Cloud.get_instance_by_name(name) do
27+
Repo.preload(console, [:cluster, owner: [account: [subscription: :plan]]])
28+
|> Map.take(~w(id first_notif_at second_notif_at type name status subdomain url cloud size region cluster owner)a)
2929
|> Proto.serialize()
3030
|> Jason.encode()
3131
else
3232
_ -> {:ok, "no instance with name #{name}"}
3333
end
3434
end
3535
def invoke(_), do: {:error, "email is required"}
36-
37-
defp format(console) do
38-
Map.take(console, ~w(id type name status subdomain url cloud size region cluster owner)a)
39-
end
4036
end

Diff for: apps/core/test/mcp/tools/account_users_test.exs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule Core.MCP.Tools.AccountUsersTest do
2+
use Core.SchemaCase, async: true
3+
alias Core.MCP.Tools.AccountUsers
4+
5+
describe "invoke/1" do
6+
test "it will fetch a users account info" do
7+
account = insert(:account)
8+
user = insert(:user, account: account)
9+
10+
{:ok, res} = AccountUsers.invoke(%{"account_id" => account.id})
11+
{:ok, [parsed]} = Jason.decode(res)
12+
13+
assert parsed["id"] == user.id
14+
assert parsed["email"] == user.email
15+
assert parsed["name"] == user.name
16+
end
17+
end
18+
end

Diff for: apps/cron/lib/cron/prune/cloud.ex

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ defmodule Cron.Prune.Cloud do
55
use Cron
66
alias Core.Schema.{ConsoleInstance}
77
alias Core.Services.Cloud
8+
require Logger
89

910
def run() do
1011
ConsoleInstance.unpaid()
1112
|> ConsoleInstance.reapable()
1213
|> ConsoleInstance.ordered(asc: :id)
1314
|> Core.Repo.stream(method: :keyset)
1415
|> Core.throttle()
15-
|> Enum.each(&Cloud.reap/1)
16+
|> Enum.each(fn inst ->
17+
Logger.info("Reaping cloud console #{inst.id}")
18+
Cloud.reap(inst)
19+
|> log_error()
20+
end)
21+
end
22+
23+
defp log_error({:ok, _}), do: :ok
24+
defp log_error(err) do
25+
Logger.error("Error reaping cloud console: #{inspect(err)}")
1626
end
1727
end

Diff for: plural/helm/plural/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: plural
33
description: A helm chart for installing plural
44
appVersion: 0.11.8
5-
version: 0.10.104
5+
version: 0.10.105
66
dependencies:
77
- name: hydra
88
version: 0.26.5

Diff for: plural/helm/plural/templates/cron.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
{{- end }}
2626
containers:
2727
- name: cron
28-
image: "{{ .Values.global.registry }}/{{ .Values.cron.repository }}:{{ .Values.cron.tag | default .Chart.AppVersion }}"
28+
image: "{{ .Values.global.registry }}/{{ .Values.cron.repository }}:{{ include "plural.imageTag" . }}"
2929
imagePullPolicy: {{ .Values.image.pullPolicy }}
3030
envFrom:
3131
- secretRef:

0 commit comments

Comments
 (0)