Chat Tool Policy Resolver (chat/chat-tool-policy.ts)

mcp-use · libraries/typescript/packages/inspector/src/client/components/chat/chat-tool-policy.ts · typescript · MIT
chat, ai, lang:typescript, tag:policy

Determines which tools are visible to an AI model based on user preferences and tool metadata. Use this to manage tool availability in chat-based AI interfaces.

// Source: https://github.com/mcp-use/mcp-use | License: MIT | Copyright 2025 pietrozullo
// Provided via justclaw.it.com; keep this notice with the code.
import { isToolVisibleToModel } from "@mcp-use/client/react";

export function resolveChatToolPolicy<
  T extends { name: string; _meta?: unknown },
>(
  tools: readonly T[],
  userDisabledTools: ReadonlySet<string>
): {
  modelVisibleTools: T[];
  effectiveDisabledTools: Set<string>;
} {
  const modelVisibleTools: T[] = [];
  const effectiveDisabledTools = new Set(userDisabledTools);

  for (const tool of tools) {
    if (isToolVisibleToModel(tool)) {
      modelVisibleTools.push(tool);
    } else {
      effectiveDisabledTools.add(tool.name);
    }
  }

  return { modelVisibleTools, effectiveDisabledTools };
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key