{"id":33295181,"url":"https://github.com/rocket-connect/mcp-rag","last_synced_at":"2025-11-18T02:03:10.170Z","repository":{"id":324740974,"uuid":"1095479461","full_name":"rocket-connect/mcp-rag","owner":"rocket-connect","description":"A lightweight wrapper around AI SDK that intelligently indexes and retrieves MCP tools using graph-based vector search.","archived":false,"fork":false,"pushed_at":"2025-11-17T15:28:07.000Z","size":1176,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-17T17:20:19.530Z","etag":null,"topics":["ai","augmented","characters","embeddings","generative-ai","limits","mcp","neo4j","performance","rag","scale","tools","vector-search"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocket-connect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"rocket-connect"}},"created_at":"2025-11-13T05:25:12.000Z","updated_at":"2025-11-17T15:28:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rocket-connect/mcp-rag","commit_stats":null,"previous_names":["rocket-connect/mcp-rag"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/rocket-connect/mcp-rag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket-connect%2Fmcp-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket-connect%2Fmcp-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket-connect%2Fmcp-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket-connect%2Fmcp-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocket-connect","download_url":"https://codeload.github.com/rocket-connect/mcp-rag/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocket-connect%2Fmcp-rag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284988465,"owners_count":27095952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-18T02:00:05.759Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","augmented","characters","embeddings","generative-ai","limits","mcp","neo4j","performance","rag","scale","tools","vector-search"],"created_at":"2025-11-18T02:01:08.410Z","updated_at":"2025-11-18T02:03:10.159Z","avatar_url":"https://github.com/rocket-connect.png","language":"TypeScript","readme":"# MCP RAG\n\nA lightweight wrapper around AI SDK that intelligently indexes and retrieves MCP tools using graph-based vector search.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/docs/neo4j-model.png\" alt=\"Neo4j Model\" width=\"80%\" /\u003e\n\u003c/div\u003e\n\n## What It Does\n\nMCP RAG indexes your MCP toolset into a graph structure and uses Neo4j-powered vector search to retrieve relevant tool subsets from large collections. This dramatically reduces context overhead when working with extensive tool libraries.\n\nSee our [benchmarks](./benchmarks/latest.md) for performance improvements.\n\n## Benchmarks\n\nMCP RAG sees improvements in both efficiency and performance compared to baseline tool selection, while maintaining the same level of accuracy.\n\n**Benchmark Methodology:** Tests simulate a realistic conversation with 5 sequential prompts, each triggering a different tool as context accumulates—mirroring real-world multi-turn interactions. All tests use the complete toolset from the [GitHub MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/github) (90+ tools) to represent authentic large-scale tool selection scenarios.\n\nSee the proof in the pudding:\n\n**[Base Tool Selection Results](./benchmarks/results/base-tool-selection/latest.md)** - Baseline approach passing all tools to the model.\n\n**[RAG Tool Selection Results](./benchmarks/results/rag-tool-selection/latest.md)** - RAG-powered intelligent filtering with vector search.\n\n**[View Test Suite](./benchmarks/src/rag.test.ts)** - Complete benchmark implementation and test cases.\n\n## Installation\n\n[![npm version](https://badge.fury.io/js/@mcp-rag%2Fclient.svg)](https://badge.fury.io/js/@mcp-rag%2Fclient)\n\n```bash\nnpm install @mcp-rag/client @ai-sdk/openai neo4j-driver ai\n```\n\nSet your OpenAI API key:\n\n```bash\nexport OPENAI_API_KEY=your_key_here\n```\n\n## Quick Start\n\n```typescript\nimport { createMCPRag } from '@mcp-rag/client'\nimport { openai } from '@ai-sdk/openai'\nimport neo4j from 'neo4j-driver'\nimport { tool } from 'ai'\nimport { z } from 'zod'\n\nconst driver = neo4j.driver(\n  'neo4j://localhost:7687',\n  neo4j.auth.basic('neo4j', 'password')\n)\n\nconst rag = createMCPRag({\n  model: openai('gpt-4'),\n  neo4j: driver,\n  tools: {\n    searchDocs: tool({\n      /* ... */\n    }),\n    queryDatabase: tool({\n      /* ... */\n    }),\n    sendEmail: tool({\n      /* ... */\n    }),\n    fetchWeather: tool({\n      /* ... */\n    }),\n    analyzeImage: tool({\n      /* ... */\n    }),\n    // ... hundreds more tools\n  },\n})\n\nawait rag.sync()\nconst result = await rag.generateText({\n  prompt: 'Search for API docs',\n})\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eWhat does \u003ccode\u003erag.sync()\u003c/code\u003e do?\u003c/strong\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\nThe `sync()` method performs a complete synchronization of your tools to Neo4j, creating the graph structure needed for semantic search. Here's what happens under the hood:\n\n1. **Creates Vector Index**: Sets up a Neo4j vector index for similarity search using 1536-dimensional embeddings (OpenAI's `text-embedding-3-small` model)\n\n2. **Generates Embeddings**: For each tool in your toolset, it creates embeddings for:\n   - The tool itself (name + description)\n   - Each parameter (name + description)\n   - The return type\n\n3. **Builds Graph Structure**: Creates a graph in Neo4j with the following relationships:\n   - `ToolSet` nodes that group tools together\n   - `Tool` nodes with their embeddings\n   - `Parameter` nodes connected to tools via `HAS_PARAM` relationships\n   - `ReturnType` nodes connected to tools via `RETURNS` relationships\n\n4. **Idempotent by Design**: The sync process uses `MERGE` operations, so running it multiple times won't create duplicates. It will update existing nodes if the toolset has changed.\n\n**When to call it:**\n\n- After initial client creation (required before first use)\n- After adding or removing tools with `addTool()` or `removeTool()`\n- To force a re-index of your tools\n\nThe sync process is optimized to only run when necessary - subsequent calls to `generateText()` won't re-sync unless you explicitly call `sync()` again or modify the toolset.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eWhat does \u003ccode\u003erag.generateText()\u003c/code\u003e do?\u003c/strong\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\nThe `generateText()` method is a smart wrapper around the AI SDK's `generateText` function that adds automatic tool selection. Here's the workflow:\n\n1. **Ensures Migration**: Automatically calls the sync process if tools haven't been indexed yet\n\n2. **Semantic Tool Selection**:\n   - Generates an embedding for your prompt\n   - Performs a Neo4j vector similarity search to find the most relevant tools\n   - By default, selects up to 10 tools (configurable via `maxActiveTools`)\n   - You can override this by passing `activeTools` array explicitly\n\n3. **Calls AI SDK**: Passes only the selected subset of tools to the AI SDK's native `generateText` function along with your prompt and any additional options\n\n4. **Returns Full Result**: Returns the complete AI SDK result wrapped in a `GenerateTextResultWrapper` object, giving you access to:\n   - Tool calls made by the model\n   - Token usage statistics\n   - Response content\n   - All other AI SDK metadata\n\n**Key Benefits:**\n\n- **Reduced Context Size**: Only relevant tools are sent to the LLM, saving tokens\n- **Better Performance**: Fewer tools mean faster response times\n- **Same AI SDK Experience**: Accepts all standard AI SDK parameters and returns familiar result structures\n\n\u003c/details\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/docs/example-tools-model.png\" alt=\"Tools Select Model\" width=\"80%\" /\u003e\n\u003c/div\u003e\n\n## Features\n\n- **Graph-based indexing** – Tools are indexed with their relationships and metadata\n- **Vector search** – Neo4j-powered semantic search for tool retrieval\n- **AI SDK compatible** – Drop-in wrapper that works with your existing AI SDK setup\n- **Selective loading** – Only load the tools you need for each request\n\n## License\n\nMIT [rconnect.tech](https://www.rconnect.tech)\n","funding_links":["https://github.com/sponsors/rocket-connect"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocket-connect%2Fmcp-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocket-connect%2Fmcp-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocket-connect%2Fmcp-rag/lists"}