# ToolRAG

> TypeScript library that uses semantic search over MCP tool definitions to give LLMs only the tools relevant to each query.

ToolRAG is an open-source TypeScript library published by the GitHub user antl3x. It connects to Model Context Protocol (MCP) servers, embeds their tool definitions, and returns only the tools relevant to a user query, formatted as OpenAI function definitions. The project is licensed under Apache 2.0.

## What It Is

ToolRAG applies a retrieval-augmented generation approach to tool selection. Instead of passing every function definition to a language model, it stores tool definitions and their vector embeddings, then retrieves the best matches for each query. The README says this lets developers work with an unlimited number of tools while avoiding context window limits, extra token costs, and the performance drop that comes from overloading a model with definitions.

## How the Workflow Runs

A developer initializes ToolRAG with a list of MCP server URLs. ToolRAG registers the tools those servers expose and generates embeddings from tool descriptions and parameters, using OpenAI or Google embedding providers. When a query arrives, `listTools(query)` returns the most relevant tools through cosine similarity search. These can be passed to an LLM call such as the OpenAI Responses API. The function calls the model returns are then run with `callTool`, which executes them against the matching MCP servers.

## Architecture and Configuration

Tool definitions and embeddings are stored in a LibSQL database. Configuration options include the embedding provider, customizable relevance thresholds, and database settings for persistence. The README lists multi-tool AI assistants, enterprise systems connecting to internal tools, and unified tool discovery platforms as intended use cases.

## Setup Path

The package is installed from npm as `@antl3x/toolrag` with npm, yarn, or pnpm. The quick start initializes ToolRAG with MCP server URLs and passes the retrieved tools to an OpenAI model.

## Features
- Dynamic selection of relevant tools per query
- Semantic tool search using vector embeddings
- Reduced token usage by including only relevant function definitions
- Works with MCP-compliant servers
- Formats tools as OpenAI function definitions
- Executes selected tools against MCP servers
- LibSQL storage for tool definitions and embeddings
- Multiple embedding providers (OpenAI, Google)
- Customizable relevance thresholds
- Database configuration for persistence

## Integrations
Model Context Protocol (MCP), OpenAI, Google, LibSQL, Pipedream MCP

## Platforms
DEVELOPER_SDK

## Pricing
Open Source

## Links
- Website: https://github.com/antl3x/ToolRAG
- Documentation: https://github.com/antl3x/ToolRAG#readme
- Repository: https://github.com/antl3x/ToolRAG
- EveryDev.ai: https://www.everydev.ai/tools/toolrag
