groq-rag 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/dist/index.cjs +704 -2
- package/dist/index.d.cts +403 -2
- package/dist/index.d.ts +403 -2
- package/dist/index.js +696 -2
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
[](https://nodejs.org/)
|
|
8
8
|
[](https://groq-rag.onrender.com)
|
|
9
9
|
[](https://github.com/groq/groq-typescript)
|
|
10
|
+
[](https://context7.com/mithun50/groq-rag)
|
|
11
|
+
[](#benchmarks)
|
|
12
|
+
[](#benchmarks)
|
|
10
13
|
|
|
11
14
|
Extended [Groq TypeScript SDK](https://github.com/groq/groq-typescript) with RAG (Retrieval-Augmented Generation), web browsing, and autonomous agent capabilities. Build intelligent AI applications that can search the web, fetch URLs, query knowledge bases, and reason through complex tasks.
|
|
12
15
|
|
|
@@ -49,6 +52,7 @@ groq-rag is built on top of the official [Groq TypeScript SDK](https://github.co
|
|
|
49
52
|
- [Chat Module](#chat-module)
|
|
50
53
|
- [Agent System](#agent-system)
|
|
51
54
|
- [Tool System](#tool-system)
|
|
55
|
+
- [MCP Integration](#mcp-integration)
|
|
52
56
|
- [Configuration](#configuration)
|
|
53
57
|
- [Vector Stores](#vector-stores)
|
|
54
58
|
- [Embedding Providers](#embedding-providers)
|
|
@@ -71,6 +75,7 @@ groq-rag is built on top of the official [Groq TypeScript SDK](https://github.co
|
|
|
71
75
|
| **Web Search** | DuckDuckGo (free), Brave Search, and Serper (Google) integration |
|
|
72
76
|
| **Agent System** | ReAct-style autonomous agents with tool use, memory, and streaming |
|
|
73
77
|
| **Tool Framework** | Extensible tool system with built-in and custom tools |
|
|
78
|
+
| **MCP Integration** | Connect to Model Context Protocol servers for external tool access |
|
|
74
79
|
| **Content Limiting** | Optional token/character limits to control API costs |
|
|
75
80
|
| **TypeScript** | Full type safety with comprehensive IntelliSense support |
|
|
76
81
|
| **Zero Config** | Works out of the box with sensible defaults |
|
|
@@ -633,6 +638,111 @@ executor.register(anotherTool);
|
|
|
633
638
|
const result = await executor.execute('my_tool', { input: 'hello' });
|
|
634
639
|
```
|
|
635
640
|
|
|
641
|
+
---
|
|
642
|
+
|
|
643
|
+
### MCP Integration
|
|
644
|
+
|
|
645
|
+
Connect to [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers to use external tools from the MCP ecosystem.
|
|
646
|
+
|
|
647
|
+
#### Adding MCP Servers
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
const client = new GroqRAG();
|
|
651
|
+
|
|
652
|
+
// Add an MCP server (stdio transport)
|
|
653
|
+
await client.mcp.addServer({
|
|
654
|
+
name: 'filesystem',
|
|
655
|
+
transport: 'stdio',
|
|
656
|
+
command: 'npx',
|
|
657
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', './data'],
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
// Add another MCP server (e.g., GitHub)
|
|
661
|
+
await client.mcp.addServer({
|
|
662
|
+
name: 'github',
|
|
663
|
+
transport: 'stdio',
|
|
664
|
+
command: 'npx',
|
|
665
|
+
args: ['-y', '@modelcontextprotocol/server-github'],
|
|
666
|
+
env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN },
|
|
667
|
+
});
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
#### Using MCP Tools with Agents
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
// Create agent with built-in + MCP tools
|
|
674
|
+
const agent = await client.createAgentWithBuiltins(
|
|
675
|
+
{ model: 'llama-3.3-70b-versatile', verbose: true },
|
|
676
|
+
{ includeMCP: true }
|
|
677
|
+
);
|
|
678
|
+
|
|
679
|
+
// Agent can now use tools from all connected MCP servers
|
|
680
|
+
const result = await agent.run('List files in the data directory');
|
|
681
|
+
|
|
682
|
+
// Cleanup when done
|
|
683
|
+
await client.mcp.disconnectAll();
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
#### MCP Server Configuration
|
|
687
|
+
|
|
688
|
+
| Option | Type | Description |
|
|
689
|
+
|--------|------|-------------|
|
|
690
|
+
| `name` | string | Unique name for the server |
|
|
691
|
+
| `transport` | 'stdio' \| 'http' | Transport protocol |
|
|
692
|
+
| `command` | string | Command to run (stdio) |
|
|
693
|
+
| `args` | string[] | Command arguments (stdio) |
|
|
694
|
+
| `env` | object | Environment variables (stdio) |
|
|
695
|
+
| `url` | string | Server URL (http) |
|
|
696
|
+
| `timeout` | number | Connection timeout (ms) |
|
|
697
|
+
|
|
698
|
+
#### Standalone MCP Client
|
|
699
|
+
|
|
700
|
+
```typescript
|
|
701
|
+
import { createMCPClient } from 'groq-rag';
|
|
702
|
+
|
|
703
|
+
// Create and connect to an MCP server
|
|
704
|
+
const mcpClient = createMCPClient({
|
|
705
|
+
name: 'filesystem',
|
|
706
|
+
transport: 'stdio',
|
|
707
|
+
command: 'npx',
|
|
708
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', '.'],
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
await mcpClient.connect();
|
|
712
|
+
|
|
713
|
+
// Get tools as ToolDefinitions for use with any agent
|
|
714
|
+
const tools = mcpClient.getToolsAsDefinitions();
|
|
715
|
+
console.log('Available tools:', tools.map(t => t.name));
|
|
716
|
+
|
|
717
|
+
// Call a tool directly
|
|
718
|
+
const result = await mcpClient.callTool('read_file', { path: './README.md' });
|
|
719
|
+
|
|
720
|
+
await mcpClient.disconnect();
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
#### MCP Module Methods
|
|
724
|
+
|
|
725
|
+
| Method | Description |
|
|
726
|
+
|--------|-------------|
|
|
727
|
+
| `client.mcp.addServer(config)` | Connect to an MCP server |
|
|
728
|
+
| `client.mcp.removeServer(name)` | Disconnect from a server |
|
|
729
|
+
| `client.mcp.getServer(name)` | Get a specific MCP client |
|
|
730
|
+
| `client.mcp.getServers()` | List all connected clients |
|
|
731
|
+
| `client.mcp.getAllTools()` | Get all tools from all servers |
|
|
732
|
+
| `client.mcp.disconnectAll()` | Disconnect from all servers |
|
|
733
|
+
|
|
734
|
+
#### Popular MCP Servers
|
|
735
|
+
|
|
736
|
+
| Server | Package | Description |
|
|
737
|
+
|--------|---------|-------------|
|
|
738
|
+
| Filesystem | `@modelcontextprotocol/server-filesystem` | Read/write local files |
|
|
739
|
+
| GitHub | `@modelcontextprotocol/server-github` | GitHub API access |
|
|
740
|
+
| Brave Search | `@modelcontextprotocol/server-brave-search` | Web search |
|
|
741
|
+
| SQLite | `@modelcontextprotocol/server-sqlite` | SQLite database |
|
|
742
|
+
| Memory | `@modelcontextprotocol/server-memory` | Persistent memory |
|
|
743
|
+
|
|
744
|
+
> See [MCP Servers](https://github.com/modelcontextprotocol/servers) for more available servers.
|
|
745
|
+
|
|
636
746
|
## Configuration
|
|
637
747
|
|
|
638
748
|
### Vector Stores
|
|
@@ -888,6 +998,7 @@ Complete examples in the [examples/](./examples) directory:
|
|
|
888
998
|
| `url-fetch.ts` | URL fetching and summarization |
|
|
889
999
|
| `agent.ts` | Agent with tools |
|
|
890
1000
|
| `streaming-agent.ts` | Streaming agent execution |
|
|
1001
|
+
| `mcp-tools.ts` | **MCP server integration** |
|
|
891
1002
|
| `full-chatbot.ts` | **Full-featured interactive CLI chatbot** |
|
|
892
1003
|
|
|
893
1004
|
### Running the Full Chatbot
|
|
@@ -937,6 +1048,10 @@ groq-rag/
|
|
|
937
1048
|
│ ├── tools/
|
|
938
1049
|
│ │ ├── executor.ts # Tool execution engine
|
|
939
1050
|
│ │ └── builtins.ts # Built-in tools
|
|
1051
|
+
│ ├── mcp/
|
|
1052
|
+
│ │ ├── client.ts # MCP client implementation
|
|
1053
|
+
│ │ ├── adapter.ts # MCP to ToolDefinition conversion
|
|
1054
|
+
│ │ └── transports/ # Stdio and HTTP transports
|
|
940
1055
|
│ ├── agents/
|
|
941
1056
|
│ │ └── agent.ts # ReAct agent implementation
|
|
942
1057
|
│ └── utils/
|
|
@@ -988,8 +1103,50 @@ npm run lint
|
|
|
988
1103
|
npm run typecheck
|
|
989
1104
|
```
|
|
990
1105
|
|
|
1106
|
+
## Benchmarks
|
|
1107
|
+
|
|
1108
|
+
Performance benchmarks for groq-rag SDK operations.
|
|
1109
|
+
|
|
1110
|
+
### Local Processing (CPU-bound)
|
|
1111
|
+
|
|
1112
|
+
| Operation | Ops/sec | Avg Time |
|
|
1113
|
+
|-----------|---------|----------|
|
|
1114
|
+
| Content Truncation | **1,743,317** | 0.0006ms |
|
|
1115
|
+
| Context Formatting | **330,914** | 0.003ms |
|
|
1116
|
+
| Text Chunking | **84,861** | 0.01ms |
|
|
1117
|
+
|
|
1118
|
+
### Network Operations (I/O-bound)
|
|
1119
|
+
|
|
1120
|
+
| Operation | Ops/sec | Avg Time |
|
|
1121
|
+
|-----------|---------|----------|
|
|
1122
|
+
| Groq Chat Completion | 5.27 | 190ms |
|
|
1123
|
+
| URL Fetch | 5.05 | 198ms |
|
|
1124
|
+
| Content Limiting (Total) | 4.87 | 205ms |
|
|
1125
|
+
| Content Limiting (Snippet) | 3.09 | 323ms |
|
|
1126
|
+
| Chat with URL | 2.61 | 383ms |
|
|
1127
|
+
| Web Search (DuckDuckGo) | 1.83 | 546ms |
|
|
1128
|
+
| Chat with Web Search | 0.98 | 1024ms |
|
|
1129
|
+
|
|
1130
|
+
> **Note**: Network operations are limited by external API latency (Groq, DuckDuckGo), not SDK performance. Local processing shows the SDK's actual code efficiency.
|
|
1131
|
+
|
|
1132
|
+
Run benchmarks:
|
|
1133
|
+
```bash
|
|
1134
|
+
npm run benchmark
|
|
1135
|
+
```
|
|
1136
|
+
|
|
991
1137
|
## Changelog
|
|
992
1138
|
|
|
1139
|
+
### v0.1.6
|
|
1140
|
+
|
|
1141
|
+
- **New Feature: MCP Integration** - Connect to Model Context Protocol servers
|
|
1142
|
+
- `client.mcp.addServer()` - Connect to MCP servers (stdio/http)
|
|
1143
|
+
- `client.mcp.getAllTools()` - Get tools from connected servers
|
|
1144
|
+
- `createAgentWithBuiltins({ includeMCP: true })` - Include MCP tools in agents
|
|
1145
|
+
- Support for `@modelcontextprotocol/server-*` packages
|
|
1146
|
+
- Standalone `createMCPClient()` for direct MCP usage
|
|
1147
|
+
- **ToolExecutor Enhancement** - Added `registerMCPTools()` and `unregisterMCPTools()`
|
|
1148
|
+
- **Tests** - Added MCP client and adapter tests
|
|
1149
|
+
|
|
993
1150
|
### v0.1.4
|
|
994
1151
|
|
|
995
1152
|
- **New Feature: Content Limiting** - Control token usage with optional limits
|