Ragex. Agent. ToolSchema
(Ragex v0.14.1)
View Source
Converts MCP tool definitions to AI provider tool formats.
Supports:
- OpenAI function calling format (also used by DeepSeek R1 and Ollama)
- Anthropic tool use format
Tool sets
Three tool sets are available:
- All tools (
to_openai_tools/0,to_anthropic_tools/0) — every tool defined in the MCP server. - Agent tools (
agent_tools/1,tools_for_provider/2) — curated subset suitable for autonomous agent analysis. Includes analysis, quality, search, dependency, impact, suggestion, and graph-algorithm tools. - RAG query tools (
rag_query_tools/1) — read-only subset that reads existing knowledge-graph and embedding data without triggering any heavy analysis pipeline. Used during report generation so the AI can look up code-level evidence without re-running static analysis.
Usage
# Get all tools in OpenAI format
tools = ToolSchema.to_openai_tools()
# Get curated agent tools
tools = ToolSchema.agent_tools(:openai)
# Get read-only RAG query tools for report generation
tools = ToolSchema.rag_query_tools(:anthropic)
# Lookup specific tool
{:ok, tool} = ToolSchema.tool_by_name("semantic_search")
Summary
Functions
Get list of agent tool names.
Get curated subset of tools for agent use.
Get read-only RAG query tools for a provider.
Get read-only RAG query tool names.
Get all MCP tools converted to Anthropic tool format.
Get all MCP tools converted to OpenAI function calling format.
Lookup a tool definition by name.
Convert a list of tool names to their definitions.
Get tools for a specific provider by name.
Functions
@spec agent_tool_names() :: [String.t()]
Get list of agent tool names.
Get curated subset of tools for agent use.
Parameters
format- Output format::openai(default, also for DeepSeek) or:anthropic
Returns
List of tool definitions in the requested format.
Get read-only RAG query tools for a provider.
Same as tools_for_provider/2 restricted to @rag_tool_names.
Useful for report generation where the AI should retrieve context
but not re-run the full analysis pipeline.
@spec rag_tool_names() :: [String.t()]
Get read-only RAG query tool names.
These tools read from the existing knowledge graph and embeddings without triggering any heavy analysis pipeline.
@spec to_anthropic_tools() :: [map()]
Get all MCP tools converted to Anthropic tool format.
Returns
List of tool definitions in Anthropic format:
[
%{
name: "tool_name",
description: "Tool description",
input_schema: %{...json_schema...}
}
]
@spec to_openai_tools() :: [map()]
Get all MCP tools converted to OpenAI function calling format.
This format is also compatible with DeepSeek R1.
Returns
List of tool definitions in OpenAI format:
[
%{
type: "function",
function: %{
name: "tool_name",
description: "Tool description",
parameters: %{...json_schema...}
}
}
]
Lookup a tool definition by name.
Parameters
name- Tool name as stringformat- Output format::openai,:anthropic, or:mcp(default)
Returns
{:ok, tool}- Tool definition in requested format{:error, :not_found}- Tool not found
Convert a list of tool names to their definitions.
Parameters
names- List of tool namesformat- Output format
Returns
List of tool definitions (skips unknown tools).
Get tools for a specific provider by name.
Parameters
provider- Provider atom::deepseek_r1,:openai,:anthropic,:ollamaopts- Options::only- List of tool names to include (default: all agent tools):except- List of tool names to exclude
Returns
List of tool definitions in the appropriate format for the provider.