mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-15 06:52:45 -04:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cbdf71669 | |||
| ead657aedd | |||
| f5e4d098b0 | |||
| 4d97226e50 | |||
| 4999df18cc |
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/doc
|
# @llamaindex/doc
|
||||||
|
|
||||||
|
## 0.2.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.2.4
|
## 0.2.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/doc",
|
"name": "@llamaindex/doc",
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "fumadocs-mdx",
|
"postinstall": "fumadocs-mdx",
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"hast-util-to-jsx-runtime": "^2.3.2",
|
"hast-util-to-jsx-runtime": "^2.3.2",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"lucide-react": "^0.460.0",
|
"lucide-react": "^0.460.0",
|
||||||
"next": "^15.2.1",
|
"next": "^15.2.4",
|
||||||
"next-themes": "^0.4.3",
|
"next-themes": "^0.4.3",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/cloudflare-worker-agent-test
|
# @llamaindex/cloudflare-worker-agent-test
|
||||||
|
|
||||||
|
## 0.0.150
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.149
|
## 0.0.149
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||||
"version": "0.0.149",
|
"version": "0.0.150",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/next-agent-test
|
# @llamaindex/next-agent-test
|
||||||
|
|
||||||
|
## 0.1.150
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.1.149
|
## 0.1.149
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/next-agent-test",
|
"name": "@llamaindex/next-agent-test",
|
||||||
"version": "0.1.149",
|
"version": "0.1.150",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ai": "^4.0.0",
|
"ai": "^4.0.0",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "15.2.0",
|
"next": "^15.2.4",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "19.0.0"
|
"react-dom": "19.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# test-edge-runtime
|
# test-edge-runtime
|
||||||
|
|
||||||
|
## 0.1.149
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.1.148
|
## 0.1.148
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||||
"version": "0.1.148",
|
"version": "0.1.149",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "15.2.0",
|
"next": "^15.2.4",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0"
|
"react-dom": "^19.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/next-node-runtime
|
# @llamaindex/next-node-runtime
|
||||||
|
|
||||||
|
## 0.1.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.1.15
|
## 0.1.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/next-node-runtime-test",
|
"name": "@llamaindex/next-node-runtime-test",
|
||||||
"version": "0.1.15",
|
"version": "0.1.16",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"@llamaindex/huggingface": "workspace:*",
|
"@llamaindex/huggingface": "workspace:*",
|
||||||
"@llamaindex/readers": "workspace:*",
|
"@llamaindex/readers": "workspace:*",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "15.2.0",
|
"next": "^15.2.4",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "19.0.0"
|
"react-dom": "19.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# vite-import-llamaindex
|
# vite-import-llamaindex
|
||||||
|
|
||||||
|
## 0.0.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.15
|
## 0.0.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vite-import-llamaindex",
|
"name": "vite-import-llamaindex",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.15",
|
"version": "0.0.16",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/waku-query-engine-test
|
# @llamaindex/waku-query-engine-test
|
||||||
|
|
||||||
|
## 0.0.150
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.149
|
## 0.0.149
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/waku-query-engine-test",
|
"name": "@llamaindex/waku-query-engine-test",
|
||||||
"version": "0.0.149",
|
"version": "0.0.150",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
# examples
|
# examples
|
||||||
|
|
||||||
|
## 0.3.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- Updated dependencies [ead657a]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
- @llamaindex/tools@0.0.5
|
||||||
|
|
||||||
## 0.3.2
|
## 0.3.2
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { openai } from "@llamaindex/openai";
|
||||||
|
import { mcp } from "@llamaindex/tools";
|
||||||
|
import { agent } from "llamaindex";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
// Create an MCP server for filesystem tools
|
||||||
|
const server = mcp({
|
||||||
|
command: "npx",
|
||||||
|
args: ["-y", "@modelcontextprotocol/server-filesystem", "."],
|
||||||
|
verbose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Create an agent that uses the MCP tools
|
||||||
|
const myAgent = agent({
|
||||||
|
name: "Assistant",
|
||||||
|
systemPrompt: "Use the tools to achieve the task.",
|
||||||
|
tools: await server.tools(),
|
||||||
|
llm: openai({ model: "gpt-4o" }),
|
||||||
|
verbose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Run a task
|
||||||
|
const response = await myAgent.run(
|
||||||
|
"what are the files in the current directory?",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("Agent response:", response.data);
|
||||||
|
} finally {
|
||||||
|
await server.cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(console.error);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/examples",
|
"name": "@llamaindex/examples",
|
||||||
"version": "0.3.2",
|
"version": "0.3.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
"@llamaindex/jinaai": "^0.0.8",
|
"@llamaindex/jinaai": "^0.0.8",
|
||||||
"@llamaindex/perplexity": "^0.0.5",
|
"@llamaindex/perplexity": "^0.0.5",
|
||||||
"@llamaindex/supabase": "^0.1.1",
|
"@llamaindex/supabase": "^0.1.1",
|
||||||
"@llamaindex/tools": "^0.0.4",
|
"@llamaindex/tools": "^0.0.5",
|
||||||
"@notionhq/client": "^2.2.15",
|
"@notionhq/client": "^2.2.15",
|
||||||
"@pinecone-database/pinecone": "^4.0.0",
|
"@pinecone-database/pinecone": "^4.0.0",
|
||||||
"@vercel/postgres": "^0.10.0",
|
"@vercel/postgres": "^0.10.0",
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
"commander": "^12.1.0",
|
"commander": "^12.1.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"js-tiktoken": "^1.0.14",
|
"js-tiktoken": "^1.0.14",
|
||||||
"llamaindex": "^0.9.15",
|
"llamaindex": "^0.9.16",
|
||||||
"mongodb": "6.7.0",
|
"mongodb": "6.7.0",
|
||||||
"postgres": "^3.4.4",
|
"postgres": "^3.4.4",
|
||||||
"wikipedia": "^2.1.2",
|
"wikipedia": "^2.1.2",
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/autotool
|
# @llamaindex/autotool
|
||||||
|
|
||||||
|
## 6.0.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 6.0.15
|
## 6.0.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
# @llamaindex/autotool-01-node-example
|
# @llamaindex/autotool-01-node-example
|
||||||
|
|
||||||
|
## 0.0.97
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [4999df1]
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- @llamaindex/autotool@6.0.16
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.96
|
## 0.0.96
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -13,5 +13,5 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||||
},
|
},
|
||||||
"version": "0.0.96"
|
"version": "0.0.97"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
"url": "git+https://github.com/run-llama/LlamaIndexTS.git",
|
||||||
"directory": "packages/autotool"
|
"directory": "packages/autotool"
|
||||||
},
|
},
|
||||||
"version": "6.0.15",
|
"version": "6.0.16",
|
||||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"bunchee": "6.4.0",
|
"bunchee": "6.4.0",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "15.2.0",
|
"next": "^15.2.4",
|
||||||
"rollup": "^4.28.1",
|
"rollup": "^4.28.1",
|
||||||
"tsx": "^4.19.3",
|
"tsx": "^4.19.3",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/experimental
|
# @llamaindex/experimental
|
||||||
|
|
||||||
|
## 0.0.166
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.165
|
## 0.0.165
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/experimental",
|
"name": "@llamaindex/experimental",
|
||||||
"description": "Experimental package for LlamaIndexTS",
|
"description": "Experimental package for LlamaIndexTS",
|
||||||
"version": "0.0.165",
|
"version": "0.0.166",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/type/index.d.ts",
|
"types": "dist/type/index.d.ts",
|
||||||
"main": "dist/cjs/index.js",
|
"main": "dist/cjs/index.js",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# llamaindex
|
# llamaindex
|
||||||
|
|
||||||
|
## 0.9.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- f5e4d09: Remove gpt-tokenizer from llamaindex
|
||||||
|
|
||||||
## 0.9.15
|
## 0.9.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "llamaindex",
|
"name": "llamaindex",
|
||||||
"version": "0.9.15",
|
"version": "0.9.16",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -29,7 +29,6 @@
|
|||||||
"@types/lodash": "^4.17.7",
|
"@types/lodash": "^4.17.7",
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
"ajv": "^8.17.1",
|
"ajv": "^8.17.1",
|
||||||
"gpt-tokenizer": "^2.6.2",
|
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"magic-bytes.js": "^1.10.0"
|
"magic-bytes.js": "^1.10.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @llamaindex/server
|
# @llamaindex/server
|
||||||
|
|
||||||
|
## 0.0.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4999df1: bump nextjs
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.0.6
|
## 0.0.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/server",
|
"name": "@llamaindex/server",
|
||||||
"description": "LlamaIndex Server",
|
"description": "LlamaIndex Server",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"ai": "^4.2.0",
|
"ai": "^4.2.0",
|
||||||
"@llamaindex/env": "workspace:*",
|
"@llamaindex/env": "workspace:*",
|
||||||
"llamaindex": "workspace:*",
|
"llamaindex": "workspace:*",
|
||||||
"next": "15.2.3",
|
"next": "^15.2.4",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"@radix-ui/react-tabs": "^1.1.0",
|
"@radix-ui/react-tabs": "^1.1.0",
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @llamaindex/tools
|
# @llamaindex/tools
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ead657a: Add adapter to use stdio MCP server as tools
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/tools",
|
"name": "@llamaindex/tools",
|
||||||
"description": "LlamaIndex Tools",
|
"description": "LlamaIndex Tools",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
"@apidevtools/swagger-parser": "^10.1.0",
|
"@apidevtools/swagger-parser": "^10.1.0",
|
||||||
"@llamaindex/core": "workspace:*",
|
"@llamaindex/core": "workspace:*",
|
||||||
"@llamaindex/env": "workspace:*",
|
"@llamaindex/env": "workspace:*",
|
||||||
|
"@modelcontextprotocol/sdk": "^1.8.0",
|
||||||
"@e2b/code-interpreter": "^1.0.4",
|
"@e2b/code-interpreter": "^1.0.4",
|
||||||
"duck-duck-scrape": "^2.2.5",
|
"duck-duck-scrape": "^2.2.5",
|
||||||
"papaparse": "^5.4.1",
|
"papaparse": "^5.4.1",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export * from "./tools/duckduckgo";
|
|||||||
export * from "./tools/form-filling";
|
export * from "./tools/form-filling";
|
||||||
export * from "./tools/img-gen";
|
export * from "./tools/img-gen";
|
||||||
export * from "./tools/interpreter";
|
export * from "./tools/interpreter";
|
||||||
|
export * from "./tools/mcp";
|
||||||
export * from "./tools/openapi-action";
|
export * from "./tools/openapi-action";
|
||||||
export * from "./tools/weather";
|
export * from "./tools/weather";
|
||||||
export * from "./tools/wiki";
|
export * from "./tools/wiki";
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import type { JSONValue } from "@llamaindex/core/global";
|
||||||
|
import type { BaseToolWithCall } from "@llamaindex/core/llms";
|
||||||
|
import { FunctionTool } from "@llamaindex/core/tools";
|
||||||
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||||
|
import {
|
||||||
|
StdioClientTransport,
|
||||||
|
type StdioServerParameters,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||||
|
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
||||||
|
import type { JSONSchemaType } from "ajv";
|
||||||
|
|
||||||
|
interface ToolInput {
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
type MCPClientOptions = StdioServerParameters & {
|
||||||
|
/**
|
||||||
|
* The prefix to add to the tool name
|
||||||
|
*/
|
||||||
|
toolNamePrefix?: string;
|
||||||
|
/**
|
||||||
|
* The name of the client
|
||||||
|
*/
|
||||||
|
clientName?: string;
|
||||||
|
/**
|
||||||
|
* The version of the client
|
||||||
|
*/
|
||||||
|
clientVersion?: string;
|
||||||
|
/**
|
||||||
|
* Whether to log verbose output
|
||||||
|
*/
|
||||||
|
verbose?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MCPClient {
|
||||||
|
private mcp: Client;
|
||||||
|
private transport: StdioClientTransport | null = null;
|
||||||
|
private verbose: boolean;
|
||||||
|
private toolNamePrefix?: string | undefined;
|
||||||
|
|
||||||
|
constructor(options: MCPClientOptions) {
|
||||||
|
this.mcp = new Client({
|
||||||
|
name: options.clientName ?? "mcp-client-cli",
|
||||||
|
version: options.clientVersion ?? "1.0.0",
|
||||||
|
});
|
||||||
|
|
||||||
|
this.verbose = options.verbose ?? false;
|
||||||
|
this.toolNamePrefix = options.toolNamePrefix;
|
||||||
|
this.connectToSever(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
async connectToSever(options: StdioServerParameters) {
|
||||||
|
if (this.verbose) {
|
||||||
|
console.log("Connecting to MCP server...");
|
||||||
|
}
|
||||||
|
this.transport = new StdioClientTransport(options);
|
||||||
|
await this.mcp.connect(this.transport);
|
||||||
|
}
|
||||||
|
|
||||||
|
async listTools(): Promise<Tool[]> {
|
||||||
|
const tools = await this.mcp.listTools();
|
||||||
|
return tools.tools;
|
||||||
|
}
|
||||||
|
|
||||||
|
async cleanup() {
|
||||||
|
await this.mcp.close();
|
||||||
|
this.transport?.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tools from the MCP server and map to LlamaIndex tools
|
||||||
|
*/
|
||||||
|
async tools(): Promise<BaseToolWithCall[]> {
|
||||||
|
const mcpTools = await this.listTools();
|
||||||
|
return mcpTools.map((tool) => {
|
||||||
|
const parameters =
|
||||||
|
tool.inputSchema as unknown as JSONSchemaType<ToolInput>;
|
||||||
|
const functionTool = FunctionTool.from(
|
||||||
|
async (input: unknown) => {
|
||||||
|
if (this.verbose) {
|
||||||
|
console.log("Calling tool:", tool.name, "with input:", input);
|
||||||
|
}
|
||||||
|
const result = await this.mcp.callTool({
|
||||||
|
name: tool.name,
|
||||||
|
arguments: input as unknown as Record<string, unknown>,
|
||||||
|
});
|
||||||
|
if (this.verbose) {
|
||||||
|
console.log("Tool result:", result);
|
||||||
|
}
|
||||||
|
return result as JSONValue;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: this.toolNamePrefix
|
||||||
|
? `${this.toolNamePrefix}_${tool.name}`
|
||||||
|
: tool.name,
|
||||||
|
description: tool.description ?? "",
|
||||||
|
parameters,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return functionTool;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a MCP client
|
||||||
|
* @param options - The options for the MCP client
|
||||||
|
* @returns A MCP client
|
||||||
|
*/
|
||||||
|
export function mcp(options: MCPClientOptions) {
|
||||||
|
return new MCPClient(options);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { afterAll, beforeAll, describe, expect, test } from "vitest";
|
||||||
|
import { mcp } from "../src/tools/mcp";
|
||||||
|
|
||||||
|
describe("MCP Tools", () => {
|
||||||
|
let server: ReturnType<typeof mcp>;
|
||||||
|
let tempDir: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// Create a temporary directory for tests
|
||||||
|
tempDir = await mkdtemp(join(tmpdir(), "mcp-test-"));
|
||||||
|
|
||||||
|
server = mcp({
|
||||||
|
command: "npx",
|
||||||
|
args: ["-y", "@modelcontextprotocol/server-filesystem", tempDir],
|
||||||
|
toolNamePrefix: "test",
|
||||||
|
verbose: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for server to be ready by calling tools() once
|
||||||
|
await server.tools();
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
// Clean up server resources
|
||||||
|
await server.cleanup();
|
||||||
|
// Remove temporary directory
|
||||||
|
await rm(tempDir, { recursive: true, force: true });
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
test("MCP should list tools", async () => {
|
||||||
|
const tools = await server.tools();
|
||||||
|
expect(tools.length).toBeGreaterThan(0);
|
||||||
|
}, 20000);
|
||||||
|
|
||||||
|
test("MCP should call a tool to list files in a directory", async () => {
|
||||||
|
const tools = await server.tools();
|
||||||
|
const listDirectoryTool = tools.find(
|
||||||
|
(tool) => tool.metadata.name === "test_list_directory",
|
||||||
|
);
|
||||||
|
const result = await listDirectoryTool?.call({
|
||||||
|
path: tempDir,
|
||||||
|
});
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
}, 20000);
|
||||||
|
});
|
||||||
Generated
+470
-335
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,12 @@
|
|||||||
# @llamaindex/unit-test
|
# @llamaindex/unit-test
|
||||||
|
|
||||||
|
## 0.1.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [f5e4d09]
|
||||||
|
- llamaindex@0.9.16
|
||||||
|
|
||||||
## 0.1.15
|
## 0.1.15
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@llamaindex/unit-test",
|
"name": "@llamaindex/unit-test",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.15",
|
"version": "0.1.16",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|||||||
Reference in New Issue
Block a user