AgentQL
官方讓 AI 代理能夠透過 AgentQL 從非結構化網頁中取得結構化資料。
你可以用 Agent QL MCP 做什麼?
- 從任何網址提取結構化資料 — 描述您想要的欄位,讓 AI 透過
extract-web-data以自然語言提示來擷取。 - 將網頁轉換為表格或清單 — 從網址要求取得產品、影片或文章等項目,並指定要為每個項目擷取哪些屬性。
- 在提取過程中過濾掉不需要的內容 — 在提示中加入排除條件(例如跳過廣告或贊助項目),讓結果僅包含相關資料。
文件
AgentQL MCP 伺服器
這是一個整合了 AgentQL 資料擷取功能的模型上下文協定 (MCP) 伺服器。
功能特色
工具
extract-web-data- 從指定的 'url' 擷取結構化資料,使用 'prompt' 來描述實際資料及其要擷取的欄位。
安裝
若要使用 AgentQL MCP 伺服器從網頁擷取資料,您需要透過 npm 安裝它,從我們的開發者入口網站取得 API 金鑰,並在您喜愛且支援 MCP 的應用程式中進行設定。
安裝套件
npm install -g agentql-mcp
設定 Claude
- 透過
⌘+,開啟 Claude 桌面版設定(請勿與 Claude 帳戶設定混淆) - 前往開發者側邊欄區塊
- 點擊編輯設定並開啟
claude_desktop_config.json檔案 - 在設定檔的
mcpServers字典中新增agentql伺服器 - 重新啟動應用程式
{
"mcpServers": {
"agentql": {
"command": "npx",
"args": ["-y", "agentql-mcp"],
"env": {
"AGENTQL_API_KEY": "YOUR_API_KEY"
}
}
}
}
在此處閱讀更多關於 Claude 中 MCP 設定的資訊。
設定 VS Code
如需一鍵安裝,請點擊下方任一安裝按鈕:
手動安裝
點擊本節頂部的安裝按鈕可獲得最快的安裝方式。如需手動安裝,請遵循以下步驟:
將以下 JSON 區塊新增至 VS Code 中的使用者設定 (JSON) 檔案。您可以按下 Ctrl + Shift + P 並輸入 Preferences: Open User Settings (JSON) 來執行此操作。
{
"mcp": {
"inputs": [
{
"type": "promptString",
"id": "apiKey",
"description": "AgentQL API Key",
"password": true
}
],
"servers": {
"agentql": {
"command": "npx",
"args": ["-y", "agentql-mcp"],
"env": {
"AGENTQL_API_KEY": "${input:apiKey}"
}
}
}
}
}
或者,您可以將其新增至工作區中名為 .vscode/mcp.json 的檔案。這將允許您與他人共用該設定。
{
"inputs": [
{
"type": "promptString",
"id": "apiKey",
"description": "AgentQL API Key",
"password": true
}
],
"servers": {
"agentql": {
"command": "npx",
"args": ["-y", "agentql-mcp"],
"env": {
"AGENTQL_API_KEY": "${input:apiKey}"
}
}
}
}
設定 Cursor
- 開啟 Cursor 設定
- 前往 MCP > MCP 伺服器
- 點擊 + 新增 MCP 伺服器
- 輸入以下內容:
- 名稱:"agentql"(或您偏好的名稱)
- 類型:"command"
- 指令:
env AGENTQL_API_KEY=YOUR_API_KEY npx -y agentql-mcp
在此處閱讀更多關於 Cursor 中 MCP 設定的資訊。
設定 Windsurf
- 開啟 Windsurf:MCP 設定面板
- 點擊新增自訂伺服器+
- 或者,您可以直接開啟
~/.codeium/windsurf/mcp_config.json - 在設定檔的
mcpServers字典中新增agentql伺服器
{
"mcpServers": {
"agentql": {
"command": "npx",
"args": ["-y", "agentql-mcp"],
"env": {
"AGENTQL_API_KEY": "YOUR_API_KEY"
}
}
}
}
在此處閱讀更多關於 Windsurf 中 MCP 設定的資訊。
驗證 MCP 整合
給您的代理程式一個需要從網路擷取資料的任務。例如:
Extract the list of videos from the page https://www.youtube.com/results?search_query=agentql, every video should have a title, an author name, a number of views and a url to the video. Make sure to exclude ads items. Format this as a markdown table.
[!TIP] 如果您的代理程式抱怨無法開啟網址或從網路載入內容,而不是使用 AgentQL,請嘗試加入「使用工具」或「使用 agentql 工具」的提示。
開發
安裝相依套件:
npm install
建置伺服器:
npm run build
用於自動重新建置的開發模式:
npm run watch
如果您想試用開發版本,可以使用以下設定來取代預設設定:
{
"mcpServers": {
"agentql": {
"command": "/path/to/agentql-mcp/dist/index.js",
"env": {
"AGENTQL_API_KEY": "YOUR_API_KEY"
}
}
}
}
[!NOTE] 別忘了移除預設的 AgentQL MCP 伺服器設定,以免 Claude 因兩個相似的伺服器而混淆。
除錯
由於 MCP 伺服器透過 stdio 進行通訊,除錯可能具有挑戰性。我們建議使用 MCP Inspector,它可作為套件腳本使用:
npm run inspector
Inspector 將提供一個 URL,以便在您的瀏覽器中存取除錯工具。