> Documentation index: https://metorial.com/llms.txt. Every page is available as Markdown by adding .md to its URL.

# Limit the tools an agent can use from an integration
URL: https://metorial.com/docs/build/guides/limit-agent-tools

Add toolFilters to a provider entry when you create a session, for example { type: "tool_keys", keys: ["webSearch"] }, so the session serves only those tools.

---

To give an agent only some of a provider's tools, add `toolFilters` to that provider's entry when you create the session. `{ type: 'tool_keys', keys: ['webSearch'] }` serves one tool, and `{ type: 'tool_regex', pattern: '^(list|get|search)' }` serves every tool whose key matches. Metorial applies the filter on its side, so the agent can neither see nor call the rest.

**What you'll learn**

* How to find a provider's tool keys
* How to filter tools for one session or for every session of a deployment
* How to confirm what the agent sees

**Before you start**

* [Install the CLI and sign in](https://metorial.com/docs/build/sandboxes#install-the-tools)
* A secret [API key](https://metorial.com/docs/build/api) in `METORIAL_API_KEY`
* A provider deployment ID in `METORIAL_PROVIDER_DEPLOYMENT_ID`. The examples use Metorial Search, created with `metorial-admin providers deployments create --provider-id metorial-search --name "Metorial Search"`.

## Find the tool keys

A filter names tools by key. List a provider's versions, then the tools of the latest one:

```bash
metorial-admin providers versions list --provider-id <provider-id>
metorial-admin providers tools list --provider-version-id <provider-version-id>
```

Metorial Search has two tools, `webSearch` and `getWebContent`.

## Filter one session

Install the SDK and an adapter:

**TypeScript**

```bash
npm install metorial @metorial/ai-sdk ai
```

**Python**

```bash
pip install metorial
```

This program connects with a filter and prints the tools the agent would get. Save it as `filter.ts` or `filter.py`.

**TypeScript**

```typescript
import { metorialAiSdk } from '@metorial/ai-sdk';
import Metorial from 'metorial';

let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY! });

let session = await metorial.connect({
  adapter: metorialAiSdk(),
  providers: [
    {
      providerDeploymentId: process.env.METORIAL_PROVIDER_DEPLOYMENT_ID!,
      toolFilters: [{ type: 'tool_keys', keys: ['webSearch'] }]
    }
  ]
});

console.log(Object.keys(session.tools()).join(', '));
```

**Python**

```python
import asyncio
import os

from metorial import Metorial, metorial_openai


async def main():
    metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])

    session = await metorial.connect(
        adapter=metorial_openai(),
        providers=[
            {
                "provider_deployment_id": os.environ["METORIAL_PROVIDER_DEPLOYMENT_ID"],
                "tool_filters": [{"type": "tool_keys", "keys": ["webSearch"]}],
            }
        ],
    )

    print(", ".join(tool["function"]["name"] for tool in session.tools()))


asyncio.run(main())
```

Filter types for tools:

* `tool_keys`: an exact list, `{ type: 'tool_keys', keys: ['webSearch'] }`.
* `tool_regex`: a pattern, matched without regard to case, `{ type: 'tool_regex', pattern: '^(list|get|search)' }`.
* `tool_categories`: the provider's own tool categories, `{ type: 'tool_categories', keys: ['<category-key>'] }`.

A tool passes when any rule in the list matches it. Each provider entry has its own filter, so one session can give full access to one app and read access to another.

## Filter every session of a deployment

Set the filter on the deployment and it applies to every session that uses it. A session filter can narrow it further.

```bash
metorial-admin providers deployments update pde_your_deployment_id \
  --body '{"tool_filters": [{"type": "tool_regex", "pattern": "^(list|get|search)"}]}'
```

In the dashboard, the same setting is **Tool Filters** on an integration, where you allow or reject read-only, write and destructive tools as groups. See [Create an integration](https://metorial.com/docs/platform/integrations/create-integration).

## Check it worked

The program prints the one tool you allowed, with the provider prefix, next to `metorial_connection_status`, the diagnostic tool Metorial adds to every session. The AI SDK adapter lowercases tool names, so the TypeScript program prints them in lower case.

```text
metorial_connection_status, metorial_search_webSearch
```

Without `toolFilters`, the same program also prints `metorial_search_getWebContent`.

## Troubleshooting

### `Tool access not allowed`

The agent called a tool the filter excludes, for example one it remembered from an earlier session. Add the tool's key to the filter if the agent should have it.

### The session has no tools from the provider

No tool matched. Compare the keys in your filter with the output of `metorial-admin providers tools list`.

## Next steps

* [Sessions](https://metorial.com/docs/build/operate/sessions): how providers, filters and connections fit together
* [Use tools from several apps in one session](https://metorial.com/docs/build/guides/use-tools-from-several-apps): a different filter for each provider
* [Give teams read-only access](https://metorial.com/docs/platform/guides/tool-permissions): tool filters for people who connect through a portal