@aigne/example-mcp-sqlite 1.8.0 → 1.10.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 +7 -7
- package/index.test.ts +10 -2
- package/index.ts +5 -5
- package/package.json +6 -3
- package/usages.ts +7 -7
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ The following example demonstrates how to interact with an SQLite database:
|
|
|
111
111
|
```typescript
|
|
112
112
|
import assert from "node:assert";
|
|
113
113
|
import { join } from "node:path";
|
|
114
|
-
import { AIAgent,
|
|
114
|
+
import { AIAgent, AIGNE, MCPAgent } from "@aigne/core";
|
|
115
115
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
116
116
|
|
|
117
117
|
const { OPENAI_API_KEY } = process.env;
|
|
@@ -126,9 +126,9 @@ const sqlite = await MCPAgent.from({
|
|
|
126
126
|
args: ["-q", "mcp-server-sqlite", "--db-path", join(process.cwd(), "usages.db")],
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
const
|
|
129
|
+
const aigne = new AIGNE({
|
|
130
130
|
model,
|
|
131
|
-
|
|
131
|
+
skills: [sqlite],
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
const agent = AIAgent.from({
|
|
@@ -136,26 +136,26 @@ const agent = AIAgent.from({
|
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
console.log(
|
|
139
|
-
await
|
|
139
|
+
await aigne.invoke(agent, "create a product table with columns name description and createdAt"),
|
|
140
140
|
);
|
|
141
141
|
// output:
|
|
142
142
|
// {
|
|
143
143
|
// $message: "The product table has been created successfully with the columns: `name`, `description`, and `createdAt`.",
|
|
144
144
|
// }
|
|
145
145
|
|
|
146
|
-
console.log(await
|
|
146
|
+
console.log(await aigne.invoke(agent, "create 10 products for test"));
|
|
147
147
|
// output:
|
|
148
148
|
// {
|
|
149
149
|
// $message: "I have successfully created 10 test products in the database. Here are the products that were added:\n\n1. Product 1: $10.99 - Description for Product 1\n2. Product 2: $15.99 - Description for Product 2\n3. Product 3: $20.99 - Description for Product 3\n4. Product 4: $25.99 - Description for Product 4\n5. Product 5: $30.99 - Description for Product 5\n6. Product 6: $35.99 - Description for Product 6\n7. Product 7: $40.99 - Description for Product 7\n8. Product 8: $45.99 - Description for Product 8\n9. Product 9: $50.99 - Description for Product 9\n10. Product 10: $55.99 - Description for Product 10\n\nIf you need any further assistance or operations, feel free to ask!",
|
|
150
150
|
// }
|
|
151
151
|
|
|
152
|
-
console.log(await
|
|
152
|
+
console.log(await aigne.invoke(agent, "how many products?"));
|
|
153
153
|
// output:
|
|
154
154
|
// {
|
|
155
155
|
// $message: "There are 10 products in the database.",
|
|
156
156
|
// }
|
|
157
157
|
|
|
158
|
-
await
|
|
158
|
+
await aigne.shutdown();
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
## License
|
package/index.test.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import { test } from "bun:test";
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { runExampleTest } from "@aigne/test-utils/run-example-test.js";
|
|
2
3
|
|
|
3
|
-
test(
|
|
4
|
+
test(
|
|
5
|
+
"should successfully run the mcp-sqlite",
|
|
6
|
+
async () => {
|
|
7
|
+
const { code } = await runExampleTest();
|
|
8
|
+
expect(code).toBe(0);
|
|
9
|
+
},
|
|
10
|
+
{ timeout: 600000 },
|
|
11
|
+
);
|
package/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { runChatLoopInTerminal } from "@aigne/cli/utils/run-chat-loop.js";
|
|
5
|
-
import { AIAgent,
|
|
5
|
+
import { AIAgent, AIGNE, MCPAgent, PromptBuilder } from "@aigne/core";
|
|
6
6
|
import { loadModel } from "@aigne/core/loader/index.js";
|
|
7
7
|
import { logger } from "@aigne/core/utils/logger.js";
|
|
8
8
|
|
|
@@ -20,12 +20,12 @@ const sqlite = await MCPAgent.from({
|
|
|
20
20
|
],
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
const prompt = await sqlite.prompts["mcp-demo"]?.
|
|
23
|
+
const prompt = await sqlite.prompts["mcp-demo"]?.invoke({ topic: "product service" });
|
|
24
24
|
if (!prompt) throw new Error("Prompt mcp-demo not found");
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const aigne = new AIGNE({
|
|
27
27
|
model,
|
|
28
|
-
|
|
28
|
+
skills: [sqlite],
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
const agent = AIAgent.from({
|
|
@@ -33,7 +33,7 @@ const agent = AIAgent.from({
|
|
|
33
33
|
memory: true,
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
const userAgent =
|
|
36
|
+
const userAgent = aigne.invoke(agent);
|
|
37
37
|
|
|
38
38
|
await runChatLoopInTerminal(userAgent, {
|
|
39
39
|
initialCall: {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-mcp-sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework and Sqlite MCP Server to interact with a SQLite database",
|
|
5
5
|
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
6
6
|
"homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/mcp-sqlite",
|
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"openai": "^4.94.0",
|
|
20
20
|
"zod": "^3.24.2",
|
|
21
|
-
"@aigne/
|
|
22
|
-
"@aigne/
|
|
21
|
+
"@aigne/core": "^1.13.0",
|
|
22
|
+
"@aigne/cli": "^1.8.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@aigne/test-utils": "^0.1.0"
|
|
23
26
|
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"start": "bun run index.ts",
|
package/usages.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { AIAgent,
|
|
3
|
+
import { AIAgent, AIGNE, MCPAgent } from "@aigne/core";
|
|
4
4
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
5
5
|
|
|
6
6
|
const { OPENAI_API_KEY } = process.env;
|
|
@@ -15,9 +15,9 @@ const sqlite = await MCPAgent.from({
|
|
|
15
15
|
args: ["-q", "mcp-server-sqlite", "--db-path", join(process.cwd(), "usages.db")],
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const aigne = new AIGNE({
|
|
19
19
|
model,
|
|
20
|
-
|
|
20
|
+
skills: [sqlite],
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
const agent = AIAgent.from({
|
|
@@ -25,23 +25,23 @@ const agent = AIAgent.from({
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
console.log(
|
|
28
|
-
await
|
|
28
|
+
await aigne.invoke(agent, "create a product table with columns name description and createdAt"),
|
|
29
29
|
);
|
|
30
30
|
// output:
|
|
31
31
|
// {
|
|
32
32
|
// $message: "The product table has been created successfully with the columns: `name`, `description`, and `createdAt`.",
|
|
33
33
|
// }
|
|
34
34
|
|
|
35
|
-
console.log(await
|
|
35
|
+
console.log(await aigne.invoke(agent, "create 10 products for test"));
|
|
36
36
|
// output:
|
|
37
37
|
// {
|
|
38
38
|
// $message: "I have successfully created 10 test products in the database. Here are the products that were added:\n\n1. Product 1: $10.99 - Description for Product 1\n2. Product 2: $15.99 - Description for Product 2\n3. Product 3: $20.99 - Description for Product 3\n4. Product 4: $25.99 - Description for Product 4\n5. Product 5: $30.99 - Description for Product 5\n6. Product 6: $35.99 - Description for Product 6\n7. Product 7: $40.99 - Description for Product 7\n8. Product 8: $45.99 - Description for Product 8\n9. Product 9: $50.99 - Description for Product 9\n10. Product 10: $55.99 - Description for Product 10\n\nIf you need any further assistance or operations, feel free to ask!",
|
|
39
39
|
// }
|
|
40
40
|
|
|
41
|
-
console.log(await
|
|
41
|
+
console.log(await aigne.invoke(agent, "how many products?"));
|
|
42
42
|
// output:
|
|
43
43
|
// {
|
|
44
44
|
// $message: "There are 10 products in the database.",
|
|
45
45
|
// }
|
|
46
46
|
|
|
47
|
-
await
|
|
47
|
+
await aigne.shutdown();
|