@aigne/example-mcp-sqlite 1.11.1 → 1.12.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.
Files changed (4) hide show
  1. package/README.md +44 -3
  2. package/index.ts +32 -37
  3. package/package.json +6 -6
  4. package/usages.ts +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sqlite MCP Server Demo
2
2
 
3
- This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) and [MCP Server SQlite](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite) to interact with SQLite databases.
3
+ This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) and [MCP Server SQlite](https://github.com/modelcontextprotocol/servers/tree/main/src/sqlite) to interact with SQLite databases. The example now supports both one-shot and interactive chat modes, along with customizable model settings and pipeline input/output.
4
4
 
5
5
  ```mermaid
6
6
  flowchart LR
@@ -71,7 +71,14 @@ AI ->> User: There are 10 products in the database.
71
71
  ```bash
72
72
  export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # Set your OpenAI API key
73
73
 
74
- npx -y @aigne/example-mcp-sqlite # Run the example
74
+ # Run in one-shot mode (default)
75
+ npx -y @aigne/example-mcp-sqlite
76
+
77
+ # Run in interactive chat mode
78
+ npx -y @aigne/example-mcp-sqlite --chat
79
+
80
+ # Use pipeline input
81
+ echo "create a product table with columns name description and createdAt" | npx -y @aigne/example-mcp-sqlite
75
82
  ```
76
83
 
77
84
  ## Installation
@@ -101,7 +108,41 @@ OPENAI_API_KEY="" # Set your OpenAI API key here
101
108
  ### Run the Example
102
109
 
103
110
  ```bash
104
- pnpm start
111
+ pnpm start # Run in one-shot mode (default)
112
+
113
+ # Run in interactive chat mode
114
+ pnpm start -- --chat
115
+
116
+ # Use pipeline input
117
+ echo "create a product table with columns name description and createdAt" | pnpm start
118
+ ```
119
+
120
+ ### Run Options
121
+
122
+ The example supports the following command-line parameters:
123
+
124
+ | Parameter | Description | Default |
125
+ |-----------|-------------|---------|
126
+ | `--chat` | Run in interactive chat mode | Disabled (one-shot mode) |
127
+ | `--model <provider[:model]>` | AI model to use in format 'provider[:model]' where model is optional. Examples: 'openai' or 'openai:gpt-4o-mini' | openai |
128
+ | `--temperature <value>` | Temperature for model generation | Provider default |
129
+ | `--top-p <value>` | Top-p sampling value | Provider default |
130
+ | `--presence-penalty <value>` | Presence penalty value | Provider default |
131
+ | `--frequency-penalty <value>` | Frequency penalty value | Provider default |
132
+ | `--log-level <level>` | Set logging level (ERROR, WARN, INFO, DEBUG, TRACE) | INFO |
133
+ | `--input`, `-i <input>` | Specify input directly | None |
134
+
135
+ #### Examples
136
+
137
+ ```bash
138
+ # Run in chat mode (interactive)
139
+ pnpm start -- --chat
140
+
141
+ # Set logging level
142
+ pnpm start -- --log-level DEBUG
143
+
144
+ # Use pipeline input
145
+ echo "how many products?" | pnpm start
105
146
  ```
106
147
 
107
148
  ## Example
package/index.ts CHANGED
@@ -1,42 +1,37 @@
1
1
  #!/usr/bin/env bunwrapper
2
2
 
3
3
  import { join } from "node:path";
4
- import { runChatLoopInTerminal } from "@aigne/cli/utils/run-chat-loop.js";
5
- import { AIAgent, AIGNE, MCPAgent, PromptBuilder } from "@aigne/core";
6
- import { loadModel } from "@aigne/core/loader/index.js";
7
- import { logger } from "@aigne/core/utils/logger.js";
8
-
9
- logger.enable(`aigne:mcp,${process.env.DEBUG}`);
10
-
11
- const model = await loadModel();
12
-
13
- const sqlite = await MCPAgent.from({
14
- command: "uvx",
15
- args: [
16
- "-q",
17
- "mcp-server-sqlite",
18
- "--db-path",
19
- join(process.cwd(), "aigne-example-sqlite-mcp-server.db"),
20
- ],
21
- });
22
-
23
- const prompt = await sqlite.prompts["mcp-demo"]?.invoke({ topic: "product service" });
24
- if (!prompt) throw new Error("Prompt mcp-demo not found");
25
-
26
- const aigne = new AIGNE({
27
- model,
28
- skills: [sqlite],
29
- });
30
-
31
- const agent = AIAgent.from({
32
- instructions: PromptBuilder.from(prompt),
33
- memory: true,
34
- });
35
-
36
- const userAgent = aigne.invoke(agent);
37
-
38
- await runChatLoopInTerminal(userAgent, {
39
- initialCall: {},
40
- });
4
+ import { runWithAIGNE } from "@aigne/cli/utils/run-with-aigne.js";
5
+ import { AIAgent, MCPAgent, PromptBuilder } from "@aigne/core";
6
+
7
+ await runWithAIGNE(
8
+ async () => {
9
+ const sqlite = await MCPAgent.from({
10
+ command: "uvx",
11
+ args: [
12
+ "-q",
13
+ "mcp-server-sqlite",
14
+ "--db-path",
15
+ join(process.cwd(), "aigne-example-sqlite-mcp-server.db"),
16
+ ],
17
+ });
18
+
19
+ const prompt = await sqlite.prompts["mcp-demo"]?.invoke({ topic: "product service" });
20
+ if (!prompt) throw new Error("Prompt mcp-demo not found");
21
+
22
+ const agent = AIAgent.from({
23
+ instructions: PromptBuilder.from(prompt),
24
+ skills: [sqlite],
25
+ memory: true,
26
+ });
27
+
28
+ return agent;
29
+ },
30
+ {
31
+ chatLoopOptions: {
32
+ initialCall: {},
33
+ },
34
+ },
35
+ );
41
36
 
42
37
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/example-mcp-sqlite",
3
- "version": "1.11.1",
3
+ "version": "1.12.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",
@@ -16,13 +16,13 @@
16
16
  "README.md"
17
17
  ],
18
18
  "dependencies": {
19
- "openai": "^4.97.0",
20
- "zod": "^3.24.4",
21
- "@aigne/cli": "^1.9.1",
22
- "@aigne/core": "^1.15.0"
19
+ "@aigne/core": "^1.16.0",
20
+ "@aigne/cli": "^1.10.0",
21
+ "@aigne/openai": "^0.1.0"
23
22
  },
24
23
  "devDependencies": {
25
- "@aigne/test-utils": "^0.2.0"
24
+ "@types/bun": "^1.2.9",
25
+ "@aigne/test-utils": "^0.3.0"
26
26
  },
27
27
  "scripts": {
28
28
  "start": "bun run index.ts",
package/usages.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert";
2
2
  import { join } from "node:path";
3
3
  import { AIAgent, AIGNE, MCPAgent } from "@aigne/core";
4
- import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
4
+ import { OpenAIChatModel } from "@aigne/openai";
5
5
 
6
6
  const { OPENAI_API_KEY } = process.env;
7
7
  assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");