Utility that extracts a tool name from LLM tool objects.
// Source: https://github.com/mnfst/llm-gateway | License: MIT | Copyright 2026 MNFST, Inc
// Provided via justclaw.it.com; keep this notice with the code.
// ── Input types ──
export interface ScorerMessage {
role: string;
content?: unknown;
[key: string]: unknown;
}
export interface ScorerTool {
[key: string]: unknown;
}
/**
* Extract a tool's name across the two shapes agents send: a top-level `name`
* (Anthropic-style) or a nested `function.name` (OpenAI-style). Returns null
* when neither is present.
*/
export function extractToolName(tool: ScorerTool): string | null {
if (typeof tool.name === 'string') return tool.name;
const fn = tool.function as { name?: string } | undefined;
if (fn && typeof fn.name === 'string') return fn.name;
return null;
}
export interf
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key