Filter tools
Public documentation preview — incomplete. The SDK and optional AI SDK peers remain private and unpublished. Ranking and filtering examples do not prove provider compatibility or grant execution permission.
filterTools({ prompt, tools, context, limit, signal }) returns scored, ordered tool descriptors. Use the trusted MCP-server array and policy from the shared configuration. With no configured ranker or model option, ranking is lexical and sends no prompt or catalogue to a model; server discovery may still perform network I/O. Filtering never dispatches a tool.
trustedContext must come from your authenticated server, not model text or an untrusted request field. If you opt into named model ranking, add model: 'general' to the filter options: it selects models.general.ranking, checks model access and can send the prompt, schemas and tool descriptions to your configured provider. It does not use a server’s routing binding. Do not specify model and ranker together.
Returned score is ranking output, not authorization or a call argument. To reuse a ranked bound descriptor as a source for execute, remove the output-only score: const { score, ...boundDescriptor } = selected[0];. First check that the descriptor exists and remains current. Raw tool definitions can also be filtered but remain unbound; they cannot be executed simply because they were ranked.
For a fully owned router lifetime, wrap creation and filtering in try/finally with await router.close(). The source-controlled examples/code.ts module shows this pattern for maintainers with repository access; it is not a tested live MCP run. To perform one governed action, scope an execute.