@aigne/example-mcp-puppeteer 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.
- package/README.md +37 -2
- package/index.ts +32 -37
- package/package.json +6 -6
- package/usages.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Puppeteer MCP Server Demo
|
|
2
2
|
|
|
3
|
-
This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) and [Puppeteer MCP Server](https://github.com/modelcontextprotocol/servers/tree/8bd41eb0b3cf48aea0d1fe5b6c7029736092dcb1/src/puppeteer) to extract content from websites using Puppeteer.
|
|
3
|
+
This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) and [Puppeteer MCP Server](https://github.com/modelcontextprotocol/servers/tree/8bd41eb0b3cf48aea0d1fe5b6c7029736092dcb1/src/puppeteer) to extract content from websites using Puppeteer. 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
|
|
@@ -66,7 +66,14 @@ AI ->> User: The content is as follows: ...
|
|
|
66
66
|
```bash
|
|
67
67
|
export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # Set your OpenAI API key
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
# Run in one-shot mode (default)
|
|
70
|
+
npx -y @aigne/example-mcp-puppeteer
|
|
71
|
+
|
|
72
|
+
# Run in interactive chat mode
|
|
73
|
+
npx -y @aigne/example-mcp-puppeteer --chat
|
|
74
|
+
|
|
75
|
+
# Use pipeline input
|
|
76
|
+
echo "extract content from https://www.arcblock.io" | npx -y @aigne/example-mcp-puppeteer
|
|
70
77
|
```
|
|
71
78
|
|
|
72
79
|
## Installation
|
|
@@ -99,6 +106,34 @@ OPENAI_API_KEY="" # Set your OpenAI API key here
|
|
|
99
106
|
pnpm start
|
|
100
107
|
```
|
|
101
108
|
|
|
109
|
+
### Run Options
|
|
110
|
+
|
|
111
|
+
The example supports the following command-line parameters:
|
|
112
|
+
|
|
113
|
+
| Parameter | Description | Default |
|
|
114
|
+
|-----------|-------------|---------|
|
|
115
|
+
| `--chat` | Run in interactive chat mode | Disabled (one-shot mode) |
|
|
116
|
+
| `--model <provider[:model]>` | AI model to use in format 'provider[:model]' where model is optional. Examples: 'openai' or 'openai:gpt-4o-mini' | openai |
|
|
117
|
+
| `--temperature <value>` | Temperature for model generation | Provider default |
|
|
118
|
+
| `--top-p <value>` | Top-p sampling value | Provider default |
|
|
119
|
+
| `--presence-penalty <value>` | Presence penalty value | Provider default |
|
|
120
|
+
| `--frequency-penalty <value>` | Frequency penalty value | Provider default |
|
|
121
|
+
| `--log-level <level>` | Set logging level (ERROR, WARN, INFO, DEBUG, TRACE) | INFO |
|
|
122
|
+
| `--input`, `-i <input>` | Specify input directly | None |
|
|
123
|
+
|
|
124
|
+
#### Examples
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Run in chat mode (interactive)
|
|
128
|
+
pnpm start -- --chat
|
|
129
|
+
|
|
130
|
+
# Set logging level
|
|
131
|
+
pnpm start -- --log-level DEBUG
|
|
132
|
+
|
|
133
|
+
# Use pipeline input
|
|
134
|
+
echo "extract content from https://www.arcblock.io" | pnpm start
|
|
135
|
+
```
|
|
136
|
+
|
|
102
137
|
## Example
|
|
103
138
|
|
|
104
139
|
The following example demonstrates how to extract content from a website:
|
package/index.ts
CHANGED
|
@@ -1,41 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env bunwrapper
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { AIAgent,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await runChatLoopInTerminal(userAgent, {
|
|
36
|
-
welcome:
|
|
37
|
-
"Hello! I'm a chatbot that can extract content from a website. Try asking me a question!",
|
|
38
|
-
defaultQuestion: "What is the content of https://www.arcblock.io",
|
|
39
|
-
});
|
|
3
|
+
import { runWithAIGNE } from "@aigne/cli/utils/run-with-aigne.js";
|
|
4
|
+
import { AIAgent, MCPAgent } from "@aigne/core";
|
|
5
|
+
|
|
6
|
+
await runWithAIGNE(
|
|
7
|
+
async () => {
|
|
8
|
+
const puppeteer = await MCPAgent.from({
|
|
9
|
+
command: "npx",
|
|
10
|
+
args: ["-y", "@modelcontextprotocol/server-puppeteer"],
|
|
11
|
+
env: process.env as Record<string, string>,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const agent = AIAgent.from({
|
|
15
|
+
name: "example_puppeteer",
|
|
16
|
+
instructions: `\
|
|
17
|
+
## Steps to extract content from a website
|
|
18
|
+
1. navigate to the url
|
|
19
|
+
2. evaluate document.body.innerText to get the content
|
|
20
|
+
`,
|
|
21
|
+
skills: [puppeteer],
|
|
22
|
+
memory: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return agent;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
chatLoopOptions: {
|
|
29
|
+
welcome:
|
|
30
|
+
"Hello! I'm a chatbot that can extract content from a website. Try asking me a question!",
|
|
31
|
+
defaultQuestion: "What is the content of https://www.arcblock.io",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
40
35
|
|
|
41
36
|
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/example-mcp-puppeteer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "A demonstration of using AIGNE Framework and Puppeteer MCP Server to extract content from websites using Puppeteer",
|
|
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-puppeteer",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"@aigne/
|
|
22
|
-
"@aigne/core": "^1.15.0"
|
|
19
|
+
"@aigne/cli": "^1.10.0",
|
|
20
|
+
"@aigne/core": "^1.16.0",
|
|
21
|
+
"@aigne/openai": "^0.1.0"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"@
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import { AIAgent, AIGNE, MCPAgent } from "@aigne/core";
|
|
3
|
-
import { OpenAIChatModel } from "@aigne/
|
|
3
|
+
import { OpenAIChatModel } from "@aigne/openai";
|
|
4
4
|
|
|
5
5
|
const { OPENAI_API_KEY } = process.env;
|
|
6
6
|
assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
|