// Set of built-in tool names (from formatToolArgs in ToolCallLine.tsx).
// Any tool not in this set that has a `server_tool` name pattern is an MCP tool.
export const BUILT_IN_TOOLS = new Set([
  'view_file',
  'list_dir',
  'grep',
  'find_files',
  'git_status',
  'skill_use',
]);

/**
 * Returns true if the tool name follows the `<server>_<tool>` MCP pattern.
 * Built-in tools (view_file, grep, skill_use, etc.) are excluded even if
 * they happen to contain an underscore (e.g. 'git_status', 'skill_use').
 */
export function isMcpTool(name: string): boolean {
  return name.includes('_') && !BUILT_IN_TOOLS.has(name);
}

/**
 * Extracts the MCP server name from a tool call name.
 * For 'context7_searchWeb' returns 'context7'.
 * Returns null for native tools.
 */
export function extractServerName(name: string): string | null {
  const idx = name.indexOf('_');
  if (idx === -1) return null;
  return name.slice(0, idx);
}

/**
 * Extracts the tool name (without server prefix) from an MCP tool call name.
 * For 'context7_searchWeb' returns 'searchWeb'.
 * Returns null for native tools.
 */
export function extractToolName(name: string): string | null {
  const idx = name.indexOf('_');
  if (idx === -1) return null;
  return name.slice(idx + 1);
}
