# IToolApprovalRuleStore

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.itoolapprovalrulestore/
> Summary: IToolApprovalRuleStore: The store for persistent approval rules.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The store for persistent approval rules.

```csharp
public interface IToolApprovalRuleStore
```

## Remarks

The rules are read on every run; implementations must keep the read cheap. The
in-memory implementation holds every rule in memory; the PostgreSQL implementation is
indexed on `(tenant_id, tool_name)`.

## Methods

### <a id="Tracon_IToolApprovalRuleStore_AddAsync_Tracon_ToolApprovalRule_System_Threading_CancellationToken_"></a> AddAsync\(ToolApprovalRule, CancellationToken\)

Adds a rule. When a rule with the same identity is already stored, the existing
rule is returned and no new record is opened.

```csharp
ValueTask<ToolApprovalRule> AddAsync(ToolApprovalRule rule, CancellationToken cancellationToken = default)
```

#### Parameters

`rule` [ToolApprovalRule](/api/tracon.toolapprovalrule/)

The rule to add.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[ToolApprovalRule](/api/tracon.toolapprovalrule/)\>

The persisted rule.

#### Remarks

A rule's identity is its tenant, agent, tool, [ToolApprovalRule.ArgumentsHash](/api/tracon.toolapprovalrule/#Tracon_ToolApprovalRule_ArgumentsHash),
[ToolApprovalRule.SourceFingerprint](/api/tracon.toolapprovalrule/#Tracon_ToolApprovalRule_SourceFingerprint), and condition set. Two rules that
differ only in their source fingerprint are two rules: a rule for the same tool of a
server that has since moved to another endpoint must not come back in place of a
new one. The condition set is compared as a set - the order of the
conditions does not count. Within a condition, the path and the operator are
compared exactly and the value as its JSON text, with one exception: a list value
([ToolArgumentOperator.In](/api/tracon.toolargumentoperator/), [ToolArgumentOperator.NotIn](/api/tracon.toolargumentoperator/)) is
compared element by element, so whitespace between its elements does not count.
Every other value is compared as the exact JSON text it was written with -
`100` and `100.0` are two different conditions, and so are two strings
that differ only inside the quotes.

### <a id="Tracon_IToolApprovalRuleStore_DeleteAsync_System_String_System_Guid_System_Threading_CancellationToken_"></a> DeleteAsync\(string, Guid, CancellationToken\)

Deletes a rule.

```csharp
ValueTask<bool> DeleteAsync(string tenantId, Guid ruleId, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant id. The rule of another tenant cannot be deleted.

`ruleId` [Guid](https://learn.microsoft.com/dotnet/api/system.guid)

The rule id.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when the rule was deleted.

### <a id="Tracon_IToolApprovalRuleStore_ListAsync_System_String_System_Threading_CancellationToken_"></a> ListAsync\(string, CancellationToken\)

Lists the rules of a tenant.

```csharp
ValueTask<IReadOnlyList<ToolApprovalRule>> ListAsync(string tenantId, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant id.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[ToolApprovalRule](/api/tracon.toolapprovalrule/)\>\>

The rules, newest first.
