@etshop/mcp-server 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Etshop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # Etshop MCP Server & Agent Skills: Etsy market research for AI agents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@etshop/mcp-server)](https://www.npmjs.com/package/@etshop/mcp-server)
4
+ [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.pipiads--dev%2Fetshop-blue)](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.pipiads-dev/etshop)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6
+
7
+ Give Claude, ChatGPT, Cursor, VS Code Copilot or any MCP-compatible agent **live Etsy market data**: trending products, shop sales and growth, keyword search volume and competition, and hourly competitor shop monitoring. Powered by the [Etshop API](https://api.etshop.ai).
8
+
9
+ > Ask your agent: *"Find trending handmade jewelry on Etsy under $40 that started selling in the last 90 days"*, *"Is 'linen napkins' a good niche?"*, *"How much does etsy.com/shop/XYZ sell and what are its best sellers?"*, *"Write 13 Etsy tags for my personalized dog portrait"*.
10
+
11
+ This repo contains:
12
+
13
+ - **An MCP server** (`@etshop/mcp-server`) with 28 tools covering shops, products, keywords and shop monitoring.
14
+ - **Agent Skills** (`skills/`): ready-made research workflows (niche research, product research, competitor analysis, listing SEO, shop monitoring) that work in Claude Code, Claude.ai, Codex, Cursor and other agents supporting the [Agent Skills](https://agentskills.io) standard.
15
+
16
+ Unlike Etsy MCP servers that manage *your own* shop through Etsy's seller API, Etshop is about **market intelligence**: what sells across Etsy, who is growing, and which keywords are worth targeting.
17
+
18
+ ## Get an API key
19
+
20
+ 1. Sign up at **https://api.etshop.ai** and buy credits in the developer center ([pricing](https://api.etshop.ai/pricing)).
21
+ 2. Create an API key under *API Keys*.
22
+
23
+ ## Install the MCP server
24
+
25
+ Requires Node.js 18+.
26
+
27
+ ### Claude Code
28
+
29
+ ```bash
30
+ claude mcp add etshop -e ETSHOP_API_KEY=your_key -- npx -y @etshop/mcp-server
31
+ ```
32
+
33
+ ### Claude Desktop / Cursor / Windsurf / Cline (JSON config)
34
+
35
+ Add to `claude_desktop_config.json`, `~/.cursor/mcp.json`, etc.:
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "etshop": {
41
+ "command": "npx",
42
+ "args": ["-y", "@etshop/mcp-server"],
43
+ "env": { "ETSHOP_API_KEY": "your_key" }
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### VS Code (Copilot agent mode)
50
+
51
+ ```bash
52
+ code --add-mcp '{"name":"etshop","command":"npx","args":["-y","@etshop/mcp-server"],"env":{"ETSHOP_API_KEY":"your_key"}}'
53
+ ```
54
+
55
+ ### OpenAI Codex CLI
56
+
57
+ ```bash
58
+ codex mcp add etshop --env ETSHOP_API_KEY=your_key -- npx -y @etshop/mcp-server
59
+ ```
60
+
61
+ ### Configuration
62
+
63
+ | Env var | Default | Description |
64
+ |---|---|---|
65
+ | `ETSHOP_API_KEY` | (required) | Your Etshop API key |
66
+ | `ETSHOP_TOOLSETS` | `all` | Comma-separated subset: `shop`, `product`, `keyword`, `monitor` (account tools are always on). Fewer tools improves tool selection. |
67
+ | `ETSHOP_INCLUDE_IMAGES` | `false` | Include image URLs in results (off to save tokens) |
68
+ | `ETSHOP_TIMEOUT_MS` | `30000` | Request timeout |
69
+ | `ETSHOP_API_BASE_URL` | `https://api.etshop.ai/open-api` | API endpoint override |
70
+
71
+ ## Install the Agent Skills
72
+
73
+ ```bash
74
+ npx skills add pipiads-dev/etshop-mcp-server # all skills, any supported agent
75
+ npx skills add pipiads-dev/etshop-mcp-server --skill etsy-niche-research
76
+ ```
77
+
78
+ Or copy a folder from `skills/` into `~/.claude/skills/` (Claude Code) or zip a skill folder and upload it as a custom skill in Claude.ai.
79
+
80
+ | Skill | What it does |
81
+ |---|---|
82
+ | [`etsy-niche-research`](skills/etsy-niche-research/SKILL.md) | Validate a niche: demand vs. competition, price band, top competitors, go/no-go report |
83
+ | [`etsy-product-research`](skills/etsy-product-research/SKILL.md) | Find trending / breakout / best-selling products and mine their reviews |
84
+ | [`etsy-competitor-analysis`](skills/etsy-competitor-analysis/SKILL.md) | Deep-dive a competitor shop: sales trend, best sellers, keywords, weaknesses |
85
+ | [`etsy-listing-seo`](skills/etsy-listing-seo/SKILL.md) | Data-driven Etsy title + 13 tags |
86
+ | [`etsy-shop-monitoring`](skills/etsy-shop-monitoring/SKILL.md) | Set up 30-day competitor monitoring and generate sales reports |
87
+ | [`etshop-api`](skills/etshop-api/SKILL.md) | Call the Etshop REST API directly (no MCP needed) with a full endpoint reference |
88
+
89
+ The skills use the MCP tools when available, and fall back to direct HTTPS calls otherwise.
90
+
91
+ ## Tools
92
+
93
+ | Tool | What it returns | Cost |
94
+ |---|---|---|
95
+ | `get_credits_balance` | Balance of all 3 credit types | free |
96
+ | `list_categories` | Etsy category tree | free |
97
+ | `search_shops` | Filter/sort open shops by sales growth, sales, reviews, price, country, star seller... | 1 Credit / shop |
98
+ | `get_top_selling_shops` | Daily / weekly / monthly best-seller leaderboard | 1 Credit / shop |
99
+ | `search_closed_shops` | Shops that closed, with sales before closing | 1 Credit / shop |
100
+ | `get_shop_details` | Full shop profile, last-30-day sales, categories | 2 Credits |
101
+ | `get_shop_daily_stats`, `get_shop_trend` | 90-day daily sales / reviews / favorites | free* |
102
+ | `search_products` | Filter/sort listings by sales growth, real sales, price, category, badges, listing date... | 1 Credit / product |
103
+ | `get_product_details` | Tags, category, Bestseller / Etsy's Pick history | free* |
104
+ | `get_product_daily_stats`, `get_product_trend` | 90-day daily product data | free* |
105
+ | `get_product_reviews` | Reviews filtered by stars / photos / variation | free* |
106
+ | `search_keyword` | Competition, real sales, Google volume / CPC for a keyword | 1 Keyword Credit (repeat within 30 days free) |
107
+ | `get_keyword_analytics` | Avg sales & price, popular tags, categories, price distribution | free** |
108
+ | `get_related_keywords` | Related / similar keywords, or the tags of a shop or listing | free** |
109
+ | `get_keyword_products` | Listings ranking for a tag | free** |
110
+ | `check_shops_monitorable` | Pre-check shops before monitoring | free |
111
+ | `add_shop_monitors` | Start 30-day hourly monitoring of shops | 1 Monitor Credit / shop |
112
+ | `list_shop_monitors`, `get_monitor_overview`, `get_monitored_shop`, `get_monitored_shop_sales`, `list_monitor_history` | Monitoring results: sales, revenue, new listings, per-listing real sales | free |
113
+ | `stop_shop_monitors`, `delete_monitor_records`, `list_monitor_groups`, `manage_monitor_groups` | Manage monitors and groups | free |
114
+
115
+ \* The shop/product must have been returned by a paid list/details tool in the last 3 days.
116
+ \*\* The keyword must have been searched with `search_keyword` in the last 30 days.
117
+ The server explains these rules to the agent and turns `403002` errors into instructions for what to call first. List tools default to 10 records per page to protect your credits.
118
+
119
+ ## Development
120
+
121
+ ```bash
122
+ npm install
123
+ npm run build
124
+ npm test
125
+ ETSHOP_API_KEY=your_key npm run inspect # MCP Inspector
126
+ ```
127
+
128
+ ## Links
129
+
130
+ - API docs: https://api.etshop.ai/doc
131
+ - Pricing: https://api.etshop.ai/pricing
132
+ - Support: service@etshop.ai
133
+
134
+ Etshop is an independent service and is not affiliated with, endorsed or sponsored by Etsy, Inc. "Etsy" is a trademark of Etsy, Inc. Data are Etshop estimates.
135
+
136
+ ## License
137
+
138
+ MIT
package/dist/client.js ADDED
@@ -0,0 +1,80 @@
1
+ export const DEFAULT_BASE_URL = "https://api.etshop.ai/open-api";
2
+ export const DASHBOARD_URL = "https://api.etshop.ai/dashboard";
3
+ export const DOCS_URL = "https://api.etshop.ai/doc";
4
+ export class EtshopClient {
5
+ apiKey;
6
+ baseUrl;
7
+ timeoutMs;
8
+ userAgent;
9
+ fetchImpl;
10
+ constructor(opts = {}) {
11
+ this.apiKey = opts.apiKey?.trim() || undefined;
12
+ this.baseUrl = (opts.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
13
+ this.timeoutMs = opts.timeoutMs ?? 30_000;
14
+ this.userAgent = opts.userAgent ?? "etshop-mcp-server";
15
+ this.fetchImpl = opts.fetchImpl ?? fetch;
16
+ }
17
+ get(path, query = {}) {
18
+ const url = new URL(this.baseUrl + path);
19
+ for (const [key, value] of Object.entries(query)) {
20
+ if (value === undefined || value === null || value === "")
21
+ continue;
22
+ url.searchParams.set(key, typeof value === "boolean" ? (value ? "1" : "0") : String(value));
23
+ }
24
+ return this.request(url.toString(), { method: "GET" });
25
+ }
26
+ post(path, body) {
27
+ const clean = Object.fromEntries(Object.entries(body).filter(([, v]) => v !== undefined));
28
+ return this.request(this.baseUrl + path, { method: "POST", body: JSON.stringify(clean) });
29
+ }
30
+ async request(url, init) {
31
+ if (!this.apiKey) {
32
+ return {
33
+ code: 401,
34
+ message: `ETSHOP_API_KEY is not set. Create an API key at ${DASHBOARD_URL} and pass it to the MCP server ` +
35
+ `as the ETSHOP_API_KEY environment variable.`,
36
+ };
37
+ }
38
+ const controller = new AbortController();
39
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
40
+ try {
41
+ const res = await this.fetchImpl(url, {
42
+ ...init,
43
+ signal: controller.signal,
44
+ headers: {
45
+ Authorization: this.apiKey,
46
+ Accept: "application/json",
47
+ "Content-Type": "application/json",
48
+ "User-Agent": this.userAgent,
49
+ },
50
+ });
51
+ const text = await res.text();
52
+ let parsed;
53
+ try {
54
+ parsed = JSON.parse(text);
55
+ }
56
+ catch {
57
+ return {
58
+ code: res.status >= 400 ? res.status : 500,
59
+ message: `Unexpected non-JSON response (HTTP ${res.status}): ${text.slice(0, 200)}`,
60
+ };
61
+ }
62
+ if (parsed && typeof parsed === "object" && "code" in parsed) {
63
+ return parsed;
64
+ }
65
+ return { code: res.ok ? 200 : res.status, message: res.ok ? "success" : `HTTP ${res.status}`, data: parsed };
66
+ }
67
+ catch (err) {
68
+ const aborted = err instanceof Error && err.name === "AbortError";
69
+ return {
70
+ code: 500,
71
+ message: aborted
72
+ ? `Request timed out after ${this.timeoutMs / 1000}s.`
73
+ : `Network error: ${err instanceof Error ? err.message : String(err)}`,
74
+ };
75
+ }
76
+ finally {
77
+ clearTimeout(timer);
78
+ }
79
+ }
80
+ }
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { createServer, parseToolsets } from "./server.js";
4
+ import { VERSION } from "./version.js";
5
+ async function main() {
6
+ if (process.argv.includes("--version") || process.argv.includes("-v")) {
7
+ console.log(VERSION);
8
+ return;
9
+ }
10
+ const env = process.env;
11
+ const server = createServer({
12
+ apiKey: env.ETSHOP_API_KEY,
13
+ baseUrl: env.ETSHOP_API_BASE_URL,
14
+ timeoutMs: env.ETSHOP_TIMEOUT_MS ? Number(env.ETSHOP_TIMEOUT_MS) : undefined,
15
+ toolsets: parseToolsets(env.ETSHOP_TOOLSETS),
16
+ includeImages: env.ETSHOP_INCLUDE_IMAGES === "1" || env.ETSHOP_INCLUDE_IMAGES === "true",
17
+ });
18
+ await server.connect(new StdioServerTransport());
19
+ if (!env.ETSHOP_API_KEY) {
20
+ // stdout is the MCP channel; diagnostics go to stderr. Keep running so clients/directories can list tools.
21
+ console.error("[etshop-mcp] ETSHOP_API_KEY is not set; tool calls will fail until it is configured.");
22
+ }
23
+ }
24
+ main().catch((err) => {
25
+ console.error("[etshop-mcp] fatal:", err instanceof Error ? err.message : err);
26
+ process.exit(1);
27
+ });
package/dist/params.js ADDED
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ /** Default page size for charged list endpoints. Lower than the API default (20) so agents don't burn credits by accident. */
3
+ export const DEFAULT_CHARGED_PAGE_SIZE = 10;
4
+ export const productTypeEnum = z.enum(["Handmade", "Digital", "Vintage", "Customizable", "Others"]);
5
+ export const direction = z.enum(["desc", "asc"]).optional().describe("Sort direction. Default `desc`.");
6
+ export const page = z.coerce.number().int().min(1).optional().describe("Page number, starting at 1. Default 1.");
7
+ export const pageSize = (defaultSize, charged) => z.coerce
8
+ .number()
9
+ .int()
10
+ .min(1)
11
+ .max(100)
12
+ .optional()
13
+ .describe(charged
14
+ ? `Records per page (1-100). Default ${defaultSize}. Each returned record costs 1 Credit, so request only what you need.`
15
+ : `Records per page (1-100). Default ${defaultSize}.`);
16
+ /** Integer restricted to a set of values. Emitted as a plain integer in JSON Schema (widest client compatibility). */
17
+ export const intChoice = (values, desc) => z.coerce
18
+ .number()
19
+ .int()
20
+ .refine((v) => values.includes(v), { message: `Must be one of ${values.join(", ")}` })
21
+ .describe(desc);
22
+ export const id = (what) => z.coerce.number().int().positive().describe(what);
23
+ /** A list of strings accepted either as an array or a comma-separated string; sent to the API comma-separated. */
24
+ export const stringList = (desc) => z.union([z.array(z.string()), z.string()]).optional().describe(`${desc} Pass an array or a comma-separated string.`);
25
+ export const ymd = (desc) => z
26
+ .string()
27
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "Use the format YYYY-MM-DD")
28
+ .optional()
29
+ .describe(`${desc} Format YYYY-MM-DD.`);
30
+ /** Unix-seconds timestamp; also accepts a date string so the model doesn't have to compute timestamps. */
31
+ export const timeInput = (desc, tz = "UTC") => z
32
+ .union([z.number().int(), z.string()])
33
+ .optional()
34
+ .describe(`${desc} Accepts a Unix timestamp in seconds, or a date like "2026-11-01" (interpreted as 00:00 ${tz}).`);
35
+ export function joinList(v) {
36
+ if (v === undefined)
37
+ return undefined;
38
+ const parts = (Array.isArray(v) ? v : v.split(",")).map((s) => s.trim()).filter(Boolean);
39
+ return parts.length ? parts.join(",") : undefined;
40
+ }
41
+ export function flag(v) {
42
+ return v === undefined ? undefined : v ? 1 : 0;
43
+ }
44
+ /** Convert a time input to Unix seconds. `offsetHours` is the timezone a bare date is interpreted in (e.g. 8 for UTC+8). */
45
+ export function toUnixSeconds(v, offsetHours = 0) {
46
+ if (v === undefined || v === "")
47
+ return undefined;
48
+ if (typeof v === "number")
49
+ return v > 1e12 ? Math.floor(v / 1000) : v;
50
+ const s = v.trim();
51
+ if (/^\d+$/.test(s))
52
+ return toUnixSeconds(Number(s), offsetHours);
53
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
54
+ if (m) {
55
+ return Math.floor(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) / 1000) - offsetHours * 3600;
56
+ }
57
+ const ms = Date.parse(s);
58
+ if (Number.isNaN(ms))
59
+ throw new InputError(`Invalid time value "${v}". Use Unix seconds or YYYY-MM-DD.`);
60
+ return Math.floor(ms / 1000);
61
+ }
62
+ /** Builds `{prefix}_start` / `{prefix}_end` numeric range filters. */
63
+ export function range(prefix, label, integer = true) {
64
+ const num = integer ? z.coerce.number().int().min(0) : z.coerce.number().min(0);
65
+ return {
66
+ [`${prefix}_start`]: num.optional().describe(`Minimum ${label}.`),
67
+ [`${prefix}_end`]: num.optional().describe(`Maximum ${label}.`),
68
+ };
69
+ }
70
+ export class InputError extends Error {
71
+ }
package/dist/server.js ADDED
@@ -0,0 +1,38 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { EtshopClient } from "./client.js";
3
+ import { allTools } from "./tools/index.js";
4
+ import { ALL_TOOLSETS, registerTools } from "./tooling.js";
5
+ import { VERSION } from "./version.js";
6
+ export const SERVER_INSTRUCTIONS = `Etshop gives you Etsy market data: shops, products (listings), keywords and competitor shop monitoring.
7
+
8
+ Billing (tell the user before large spends):
9
+ - Credits: search_shops / get_top_selling_shops / search_closed_shops / search_products cost 1 per returned record; get_shop_details costs 2. Keep page_size small.
10
+ - Keyword Credits: search_keyword costs 1 per keyword; the same keyword is free again for 30 days.
11
+ - Monitor Credits: add_shop_monitors costs 1 per shop for a fixed 30-day monitor (no refund on early stop).
12
+ - Everything else is free. get_credits_balance shows all balances.
13
+
14
+ Unlock rules (otherwise error 403002):
15
+ - Product detail/stats/trend/reviews need the product to have been returned by search_products or get_keyword_products in the last 3 days.
16
+ - Shop stats/trend need the shop to have been returned by any shop list, get_shop_details or search_products in the last 3 days.
17
+ - get_keyword_analytics, get_related_keywords (keyword modes) and get_keyword_products need search_keyword on that keyword in the last 30 days.
18
+ So always start from a charged search/list tool, then drill down with the free tools.
19
+
20
+ Rate limit: 200 requests/minute per account. Prices are USD; times are Unix seconds unless a tool says otherwise.`;
21
+ export function parseToolsets(raw) {
22
+ if (!raw || raw.trim() === "" || raw.trim() === "all")
23
+ return ALL_TOOLSETS;
24
+ const wanted = raw.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
25
+ const unknown = wanted.filter((s) => !ALL_TOOLSETS.includes(s));
26
+ if (unknown.length) {
27
+ throw new Error(`Unknown ETSHOP_TOOLSETS value(s): ${unknown.join(", ")}. Valid: ${ALL_TOOLSETS.join(", ")}, all.`);
28
+ }
29
+ // The account toolset (balance, categories) is always useful and tiny; always include it.
30
+ return Array.from(new Set(["account", ...wanted]));
31
+ }
32
+ export function createServer(opts = {}) {
33
+ const client = new EtshopClient({ userAgent: `etshop-mcp-server/${VERSION}`, ...opts });
34
+ const toolsets = new Set(opts.toolsets ?? ALL_TOOLSETS);
35
+ const server = new McpServer({ name: "etshop", title: "Etshop: Etsy Market Research", version: VERSION, websiteUrl: "https://api.etshop.ai" }, { instructions: SERVER_INSTRUCTIONS });
36
+ registerTools(server, allTools.filter((t) => toolsets.has(t.toolset)), { client, includeImages: opts.includeImages ?? false });
37
+ return server;
38
+ }
@@ -0,0 +1,95 @@
1
+ import { DASHBOARD_URL } from "./client.js";
2
+ import { InputError } from "./params.js";
3
+ export const ALL_TOOLSETS = ["account", "shop", "product", "keyword", "monitor"];
4
+ export function defineTool(def) {
5
+ return def;
6
+ }
7
+ const CREDIT_LABEL = {
8
+ default: "Credits",
9
+ keyword_credits: "Keyword Credits",
10
+ monitor_credits: "Monitor Credits",
11
+ };
12
+ const IMAGE_KEYS = new Set(["image", "images"]);
13
+ /** Laravel-style pagination links: internal API URLs that only waste tokens. */
14
+ const NOISE_KEYS = new Set(["first_page_url", "last_page_url", "next_page_url", "prev_page_url", "path", "links"]);
15
+ /** Recursively drop noise fields (and image URLs unless `keepImages`): they cost tokens and rarely help a text model. */
16
+ export function slim(value, keepImages = false) {
17
+ if (Array.isArray(value))
18
+ return value.map((v) => slim(v, keepImages));
19
+ if (value && typeof value === "object") {
20
+ const out = {};
21
+ for (const [k, v] of Object.entries(value)) {
22
+ if (NOISE_KEYS.has(k) || (!keepImages && IMAGE_KEYS.has(k)))
23
+ continue;
24
+ out[k] = slim(v, keepImages);
25
+ }
26
+ return out;
27
+ }
28
+ return value;
29
+ }
30
+ export function creditsLine(result) {
31
+ const c = result.credits;
32
+ if (!c)
33
+ return undefined;
34
+ const label = CREDIT_LABEL[c.type] ?? c.type;
35
+ return `[${label}] consumed ${c.consumed_credits}, remaining ${c.remaining_credits}`;
36
+ }
37
+ export function errorHint(result, def) {
38
+ switch (String(result.code)) {
39
+ case "401":
40
+ if (result.message.includes("ETSHOP_API_KEY is not set"))
41
+ return "";
42
+ return `Authentication failed. Check that ETSHOP_API_KEY is a valid, enabled API key (manage keys at ${DASHBOARD_URL}).`;
43
+ case "403001": {
44
+ const label = CREDIT_LABEL[result.credits?.type ?? ""] ?? "credits";
45
+ return `Insufficient ${label}. Tell the user to top up at ${DASHBOARD_URL}; call get_credits_balance to see all balances.`;
46
+ }
47
+ case "403002":
48
+ return (def.on403002 ??
49
+ "This record has not been requested recently. Fetch it through a list or details endpoint first, then retry.");
50
+ case "429":
51
+ return "Rate limit exceeded (200 requests/minute per account). Wait a bit before retrying, and avoid parallel bursts.";
52
+ case "500":
53
+ return "Server error. Any credits charged by this request were refunded automatically. Retry later.";
54
+ default:
55
+ return "";
56
+ }
57
+ }
58
+ export function formatResult(result, def, ctx) {
59
+ const credits = creditsLine(result);
60
+ if (Number(result.code) !== 200) {
61
+ const hint = errorHint(result, def);
62
+ const text = [`Error ${result.code}: ${result.message}`, hint, credits].filter(Boolean).join("\n");
63
+ return { isError: true, content: [{ type: "text", text }] };
64
+ }
65
+ const data = slim(result.data, ctx.includeImages);
66
+ const parts = [JSON.stringify(data ?? null)];
67
+ if (credits)
68
+ parts.push(credits);
69
+ return { content: [{ type: "text", text: parts.join("\n\n") }] };
70
+ }
71
+ export function registerTools(server, defs, ctx) {
72
+ for (const def of defs) {
73
+ server.registerTool(def.name, {
74
+ title: def.title,
75
+ description: def.description,
76
+ inputSchema: def.input,
77
+ annotations: {
78
+ title: def.title,
79
+ readOnlyHint: def.readOnly,
80
+ destructiveHint: def.readOnly ? false : (def.destructive ?? false),
81
+ idempotentHint: def.readOnly ? true : (def.idempotent ?? false),
82
+ openWorldHint: true,
83
+ },
84
+ }, (async (args) => {
85
+ try {
86
+ const result = await def.run(args, ctx);
87
+ return formatResult(result, def, ctx);
88
+ }
89
+ catch (err) {
90
+ const message = err instanceof InputError ? err.message : `Unexpected error: ${String(err)}`;
91
+ return { isError: true, content: [{ type: "text", text: message }] };
92
+ }
93
+ }));
94
+ }
95
+ }
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../tooling.js";
3
+ import { id } from "../params.js";
4
+ function prune(nodes, depth) {
5
+ return nodes.map((n) => ({
6
+ id: n.id,
7
+ name: n.name,
8
+ ...(depth > 1 && n.children?.length ? { children: prune(n.children, depth - 1) } : {}),
9
+ }));
10
+ }
11
+ function findByName(nodes, q, path = [], out = []) {
12
+ for (const n of nodes) {
13
+ const p = [...path, n.name];
14
+ if (n.name.toLowerCase().includes(q))
15
+ out.push({ id: n.id, category_path: p.join(" > ") });
16
+ if (n.children?.length)
17
+ findByName(n.children, q, p, out);
18
+ }
19
+ return out;
20
+ }
21
+ export const accountTools = [
22
+ defineTool({
23
+ name: "get_credits_balance",
24
+ title: "Get Credits Balance",
25
+ toolset: "account",
26
+ description: "Get the remaining balance of all three Etshop credit types in one call: Credits (shop & product data), " +
27
+ "Keyword Credits (keyword search) and Monitor Credits (shop monitoring). Free. Call this before large " +
28
+ "research tasks to plan spending.",
29
+ input: {},
30
+ readOnly: true,
31
+ run: (_args, { client }) => client.get("/v1/credits"),
32
+ }),
33
+ defineTool({
34
+ name: "list_categories",
35
+ title: "List Etsy Categories",
36
+ toolset: "account",
37
+ description: "Find Etsy category IDs to use as `categories` in search_products. Use `search` (e.g. \"linens\" or \"necklace\") to get " +
38
+ "matching categories with their full path. That is the cheapest way to find an ID. Without `search` it returns " +
39
+ "the category tree down to `max_depth` levels (default 2; the full 3-level tree is very large). Pass `shop_id` to " +
40
+ "limit it to the categories a shop sells in. Free.",
41
+ input: {
42
+ search: z.string().optional().describe("Case-insensitive substring of a category name; returns flat {id, path} matches."),
43
+ max_depth: z.coerce.number().int().min(1).max(3).optional().describe("Tree depth when not searching (1-3). Default 2."),
44
+ shop_id: id("Optional Etsy shop ID; return only categories this shop has products in.").optional(),
45
+ },
46
+ readOnly: true,
47
+ run: async (args, { client }) => {
48
+ const res = await client.get("/v1/category", { shop_id: args.shop_id });
49
+ const tree = res.data?.data;
50
+ if (Number(res.code) !== 200 || !Array.isArray(tree))
51
+ return res;
52
+ const q = args.search?.trim().toLowerCase();
53
+ const data = q ? { matches: findByName(tree, q) } : { data: prune(tree, args.max_depth ?? 2) };
54
+ return { ...res, data };
55
+ },
56
+ }),
57
+ ];
@@ -0,0 +1,6 @@
1
+ import { accountTools } from "./account.js";
2
+ import { keywordTools } from "./keyword.js";
3
+ import { monitorTools } from "./monitor.js";
4
+ import { productTools } from "./product.js";
5
+ import { shopTools } from "./shop.js";
6
+ export const allTools = [...accountTools, ...shopTools, ...productTools, ...keywordTools, ...monitorTools];
@@ -0,0 +1,108 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../tooling.js";
3
+ import { direction, id, joinList, page, pageSize, stringList, DEFAULT_CHARGED_PAGE_SIZE } from "../params.js";
4
+ const KEYWORD_403002 = "This keyword has not been searched in the last 30 days. Call search_keyword with it first (1 Keyword Credit), " +
5
+ "then retry this free call.";
6
+ const country = z
7
+ .string()
8
+ .optional()
9
+ .describe("Country/region (ISO 3166-1 alpha-2, e.g. US) for the Google search volume / CPC data. Omit or ALL for global.");
10
+ export const keywordTools = [
11
+ defineTool({
12
+ name: "search_keyword",
13
+ title: "Etsy Keyword Search",
14
+ toolset: "keyword",
15
+ description: "Core metrics for one Etsy search keyword / tag: competition (number of listings using it), shop competition, " +
16
+ "real sales, total reviews and favorites of those listings, and Google monthly search volume, CPC and paid " +
17
+ "difficulty. COST: 1 Keyword Credit per keyword; repeating the same keyword within 30 days is free " +
18
+ "(`is_deductions=false`); unknown keywords return {} and are free. A charged search unlocks the keyword for 30 " +
19
+ "days in get_keyword_analytics, get_related_keywords and get_keyword_products (all free). Case-insensitive.",
20
+ input: {
21
+ keyword: z.string().min(1).describe('The keyword, e.g. "wall art".'),
22
+ country,
23
+ },
24
+ readOnly: true,
25
+ run: (a, { client }) => client.get("/v1/keyword/search", a),
26
+ }),
27
+ defineTool({
28
+ name: "get_keyword_analytics",
29
+ title: "Etsy Keyword Analytics",
30
+ toolset: "keyword",
31
+ description: "Deep market analysis of an Etsy keyword: average real sales, average price, favorites and reviews per listing, " +
32
+ "up to 80 most popular co-occurring tags, top categories, price distribution of top listings and processing-time " +
33
+ "distribution. Free, but the keyword must have been searched with search_keyword in the last 30 days.",
34
+ input: { keyword: z.string().min(1).describe("The keyword (case-insensitive).") },
35
+ readOnly: true,
36
+ on403002: KEYWORD_403002,
37
+ run: (a, { client }) => client.get("/v1/keyword/analytics", a),
38
+ }),
39
+ defineTool({
40
+ name: "get_related_keywords",
41
+ title: "Etsy Related Keywords",
42
+ toolset: "keyword",
43
+ description: "Keyword ideas with metrics (competition, shop competition, real sales, reviews, favorites, Google volume/CPC). " +
44
+ "mode `related` = other tags used by top listings for the keyword; `similar` = keywords with similar wording; " +
45
+ "`all` = both; `shop` = all tags used by a shop's listings (needs shop_id); `product` = tags of one listing " +
46
+ "(needs product_id). Free. For related/similar/all the keyword must have been searched with search_keyword in the " +
47
+ "last 30 days; for shop/product the shop or product must have been returned by a shop/product tool in the last 3 days.",
48
+ input: {
49
+ mode: z.enum(["related", "similar", "all", "shop", "product"]).describe("What to look up (see description)."),
50
+ keyword: z.string().optional().describe("Required for related / similar / all."),
51
+ shop_id: id("Required for mode=shop.").optional(),
52
+ product_id: id("Required for mode=product.").optional(),
53
+ country,
54
+ limit: z.coerce
55
+ .number()
56
+ .int()
57
+ .min(1)
58
+ .max(1000)
59
+ .optional()
60
+ .describe("Max keywords to return (sorted by competition, highest first). Default 50; shop mode can return thousands."),
61
+ },
62
+ readOnly: true,
63
+ on403002: "Not unlocked. For keyword modes call search_keyword first; for mode=shop call get_shop_details (or a shop list) " +
64
+ "first; for mode=product call search_products first. Then retry.",
65
+ run: async (a, { client }) => {
66
+ const type = { related: 1, similar: 2, all: 3, shop: 4, product: 5 }[a.mode];
67
+ const res = await client.get("/v1/keyword/keyword-list", {
68
+ type,
69
+ keyword: type <= 3 ? a.keyword : undefined,
70
+ shop_id: type === 4 ? a.shop_id : undefined,
71
+ product_id: type === 5 ? a.product_id : undefined,
72
+ country: type <= 3 ? a.country : undefined,
73
+ });
74
+ const list = res.data?.list;
75
+ const limit = a.limit ?? 50;
76
+ if (Number(res.code) !== 200 || !Array.isArray(list) || list.length <= limit)
77
+ return res;
78
+ return { ...res, data: { list: list.slice(0, limit), returned: limit, total: list.length } };
79
+ },
80
+ }),
81
+ defineTool({
82
+ name: "get_keyword_products",
83
+ title: "Etsy Listings for a Keyword",
84
+ toolset: "keyword",
85
+ description: "Etsy listings whose tags exactly match a keyword: the actual competitors for that search term, with sales, " +
86
+ "reviews and favorites growth. Sort by 7-day review/favorite growth, totals or listing date. Free, but the " +
87
+ "keyword must have been searched with search_keyword in the last 30 days. Returned products and their shops are " +
88
+ "unlocked for 3 days for the free product/shop detail, stats, trend and review tools.",
89
+ input: {
90
+ tags: z.string().min(1).describe("The keyword, exactly matched against listing tags (case-insensitive)."),
91
+ name: stringList("Further require these words in the listing tags or title."),
92
+ order_by: z
93
+ .enum(["review_growth", "collection_growth", "total_collection", "total_review", "create_date"])
94
+ .optional()
95
+ .describe("Sort field. Default review_growth (7-day review growth)."),
96
+ direction,
97
+ current_page: page,
98
+ page_size: pageSize(DEFAULT_CHARGED_PAGE_SIZE, false),
99
+ },
100
+ readOnly: true,
101
+ on403002: KEYWORD_403002,
102
+ run: (a, { client }) => client.get("/v1/keyword/keyword-product-list", {
103
+ ...a,
104
+ name: joinList(a.name),
105
+ page_size: a.page_size ?? DEFAULT_CHARGED_PAGE_SIZE,
106
+ }),
107
+ }),
108
+ ];
@@ -0,0 +1,215 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../tooling.js";
3
+ import { direction, page, pageSize, timeInput, toUnixSeconds, InputError } from "../params.js";
4
+ const shopUrls = z
5
+ .array(z.string().min(1))
6
+ .min(1)
7
+ .max(50)
8
+ .describe('Etsy shop names or shop URLs, e.g. "PrintPalaceStudio" or "https://www.etsy.com/shop/PrintPalaceStudio". Max 50.');
9
+ const groupId = z.string().length(32).describe("Monitor group ID (32 characters) from list_monitor_groups.");
10
+ const shopName = z.string().min(1).describe("Exact shop name as returned in `name` by list_shop_monitors.");
11
+ const MONITOR_404 = "If you get 404, the shop is not currently monitored; check list_shop_monitors.";
12
+ const growthSort = [
13
+ "sold_count",
14
+ "sold_count_1",
15
+ "sold_count_7",
16
+ "sold_count_total",
17
+ "product_count",
18
+ "product_count_1",
19
+ "product_count_7",
20
+ "product_count_total",
21
+ "favorites_count",
22
+ "favorites_count_1",
23
+ "favorites_count_7",
24
+ "favorites_count_total",
25
+ "total_rating_count",
26
+ "total_rating_count_1",
27
+ "total_rating_count_7",
28
+ "total_rating_count_total",
29
+ ];
30
+ export const monitorTools = [
31
+ defineTool({
32
+ name: "check_shops_monitorable",
33
+ title: "Check Shops Can Be Monitored",
34
+ toolset: "monitor",
35
+ description: "Pre-check up to 50 Etsy shops before monitoring: tells which can be monitored and why others can't (already " +
36
+ "monitored, URL not parseable, shop closed...). Creates nothing and costs nothing. Run this before add_shop_monitors.",
37
+ input: { urls: shopUrls },
38
+ readOnly: true,
39
+ run: (a, { client }) => client.post("/v1/monitor/check-monitor-site", { urls: a.urls }),
40
+ }),
41
+ defineTool({
42
+ name: "add_shop_monitors",
43
+ title: "Start Monitoring Etsy Shops",
44
+ toolset: "monitor",
45
+ description: "Start monitoring up to 50 competitor Etsy shops (by name or URL). Monitored shops get hourly-updated sales, " +
46
+ "revenue, new listings, reviews and favorites tracking, incl. per-listing real sales. COST: 1 Monitor Credit per " +
47
+ "shop successfully added; each monitor runs a fixed 30 days then stops; stopping early does NOT refund. The whole " +
48
+ "request fails with 403001 if Monitor Credits < number of shops submitted; shops that fail to add are refunded. " +
49
+ "Confirm with the user before calling, and run check_shops_monitorable first.",
50
+ input: {
51
+ urls: shopUrls,
52
+ group_id: groupId.optional().describe("Optional group to put the shops in (from list_monitor_groups)."),
53
+ },
54
+ readOnly: false,
55
+ destructive: false,
56
+ idempotent: false,
57
+ run: (a, { client }) => client.post("/v1/monitor/add-monitor-site", { urls: a.urls, group_id: a.group_id }),
58
+ }),
59
+ defineTool({
60
+ name: "list_shop_monitors",
61
+ title: "List Monitored Shops",
62
+ toolset: "monitor",
63
+ description: "List shops currently being monitored with their growth today, yesterday, last 7 days and since monitoring " +
64
+ "started (sales, new listings, reviews, favorites). Sort by any of these, filter by name or group. Returns the " +
65
+ "monitor `id` (for stop/move) and shop `name` (for the detail tools). Free.",
66
+ input: {
67
+ shop_name: z.string().optional().describe("Shop name or URL (fuzzy)."),
68
+ group_id: groupId.optional(),
69
+ order_by: z.enum(growthSort).optional().describe("Sort field. Suffix _1 = yesterday, _7 = last 7 days, _total = since monitoring started, none = today. Default sold_count."),
70
+ direction,
71
+ page,
72
+ per_page: pageSize(10, false),
73
+ },
74
+ readOnly: true,
75
+ run: (a, { client }) => client.get("/v1/monitor/list", a),
76
+ }),
77
+ defineTool({
78
+ name: "get_monitor_overview",
79
+ title: "Monitored Shops Overview",
80
+ toolset: "monitor",
81
+ description: "Aggregate growth across all currently monitored shops (or one group): total sales, new listings, reviews and " +
82
+ "favorites within a time range, plus the same totals since monitoring started. Free. (Per-shop revenue is in " +
83
+ "get_monitored_shop.)",
84
+ input: {
85
+ start_time: timeInput("Range start.").unwrap().describe("Range start: Unix seconds or YYYY-MM-DD (UTC)."),
86
+ end_time: timeInput("Range end.").unwrap().describe("Range end: Unix seconds or YYYY-MM-DD (UTC)."),
87
+ group_id: groupId.optional(),
88
+ },
89
+ readOnly: true,
90
+ run: (a, { client }) => client.get("/v1/monitor/overview", {
91
+ start_time: toUnixSeconds(a.start_time),
92
+ end_time: toUnixSeconds(a.end_time),
93
+ group_id: a.group_id,
94
+ }),
95
+ }),
96
+ defineTool({
97
+ name: "get_monitored_shop",
98
+ title: "Monitored Shop Details",
99
+ toolset: "monitor",
100
+ description: "Everything about one monitored shop in one call: its monitoring detail plus growth today / yesterday / 7 days / " +
101
+ `30 days / whole period for sales, revenue (USD), new listings, reviews and favorites. Free. ${MONITOR_404}`,
102
+ input: { shop_name: shopName },
103
+ readOnly: true,
104
+ run: async (a, { client }) => {
105
+ const [detail, growth] = await Promise.all([
106
+ client.get("/v1/monitor/detail", { shop_name: a.shop_name }),
107
+ client.get("/v1/monitor/detail-overview", { shop_name: a.shop_name }),
108
+ ]);
109
+ if (Number(detail.code) !== 200)
110
+ return detail;
111
+ if (Number(growth.code) !== 200)
112
+ return growth;
113
+ return { code: 200, message: "success", data: { detail: detail.data, growth: growth.data }, credits: growth.credits };
114
+ },
115
+ }),
116
+ defineTool({
117
+ name: "get_monitored_shop_sales",
118
+ title: "Monitored Shop Listing Sales",
119
+ toolset: "monitor",
120
+ description: "Per-listing real sales and revenue of a monitored shop during its current monitoring period: shows exactly " +
121
+ "which products are selling. Only for shops with a public sold page (have_sold_page = 1 in list_shop_monitors). " +
122
+ `Free. ${MONITOR_404}`,
123
+ input: {
124
+ shop_name: shopName,
125
+ order_by: z.enum(["real_sale", "real_revenue", "product_created_at"]).optional().describe("Sort field."),
126
+ direction,
127
+ page,
128
+ per_page: pageSize(10, false),
129
+ },
130
+ readOnly: true,
131
+ run: (a, { client }) => client.get("/v1/monitor/real-sale-list", a),
132
+ }),
133
+ defineTool({
134
+ name: "list_monitor_history",
135
+ title: "Stopped Monitors History",
136
+ toolset: "monitor",
137
+ description: "Monitors that have stopped (expired after 30 days or stopped manually) and not been deleted, newest first. " +
138
+ "Their `id` is used by delete_monitor_records. Free.",
139
+ input: { page, per_page: pageSize(10, false) },
140
+ readOnly: true,
141
+ run: (a, { client }) => client.get("/v1/monitor/history-list", a),
142
+ }),
143
+ defineTool({
144
+ name: "stop_shop_monitors",
145
+ title: "Stop Monitoring Shops",
146
+ toolset: "monitor",
147
+ description: "Stop running monitors by monitor id (from list_shop_monitors). Consumed Monitor Credits are NOT refunded; data " +
148
+ "is kept in list_monitor_history; restarting is charged again. Confirm with the user before calling.",
149
+ input: { ids: z.array(z.coerce.number().int().positive()).min(1).describe("Monitor IDs from list_shop_monitors.") },
150
+ readOnly: false,
151
+ destructive: true,
152
+ idempotent: true,
153
+ run: (a, { client }) => client.post("/v1/monitor/stop", { ids: a.ids }),
154
+ }),
155
+ defineTool({
156
+ name: "delete_monitor_records",
157
+ title: "Delete Stopped Monitors",
158
+ toolset: "monitor",
159
+ description: "Permanently delete stopped monitor records (ids from list_monitor_history). Running monitors are not affected " +
160
+ "(stop them first). Free. Confirm with the user before calling.",
161
+ input: { ids: z.array(z.coerce.number().int().positive()).min(1).describe("Monitor IDs from list_monitor_history.") },
162
+ readOnly: false,
163
+ destructive: true,
164
+ idempotent: true,
165
+ run: (a, { client }) => client.post("/v1/monitor/delete-monitor-site", { ids: a.ids }),
166
+ }),
167
+ defineTool({
168
+ name: "list_monitor_groups",
169
+ title: "List Monitor Groups",
170
+ toolset: "monitor",
171
+ description: "List your shop-monitor groups (id and name). Free.",
172
+ input: {},
173
+ readOnly: true,
174
+ run: (_a, { client }) => client.get("/v1/monitor/group-list"),
175
+ }),
176
+ defineTool({
177
+ name: "manage_monitor_groups",
178
+ title: "Manage Monitor Groups",
179
+ toolset: "monitor",
180
+ description: "Organize monitored shops into groups. action=create (group_name) creates a group (max 200); action=rename " +
181
+ "(group_id, group_name); action=move (monitor_id, group_id or omit to ungroup) moves one monitor; action=delete " +
182
+ "(group_id) deletes a group AND STOPS every shop monitored in it without refund (move shops out first to keep " +
183
+ "them). Free. Confirm with the user before deleting.",
184
+ input: {
185
+ action: z.enum(["create", "rename", "move", "delete"]),
186
+ group_name: z.string().max(100).optional().describe("Group name (create / rename)."),
187
+ group_id: groupId.optional().describe("Target group ID (rename / delete / move; omit on move to ungroup)."),
188
+ monitor_id: z.coerce.number().int().positive().optional().describe("Monitor ID from list_shop_monitors (move)."),
189
+ },
190
+ readOnly: false,
191
+ destructive: true,
192
+ idempotent: false,
193
+ run: (a, { client }) => {
194
+ const need = (v, field) => {
195
+ if (v === undefined || v === "")
196
+ throw new InputError(`action=${a.action} requires ${field}.`);
197
+ };
198
+ switch (a.action) {
199
+ case "create":
200
+ need(a.group_name, "group_name");
201
+ return client.post("/v1/monitor/create-group", { group_name: a.group_name });
202
+ case "rename":
203
+ need(a.group_id, "group_id");
204
+ need(a.group_name, "group_name");
205
+ return client.post("/v1/monitor/change-group", { id: a.group_id, group_name: a.group_name });
206
+ case "move":
207
+ need(a.monitor_id, "monitor_id");
208
+ return client.post("/v1/monitor/move-group", { id: a.monitor_id, move_id: a.group_id ?? null });
209
+ case "delete":
210
+ need(a.group_id, "group_id");
211
+ return client.post("/v1/monitor/delete-group", { id: a.group_id });
212
+ }
213
+ },
214
+ }),
215
+ ];
@@ -0,0 +1,147 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../tooling.js";
3
+ import { DEFAULT_CHARGED_PAGE_SIZE, direction, flag, id, intChoice, joinList, page, pageSize, productTypeEnum, range, stringList, timeInput, toUnixSeconds, ymd, } from "../params.js";
4
+ const REQUESTED_RULE = "The product must have been returned in the last 3 days by search_products or get_keyword_products. Free.";
5
+ const PRODUCT_403002 = "This product was not returned by search_products or get_keyword_products in the last 3 days. Find it again " +
6
+ "with search_products (e.g. shop_id=<its shop> or name=<title words>, small page_size), then retry this free call.";
7
+ export const productTools = [
8
+ defineTool({
9
+ name: "search_products",
10
+ title: "Search Etsy Products",
11
+ toolset: "product",
12
+ description: "Search and filter Etsy listings (products) by title/tag keywords, category, shop, price, sales, real sales, " +
13
+ "reviews, favorites, views, listing date, Bestseller / Etsy's Pick badges, video and product type, sorted by " +
14
+ "growth over a period (e.g. trending products with the fastest sales growth in the last 7 days) or totals. " +
15
+ "Use shop_id to list a specific shop's products. COST: 1 Credit per returned product (empty results are " +
16
+ "free). Returned products and their shops are unlocked for 3 days for the free product/shop detail, stats, " +
17
+ "trend and review tools.",
18
+ input: {
19
+ times: intChoice([5, 2, 3, 4], "Growth period for *_growth fields and growth sorting: 5 last 3 days, 2 last 7 days, 3 last 30 days, 4 last 90 days. Default 2.").default(2),
20
+ name: stringList("Keywords that must all appear in the listing title or tags."),
21
+ exclude_name: stringList("Exclude listings whose title contains any of these keywords."),
22
+ categories: id("Category ID from list_categories (any level; subcategories included).").optional(),
23
+ shop_id: id("Only products of this shop (closed shops included).").optional(),
24
+ price_start: z.coerce.number().min(0).optional().describe("Minimum price (USD)."),
25
+ price_end: z.coerce.number().min(0).optional().describe("Maximum price (USD)."),
26
+ created_time_start: ymd("Listed on or after this date."),
27
+ created_time_end: ymd("Listed on or before this date."),
28
+ bestseller: z.boolean().optional().describe("true = only listings with the Bestseller badge."),
29
+ etsy_pick: z.boolean().optional().describe("true = only Etsy's Pick listings."),
30
+ with_video: z.boolean().optional().describe("true = only listings with a video."),
31
+ ...range("sale", "total sales"),
32
+ ...range("real_sale", "real (verified) sales"),
33
+ ...range("review", "total reviews"),
34
+ ...range("collection", "total favorites"),
35
+ ...range("view", "total views"),
36
+ product_type: z
37
+ .array(productTypeEnum)
38
+ .optional()
39
+ .describe("Filter by product type(s): Handmade, Digital, Vintage, Customizable, Others."),
40
+ is_real_sale: z.boolean().optional().describe("true = only listings with real (verified) sales."),
41
+ order_by: z
42
+ .enum([
43
+ "sale_growth",
44
+ "view_growth",
45
+ "collection_growth",
46
+ "review_growth",
47
+ "real_sale_growth",
48
+ "total_sale",
49
+ "total_view",
50
+ "total_collection",
51
+ "total_review",
52
+ "real_sale",
53
+ "create_date",
54
+ ])
55
+ .optional()
56
+ .describe("Sort field. Default review_growth."),
57
+ direction,
58
+ current_page: page,
59
+ page_size: pageSize(DEFAULT_CHARGED_PAGE_SIZE, true),
60
+ },
61
+ readOnly: true,
62
+ run: (a, { client }) => client.get("/v1/product", {
63
+ ...a,
64
+ name: joinList(a.name),
65
+ exclude_name: joinList(a.exclude_name),
66
+ product_type: joinList(a.product_type),
67
+ // The API only accepts `1` for these switches; omit when false.
68
+ bestseller: a.bestseller ? 1 : undefined,
69
+ etsy_pick: a.etsy_pick ? 1 : undefined,
70
+ with_video: a.with_video ? 1 : undefined,
71
+ is_real_sale: a.is_real_sale ? 1 : undefined,
72
+ page_size: a.page_size ?? DEFAULT_CHARGED_PAGE_SIZE,
73
+ }),
74
+ }),
75
+ defineTool({
76
+ name: "get_product_details",
77
+ title: "Get Etsy Product Details",
78
+ toolset: "product",
79
+ description: "Full details of one Etsy listing: price, sales, real sales, reviews, favorites, views, all tags, category " +
80
+ "path, product type, shop rating and sales, plus Bestseller / Etsy's Pick badge history (periods and monthly " +
81
+ `distribution). ${REQUESTED_RULE}`,
82
+ input: { product_id: id("Etsy listing (product) ID.") },
83
+ readOnly: true,
84
+ on403002: PRODUCT_403002,
85
+ run: (a, { client }) => client.get(`/v1/product/${a.product_id}`),
86
+ }),
87
+ defineTool({
88
+ name: "get_product_daily_stats",
89
+ title: "Etsy Product Daily Stats",
90
+ toolset: "product",
91
+ description: "Day-by-day data of one Etsy listing (newest first, last 90 days max, paginated). " +
92
+ `${REQUESTED_RULE} For a compact growth series use get_product_trend.`,
93
+ input: {
94
+ product_id: id("Etsy listing (product) ID."),
95
+ start_time: timeInput("Start date (inclusive)."),
96
+ end_time: timeInput("End date (exclusive)."),
97
+ current_page: page,
98
+ page_size: pageSize(20, false),
99
+ },
100
+ readOnly: true,
101
+ on403002: PRODUCT_403002,
102
+ run: (a, { client }) => client.get("/v1/product/data-analysis-list", {
103
+ ...a,
104
+ start_time: toUnixSeconds(a.start_time),
105
+ end_time: toUnixSeconds(a.end_time),
106
+ }),
107
+ }),
108
+ defineTool({
109
+ name: "get_product_trend",
110
+ title: "Etsy Product Growth Trend",
111
+ toolset: "product",
112
+ description: "Daily growth series of one Etsy listing (oldest first, last 90 days max, no pagination) plus totals over " +
113
+ `the range. Good for charts and spotting when a product took off. ${REQUESTED_RULE}`,
114
+ input: {
115
+ product_id: id("Etsy listing (product) ID."),
116
+ start_time: timeInput("Start date (inclusive)."),
117
+ end_time: timeInput("End date (exclusive)."),
118
+ },
119
+ readOnly: true,
120
+ on403002: PRODUCT_403002,
121
+ run: (a, { client }) => client.get("/v1/product/data-analysis-tread", {
122
+ product_id: a.product_id,
123
+ start_time: toUnixSeconds(a.start_time),
124
+ end_time: toUnixSeconds(a.end_time),
125
+ }),
126
+ }),
127
+ defineTool({
128
+ name: "get_product_reviews",
129
+ title: "Etsy Product Reviews",
130
+ toolset: "product",
131
+ description: "Buyer reviews of one Etsy listing, filterable by star rating, variation (SKU) and photo reviews. Use low-star " +
132
+ `reviews to find customer pain points and product improvement ideas. ${REQUESTED_RULE}`,
133
+ input: {
134
+ product_id: id("Etsy listing (product) ID."),
135
+ review_star: intChoice([1, 2, 3, 4, 5], "Only reviews with this star rating (1-5).").optional(),
136
+ sku: id("SKU image ID: only reviews for this variation.").optional(),
137
+ with_photo: z.boolean().optional().describe("true = only reviews with buyer photos."),
138
+ order_by: z.enum(["date", "rating"]).optional().describe("Sort by review date or rating. Default: most recently collected first."),
139
+ direction,
140
+ current_page: page,
141
+ page_size: pageSize(20, false),
142
+ },
143
+ readOnly: true,
144
+ on403002: PRODUCT_403002,
145
+ run: (a, { client }) => client.get("/v1/product/comment-analysis-list", { ...a, with_photo: flag(a.with_photo) }),
146
+ }),
147
+ ];
@@ -0,0 +1,179 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "../tooling.js";
3
+ import { DEFAULT_CHARGED_PAGE_SIZE, direction, flag, id, intChoice, joinList, page, pageSize, productTypeEnum, range, stringList, timeInput, toUnixSeconds, ymd, } from "../params.js";
4
+ const REQUESTED_RULE = "The shop must have been returned in the last 3 days by search_shops, get_top_selling_shops, " +
5
+ "search_closed_shops, get_shop_details, search_products or get_keyword_products. Free.";
6
+ const SHOP_403002 = "This shop was not returned by a shop/product endpoint in the last 3 days. Call get_shop_details " +
7
+ "(2 Credits) with this shop_id first, then retry this free call.";
8
+ const productTypes = z
9
+ .array(productTypeEnum)
10
+ .optional()
11
+ .describe("Filter by product type(s): Handmade, Digital, Vintage, Customizable, Others.");
12
+ const countryCodes = stringList("Shop country/region codes (ISO 3166-1 alpha-2), e.g. US, GB, DE.");
13
+ export const shopTools = [
14
+ defineTool({
15
+ name: "search_shops",
16
+ title: "Search Etsy Shops",
17
+ toolset: "shop",
18
+ description: "Search and filter open Etsy shops by name/headline keywords, sales, reviews, favorites, views, price, " +
19
+ "country, star seller, product type and opening date, sorted by growth over a period (e.g. fastest-growing " +
20
+ "shops in the last 7 days) or totals. Also the way to find a shop's ID from its name. " +
21
+ "COST: 1 Credit per returned shop (empty results are free). Returned shops are unlocked for 3 days for the " +
22
+ "free get_shop_daily_stats / get_shop_trend. At most the first 10,000 results can be paged.",
23
+ input: {
24
+ times: intChoice([1, 2, 3, 4], "Growth period for *_growth fields and growth sorting: 1 yesterday, 2 last 7 days, 3 last 30 days, 4 last 90 days. Default 2.").default(2),
25
+ name: stringList("Keywords that must all appear in the shop name or headline (fuzzy)."),
26
+ exclude_name: stringList("Exclude shops whose name or headline contains any of these keywords."),
27
+ star_seller: z.boolean().optional().describe("true = Star Sellers only, false = non-Star Sellers only."),
28
+ ...range("avg_price", "average product price (USD)", false),
29
+ ...range("total_product_num", "number of listings"),
30
+ created_time_start: ymd("Shop opened on or after this date."),
31
+ created_time_end: ymd("Shop opened on or before this date."),
32
+ ...range("average_rating", "shop rating (0-5)", false),
33
+ country_code: countryCodes,
34
+ ...range("sold_count", "total sales"),
35
+ ...range("total_rating_count", "total reviews"),
36
+ ...range("favorites_count", "total favorites"),
37
+ ...range("views", "total views"),
38
+ product_type: productTypes,
39
+ is_real_sale: z.boolean().optional().describe("true = only shops that have real (verified) sales data."),
40
+ order_by: z
41
+ .enum(["sale_growth", "view_growth", "collection_growth", "review_growth", "total_sale", "total_view", "total_collection", "total_review"])
42
+ .optional()
43
+ .describe("Sort field. Default sale_growth (sales growth in the `times` period)."),
44
+ direction,
45
+ current_page: page,
46
+ page_size: pageSize(DEFAULT_CHARGED_PAGE_SIZE, true),
47
+ },
48
+ readOnly: true,
49
+ run: (a, { client }) => client.get("/v1/shop", {
50
+ ...a,
51
+ name: joinList(a.name),
52
+ exclude_name: joinList(a.exclude_name),
53
+ country_code: joinList(a.country_code),
54
+ product_type: joinList(a.product_type),
55
+ star_seller: flag(a.star_seller),
56
+ is_real_sale: flag(a.is_real_sale),
57
+ page_size: a.page_size ?? DEFAULT_CHARGED_PAGE_SIZE,
58
+ }),
59
+ }),
60
+ defineTool({
61
+ name: "get_top_selling_shops",
62
+ title: "Top Selling Etsy Shops",
63
+ toolset: "shop",
64
+ description: "Etsy best-selling shops leaderboard for a day, week (Mon-Sun) or calendar month, ranked by sales in that " +
65
+ "period. Filters: average price, listing count, opening date. COST: 1 Credit per returned shop. Returned " +
66
+ "shops are unlocked for 3 days for the free get_shop_daily_stats / get_shop_trend.",
67
+ input: {
68
+ times: intChoice([1, 2, 3], "Ranking type: 1 daily, 2 weekly, 3 monthly. Default 2.").default(2),
69
+ start_time: timeInput("Start of the ranking period: the day (daily), the Monday (weekly) or the 1st of the month (monthly). Omit for the latest period.", "UTC+8"),
70
+ ...range("avg_price", "average product price (USD)", false),
71
+ ...range("total_product_num", "number of listings"),
72
+ create_date_start: ymd("Shop opened on or after this date."),
73
+ create_date_end: ymd("Shop opened on or before this date."),
74
+ current_page: page,
75
+ page_size: pageSize(DEFAULT_CHARGED_PAGE_SIZE, true),
76
+ },
77
+ readOnly: true,
78
+ run: (a, { client }) => client.get("/v1/shop/top-sell-list", {
79
+ ...a,
80
+ start_time: toUnixSeconds(a.start_time, 8),
81
+ page_size: a.page_size ?? DEFAULT_CHARGED_PAGE_SIZE,
82
+ }),
83
+ }),
84
+ defineTool({
85
+ name: "search_closed_shops",
86
+ title: "Search Closed Etsy Shops",
87
+ toolset: "shop",
88
+ description: "Search Etsy shops that have closed, with their sales before closing: useful for finding niches where a " +
89
+ "successful seller left (demand without that supplier). Filters: sales, sales in the 30 days before closing, " +
90
+ "reviews, favorites, price, listing count, rating, country, product type, opening and closing dates. " +
91
+ "COST: 1 Credit per returned shop. Returned shops are unlocked for 3 days for the free shop stats tools.",
92
+ input: {
93
+ name: stringList("Keywords that must all appear in the shop name or headline (fuzzy)."),
94
+ ...range("sold_count", "total sales"),
95
+ ...range("sold_count_30", "sales in the 30 days before closing"),
96
+ ...range("total_rating_count", "total reviews"),
97
+ ...range("favorites_count", "total favorites"),
98
+ ...range("avg_price", "average product price (USD)", false),
99
+ ...range("total_product_num", "number of listings"),
100
+ ...range("average_rating", "shop rating (0-5)", false),
101
+ country_code: countryCodes,
102
+ product_type: productTypes,
103
+ create_date_start: ymd("Shop opened on or after this date."),
104
+ create_date_end: ymd("Shop opened on or before this date."),
105
+ close_time_start: ymd("Shop closed on or after this date."),
106
+ close_time_end: ymd("Shop closed on or before this date."),
107
+ is_real_sale: z.boolean().optional().describe("true = only shops with real (verified) sales data."),
108
+ order_by: z
109
+ .enum(["sold_count_30", "close_time", "total_sale", "total_collection", "total_review", "create_date", "total_product_num"])
110
+ .optional()
111
+ .describe("Sort field. Default sold_count_30 (sales in the 30 days before closing)."),
112
+ direction,
113
+ current_page: page,
114
+ page_size: pageSize(DEFAULT_CHARGED_PAGE_SIZE, true),
115
+ },
116
+ readOnly: true,
117
+ run: (a, { client }) => client.get("/v1/shop/close-shop-list", {
118
+ ...a,
119
+ name: joinList(a.name),
120
+ country_code: joinList(a.country_code),
121
+ product_type: joinList(a.product_type),
122
+ is_real_sale: flag(a.is_real_sale),
123
+ page_size: a.page_size ?? DEFAULT_CHARGED_PAGE_SIZE,
124
+ }),
125
+ }),
126
+ defineTool({
127
+ name: "get_shop_details",
128
+ title: "Get Etsy Shop Details",
129
+ toolset: "shop",
130
+ description: "Full profile of one Etsy shop by shop ID: rating, star seller, total sales, sales in the last 30 days, " +
131
+ "reviews, favorites, views, average price, active listings, location, languages, opening/closing time, " +
132
+ "top categories and product-type mix. COST: 2 Credits per call (404 if the shop doesn't exist). Unlocks the " +
133
+ "shop for 3 days for the free get_shop_daily_stats / get_shop_trend. If you only know the shop name, find the " +
134
+ "ID with search_shops(name=..., page_size=1).",
135
+ input: { shop_id: id("Etsy shop ID.") },
136
+ readOnly: true,
137
+ run: (a, { client }) => client.get(`/v1/shop/${a.shop_id}`),
138
+ }),
139
+ defineTool({
140
+ name: "get_shop_daily_stats",
141
+ title: "Etsy Shop Daily Stats",
142
+ toolset: "shop",
143
+ description: "Day-by-day data of one Etsy shop (newest first, last 90 days max, paginated): daily sales, reviews and " +
144
+ `favorites. ${REQUESTED_RULE} For a compact growth series use get_shop_trend.`,
145
+ input: {
146
+ shop_id: id("Etsy shop ID."),
147
+ start_time: timeInput("Start date (inclusive)."),
148
+ end_time: timeInput("End date (exclusive)."),
149
+ current_page: page,
150
+ page_size: pageSize(20, false),
151
+ },
152
+ readOnly: true,
153
+ on403002: SHOP_403002,
154
+ run: (a, { client }) => client.get("/v1/shop/data-analysis-list", {
155
+ ...a,
156
+ start_time: toUnixSeconds(a.start_time),
157
+ end_time: toUnixSeconds(a.end_time),
158
+ }),
159
+ }),
160
+ defineTool({
161
+ name: "get_shop_trend",
162
+ title: "Etsy Shop Growth Trend",
163
+ toolset: "shop",
164
+ description: "Daily growth series of one Etsy shop (oldest first, last 90 days max, no pagination) plus totals over the " +
165
+ `range: sales, reviews and favorites growth. Good for charts and spotting spikes. ${REQUESTED_RULE}`,
166
+ input: {
167
+ shop_id: id("Etsy shop ID."),
168
+ start_time: timeInput("Start date (inclusive)."),
169
+ end_time: timeInput("End date (exclusive)."),
170
+ },
171
+ readOnly: true,
172
+ on403002: SHOP_403002,
173
+ run: (a, { client }) => client.get("/v1/shop/data-analysis-tread", {
174
+ shop_id: a.shop_id,
175
+ start_time: toUnixSeconds(a.start_time),
176
+ end_time: toUnixSeconds(a.end_time),
177
+ }),
178
+ }),
179
+ ];
@@ -0,0 +1 @@
1
+ export const VERSION = "0.1.0";
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@etshop/mcp-server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Etsy market research: shop & product sales data, keyword search volume, competitor shop monitoring (Etshop API).",
5
+ "mcpName": "io.github.pipiads-dev/etshop",
6
+ "type": "module",
7
+ "bin": {
8
+ "etshop-mcp-server": "dist/index.js"
9
+ },
10
+ "main": "dist/index.js",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json && chmod +x dist/index.js",
18
+ "dev": "tsc -p tsconfig.json --watch",
19
+ "start": "node dist/index.js",
20
+ "test": "vitest run",
21
+ "typecheck": "tsc -p tsconfig.json --noEmit",
22
+ "inspect": "npx @modelcontextprotocol/inspector node dist/index.js",
23
+ "prepublishOnly": "npm run build && npm test"
24
+ },
25
+ "keywords": [
26
+ "mcp",
27
+ "mcp-server",
28
+ "model-context-protocol",
29
+ "etsy",
30
+ "etsy-seller",
31
+ "etsy-seo",
32
+ "etsy-keyword-research",
33
+ "product-research",
34
+ "ecommerce",
35
+ "market-research",
36
+ "claude",
37
+ "ai-agent",
38
+ "etshop"
39
+ ],
40
+ "homepage": "https://api.etshop.ai",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/pipiads-dev/etshop-mcp-server.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/pipiads-dev/etshop-mcp-server/issues"
47
+ },
48
+ "author": "Etshop <service@etshop.ai>",
49
+ "license": "MIT",
50
+ "engines": {
51
+ "node": ">=18"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "dependencies": {
57
+ "@modelcontextprotocol/sdk": "^1.32.2",
58
+ "zod": "^4.6.7"
59
+ },
60
+ "devDependencies": {
61
+ "@types/node": "^26.6.11",
62
+ "typescript": "^7.0.2",
63
+ "vitest": "^4.1.12"
64
+ }
65
+ }