@aigentyc/mcp 0.3.2 → 0.4.1

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.
@@ -16,9 +16,13 @@ import { linkSourcesTools } from "./link_sources.js";
16
16
  import { miscTools } from "./misc.js";
17
17
  import { pageQuestionsTools } from "./page_questions.js";
18
18
  import { personasTools } from "./personas.js";
19
+ import { projectsTools } from "./projects.js";
20
+ import { scrapersTools } from "./scrapers.js";
19
21
  import { toolsCrudTools } from "./tools_crud.js";
20
22
  export function allTools(client) {
21
23
  return [
24
+ // Project switching — connect once, then "work on project X" (no re-init).
25
+ ...projectsTools(client),
22
26
  // End-to-end discovery + embedding entry points (call these first).
23
27
  ...embedTools(client),
24
28
  // Content authoring
@@ -28,6 +32,7 @@ export function allTools(client) {
28
32
  ...linkSourcesTools(client),
29
33
  ...pageQuestionsTools(client),
30
34
  ...dataStoresTools(client),
35
+ ...scrapersTools(client),
31
36
  // Custom tools / flows
32
37
  ...toolsCrudTools(client),
33
38
  // Forms (forms + option sources + provider integrations)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0B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CAAC;AAGjD,MAAM,UAAU,QAAQ,CAAC,MAAuB;IAC9C,OAAO;QACL,2EAA2E;QAC3E,GAAG,aAAa,CAAC,MAAM,CAAC;QACxB,oEAAoE;QACpE,GAAG,UAAU,CAAC,MAAM,CAAC;QACrB,oBAAoB;QACpB,GAAG,cAAc,CAAC,MAAM,CAAC;QACzB,GAAG,UAAU,CAAC,MAAM,CAAC;QACrB,GAAG,YAAY,CAAC,MAAM,CAAC;QACvB,GAAG,gBAAgB,CAAC,MAAM,CAAC;QAC3B,GAAG,kBAAkB,CAAC,MAAM,CAAC;QAC7B,GAAG,eAAe,CAAC,MAAM,CAAC;QAC1B,GAAG,aAAa,CAAC,MAAM,CAAC;QACxB,uBAAuB;QACvB,GAAG,cAAc,CAAC,MAAM,CAAC;QACzB,yDAAyD;QACzD,GAAG,UAAU,CAAC,MAAM,CAAC;QACrB,GAAG,sBAAsB,CAAC,MAAM,CAAC;QACjC,GAAG,iBAAiB,CAAC,MAAM,CAAC;QAC5B,WAAW;QACX,GAAG,kBAAkB,CAAC,MAAM,CAAC;QAC7B,GAAG,gBAAgB,CAAC,MAAM,CAAC;QAC3B,GAAG,aAAa,CAAC,MAAM,CAAC;QACxB,cAAc;QACd,GAAG,WAAW,CAAC,MAAM,CAAC;QACtB,GAAG,YAAY,CAAC,MAAM,CAAC;QACvB,uBAAuB;QACvB,GAAG,SAAS,CAAC,MAAM,CAAC;QACpB,GAAG,SAAS,CAAC,MAAM,CAAC;QACpB,GAAG,cAAc,CAAC,MAAM,CAAC;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { DashboardClient } from "../client.js";
2
+ import { type ToolDef } from "./types.js";
3
+ export declare function projectsTools(client: DashboardClient): ToolDef[];
4
+ //# sourceMappingURL=projects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/tools/projects.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAapD,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAqBtD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,EAAE,CA6JhE"}
@@ -0,0 +1,164 @@
1
+ import { z } from "zod";
2
+ import { DEFAULT_BASE_URL, loadConfig, requireConfig, saveConfig, setActiveProfile, upsertProfile, } from "../config.js";
3
+ import { AigentycError } from "../errors.js";
4
+ import { verifyKey } from "../verify.js";
5
+ import { defineTool } from "./types.js";
6
+ /**
7
+ * Resolve a profile by its name, projectId, or (case-insensitive) label so the
8
+ * agent can switch using whatever the user said ("beta", "proj_123", ...).
9
+ */
10
+ function resolveProfile(cfg, query) {
11
+ if (cfg.profiles[query])
12
+ return { name: query, profile: cfg.profiles[query] };
13
+ for (const [name, p] of Object.entries(cfg.profiles)) {
14
+ if (p.projectId === query)
15
+ return { name, profile: p };
16
+ }
17
+ const q = query.toLowerCase();
18
+ for (const [name, p] of Object.entries(cfg.profiles)) {
19
+ if (p.label && p.label.toLowerCase() === q)
20
+ return { name, profile: p };
21
+ }
22
+ return null;
23
+ }
24
+ export function projectsTools(client) {
25
+ return [
26
+ defineTool({
27
+ name: "projects_list",
28
+ title: "List configured projects you can switch between",
29
+ description: "List every project (profile) configured locally, with its name, label, and projectId, and which one is currently active. Call this first when the user refers to a project by name so you can switch to it with projects_use.",
30
+ inputSchema: z.object({}),
31
+ handler: async () => {
32
+ const cfg = await requireConfig();
33
+ return {
34
+ active: cfg.activeProfile,
35
+ projects: Object.entries(cfg.profiles).map(([name, p]) => ({
36
+ name,
37
+ label: p.label,
38
+ projectId: p.projectId,
39
+ baseUrl: p.baseUrl,
40
+ isActive: name === cfg.activeProfile,
41
+ })),
42
+ };
43
+ },
44
+ }),
45
+ defineTool({
46
+ name: "projects_current",
47
+ title: "Show the currently active project",
48
+ description: "Return the project all other tools currently target (name, label, projectId, baseUrl).",
49
+ inputSchema: z.object({}),
50
+ handler: async () => {
51
+ const cfg = await requireConfig();
52
+ const p = cfg.profiles[cfg.activeProfile];
53
+ return {
54
+ name: cfg.activeProfile,
55
+ label: p?.label,
56
+ projectId: p?.projectId,
57
+ baseUrl: p?.baseUrl,
58
+ };
59
+ },
60
+ }),
61
+ defineTool({
62
+ name: "projects_use",
63
+ title: "Switch the active project for all subsequent tools",
64
+ description: "Switch the project that every other tool targets. Accepts a profile name, a projectId, or a label. The switch persists across restarts and stays in effect until changed. Use this when the user says 'work on project X'. Returns a get-started snapshot of the project you switched to.",
65
+ inputSchema: z.object({
66
+ project: z
67
+ .string()
68
+ .min(1)
69
+ .describe("Which project to switch to: a profile name, projectId, or label. See projects_list."),
70
+ }),
71
+ handler: async ({ project }) => {
72
+ const cfg = await requireConfig();
73
+ const match = resolveProfile(cfg, project);
74
+ if (!match) {
75
+ throw new AigentycError("NOT_FOUND", `No configured project matches "${project}". Available: ${Object.keys(cfg.profiles).join(", ") || "(none)"}. Add one with projects_add.`);
76
+ }
77
+ // Swap the live credential (apiKey + baseUrl + projectId) and persist.
78
+ client.useProfile(match.profile);
79
+ await saveConfig(setActiveProfile(cfg, match.name));
80
+ let getStarted;
81
+ try {
82
+ getStarted = await client.get(`/api/dashboard/${match.profile.projectId}/get-started`);
83
+ }
84
+ catch (err) {
85
+ getStarted = {
86
+ note: "Switched, but could not load get-started.",
87
+ error: err instanceof Error ? err.message : String(err),
88
+ };
89
+ }
90
+ return {
91
+ switchedTo: match.name,
92
+ label: match.profile.label,
93
+ projectId: match.profile.projectId,
94
+ getStarted,
95
+ };
96
+ },
97
+ }),
98
+ defineTool({
99
+ name: "projects_add",
100
+ title: "Connect a new project (one-time) and optionally switch to it",
101
+ description: "Save a new project locally so you can switch to it later without leaving the conversation. The API key is project-scoped and stored in ~/.aigentyc/config.json with 0600 permissions. The key is verified against the backend before saving. By default the new project becomes active immediately.",
102
+ inputSchema: z.object({
103
+ name: z
104
+ .string()
105
+ .min(1)
106
+ .describe("Profile name to save this project under (used to switch)."),
107
+ projectId: z.string().min(1).describe("The project's ID."),
108
+ apiKey: z
109
+ .string()
110
+ .min(1)
111
+ .describe("Project-scoped API key (e.g. tyco_...)."),
112
+ baseUrl: z
113
+ .string()
114
+ .url()
115
+ .optional()
116
+ .describe(`Backend base URL. Defaults to ${DEFAULT_BASE_URL}.`),
117
+ label: z
118
+ .string()
119
+ .optional()
120
+ .describe("Friendly display name used when listing/switching."),
121
+ allowInsecure: z
122
+ .boolean()
123
+ .optional()
124
+ .describe("Allow plaintext HTTP to non-loopback hosts. Dev only."),
125
+ activate: z
126
+ .boolean()
127
+ .optional()
128
+ .describe("Switch to this project after adding. Default true."),
129
+ }),
130
+ handler: async (args) => {
131
+ const baseUrl = (args.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
132
+ const result = await verifyKey({
133
+ baseUrl,
134
+ projectId: args.projectId,
135
+ apiKey: args.apiKey,
136
+ });
137
+ if (!result.ok) {
138
+ throw new AigentycError("UNAUTHORIZED", `${result.error ?? "Key verification failed."} Refusing to save.`);
139
+ }
140
+ const profile = {
141
+ baseUrl,
142
+ projectId: args.projectId,
143
+ apiKey: args.apiKey,
144
+ label: args.label,
145
+ allowInsecure: args.allowInsecure,
146
+ };
147
+ const activate = args.activate !== false;
148
+ const existing = await loadConfig();
149
+ const next = upsertProfile(existing, args.name, profile, activate);
150
+ await saveConfig(next);
151
+ if (activate)
152
+ client.useProfile(profile);
153
+ return {
154
+ added: args.name,
155
+ label: profile.label,
156
+ projectId: profile.projectId,
157
+ activeProfile: next.activeProfile,
158
+ activated: activate,
159
+ };
160
+ },
161
+ }),
162
+ ];
163
+ }
164
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.js","sourceRoot":"","sources":["../../src/tools/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAEL,gBAAgB,EAChB,UAAU,EAEV,aAAa,EACb,UAAU,E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AAC,KAAK,IAAI,0BAA0B,oBAAoB,CAClE,CAAC;gBACJ,CAAC;gBACD,MAAM,OAAO,GAAkB;oBAC7B,OAAO;oBACP,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,aAAa,EAAE,IAAI,CAAC,aAAa;iBAClC,CAAC;gBACF,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,KAAK,KAAK,CAAC;gBACzC,MAAM,QAAQ,GAAG,MAAM,UAAU,EAAE,CAAC;gBACpC,MAAM,IAAI,GAAG,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;gBACnE,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;gBACvB,IAAI,QAAQ;oBAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACzC,OAAO;oBACL,KAAK,EAAE,IAAI,CAAC,IAAI;oBAChB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,SAAS,EAAE,OAAO,CAAC,SAAS;oBAC5B,aAAa,EAAE,IAAI,CAAC,aAAa;oBACjC,SAAS,EAAE,QAAQ;iBACpB,CAAC;YACJ,CAAC;SACF,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { DashboardClient } from "../client.js";
2
+ import { type ToolDef } from "./types.js";
3
+ export declare function scrapersTools(client: DashboardClient): ToolDef[];
4
+ //# sourceMappingURL=scrapers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrapers.d.ts","sourceRoot":"","sources":["../../src/tools/scrapers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAoEtD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,EAAE,CAiLhE"}
@@ -0,0 +1,218 @@
1
+ import { z } from "zod";
2
+ import { pid, projectIdArg } from "./helpers.js";
3
+ import { defineTool } from "./types.js";
4
+ // Scrapers store a ScrapeConfig (the "recipe", normally built by the
5
+ // aigentyc-scraper browser extension) plus execution metadata: where results
6
+ // land (destinations), how to dedup (upsertKey), and when to run (cron /
7
+ // webhook / manual). Creating one provisions a backing cron-service job, so
8
+ // trigger + run history flow through that job.
9
+ const scrapeConfig = z
10
+ .object({
11
+ url: z.string().url().describe("The list/grid page URL to scrape."),
12
+ container: z
13
+ .object({
14
+ selector: z
15
+ .string()
16
+ .min(1)
17
+ .describe("CSS selector matching EVERY repeating item on the page."),
18
+ })
19
+ .passthrough()
20
+ .describe("How to find the repeating items. Use scrapers_infer_selectors to build this."),
21
+ })
22
+ .passthrough()
23
+ .describe("The scrape recipe. Beyond url + container.selector it carries per-field selectors and options (extra keys preserved verbatim).");
24
+ const destinations = z
25
+ .object({
26
+ dataStoreId: z
27
+ .string()
28
+ .optional()
29
+ .describe("Data store the scraped rows are upserted into."),
30
+ kb: z
31
+ .boolean()
32
+ .optional()
33
+ .describe("When true, scraped content is also pushed into the knowledge base."),
34
+ })
35
+ .describe("Where scraped results land. Empty = saved config only.");
36
+ // Fields shared by create + update. Required-ness differs, so create overrides
37
+ // `config` to be mandatory below.
38
+ const sharedFields = {
39
+ name: z.string().optional().describe("Display name. Defaults to the start URL."),
40
+ config: scrapeConfig.optional(),
41
+ upsertKey: z
42
+ .string()
43
+ .nullable()
44
+ .optional()
45
+ .describe("Field key used to dedup rows across runs. null = append-only."),
46
+ destinations: destinations.optional(),
47
+ cronExpression: z
48
+ .string()
49
+ .nullable()
50
+ .optional()
51
+ .describe("5-field cron for scheduled runs. null/omit = no schedule (manual/webhook only)."),
52
+ timezone: z.string().optional().describe("IANA timezone for the cron. Default UTC."),
53
+ webhookEnabled: z
54
+ .boolean()
55
+ .optional()
56
+ .describe("Mint a per-scraper webhook token so runs can be triggered by URL."),
57
+ customHeaders: z
58
+ .record(z.string())
59
+ .nullable()
60
+ .optional()
61
+ .describe("Headers sent on each fetch (e.g. auth). Stored encrypted; never echoed back."),
62
+ enabled: z.boolean().optional().describe("Whether scheduled runs fire. Default true."),
63
+ };
64
+ export function scrapersTools(client) {
65
+ return [
66
+ defineTool({
67
+ name: "scrapers_list",
68
+ title: "List scrapers",
69
+ description: "List every scraper in the project with its name, start URL, schedule, destinations, and enabled state. Secrets (customHeaders) are never returned.",
70
+ inputSchema: z.object({ projectId: projectIdArg }),
71
+ handler: async (args) => {
72
+ const projectId = pid(client, args.projectId);
73
+ return client.get(`/api/dashboard/${projectId}/scrapers`);
74
+ },
75
+ }),
76
+ defineTool({
77
+ name: "scrapers_get",
78
+ title: "Get a scraper",
79
+ description: "Fetch one scraper including its full `config` recipe (so it can be edited or re-run). customHeaders are never returned.",
80
+ inputSchema: z.object({
81
+ projectId: projectIdArg,
82
+ scraperId: z.string().min(1),
83
+ }),
84
+ handler: async (args) => {
85
+ const projectId = pid(client, args.projectId);
86
+ return client.get(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(args.scraperId)}`);
87
+ },
88
+ }),
89
+ defineTool({
90
+ name: "scrapers_create",
91
+ title: "Create a scraper",
92
+ description: [
93
+ "Create a scraper. `config.url` and `config.container.selector` are required — build the recipe with scrapers_infer_selectors (or the browser extension) first.",
94
+ "",
95
+ "Automation: set `cronExpression` for scheduled runs and/or `webhookEnabled` for URL-triggered runs. With neither, it's a saved config you fire manually via scrapers_trigger.",
96
+ "Set `destinations.dataStoreId` and/or `destinations.kb` to route results.",
97
+ ].join("\n"),
98
+ inputSchema: z.object({
99
+ projectId: projectIdArg,
100
+ ...sharedFields,
101
+ config: scrapeConfig,
102
+ }),
103
+ handler: async (args) => {
104
+ const { projectId: rawPid, ...body } = args;
105
+ const projectId = pid(client, rawPid);
106
+ return client.post(`/api/dashboard/${projectId}/scrapers`, body);
107
+ },
108
+ }),
109
+ defineTool({
110
+ name: "scrapers_update",
111
+ title: "Update a scraper",
112
+ description: "Update any subset of a scraper's fields. Changing cronExpression/enabled keeps the backing schedule job in sync. Omitted fields keep their stored values; enabling webhookEnabled mints a token if none exists.",
113
+ inputSchema: z.object({
114
+ projectId: projectIdArg,
115
+ scraperId: z.string().min(1),
116
+ ...sharedFields,
117
+ }),
118
+ handler: async (args) => {
119
+ const { projectId: rawPid, scraperId, ...body } = args;
120
+ const projectId = pid(client, rawPid);
121
+ return client.put(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(scraperId)}`, body);
122
+ },
123
+ }),
124
+ defineTool({
125
+ name: "scrapers_delete",
126
+ title: "Delete a scraper",
127
+ description: "Delete a scraper and its backing schedule job. Destructive — re-invoke with confirm=true.",
128
+ inputSchema: z.object({
129
+ projectId: projectIdArg,
130
+ scraperId: z.string().min(1),
131
+ confirm: z.boolean().default(false),
132
+ }),
133
+ handler: async (args) => {
134
+ if (!args.confirm) {
135
+ return {
136
+ deleted: false,
137
+ reason: "Destructive. Re-invoke with confirm=true.",
138
+ };
139
+ }
140
+ const projectId = pid(client, args.projectId);
141
+ return client.delete(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(args.scraperId)}`);
142
+ },
143
+ }),
144
+ defineTool({
145
+ name: "scrapers_trigger",
146
+ title: "Run a scraper now",
147
+ description: "Enqueue an immediate (manual) run of the scraper's backing job and return its queueId. Fails if the scraper is disabled or has no execution job configured.",
148
+ inputSchema: z.object({
149
+ projectId: projectIdArg,
150
+ scraperId: z.string().min(1),
151
+ }),
152
+ handler: async (args) => {
153
+ const projectId = pid(client, args.projectId);
154
+ return client.post(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(args.scraperId)}/trigger`);
155
+ },
156
+ }),
157
+ defineTool({
158
+ name: "scrapers_runs_list",
159
+ title: "List scraper run history",
160
+ description: "Return recent execution attempts (status, durations, errors) plus permanently-failed dead-letter entries for the scraper's job. Empty when the scraper has never run.",
161
+ inputSchema: z.object({
162
+ projectId: projectIdArg,
163
+ scraperId: z.string().min(1),
164
+ }),
165
+ handler: async (args) => {
166
+ const projectId = pid(client, args.projectId);
167
+ return client.get(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(args.scraperId)}/runs`);
168
+ },
169
+ }),
170
+ defineTool({
171
+ name: "scrapers_run_retry",
172
+ title: "Retry a failed scraper run",
173
+ description: "Re-queue a dead-letter (permanently failed) run by its queueId. Get queueIds from scrapers_runs_list's `deadLetter` array.",
174
+ inputSchema: z.object({
175
+ projectId: projectIdArg,
176
+ scraperId: z.string().min(1),
177
+ queueId: z.string().min(1).describe("Dead-letter entry id to retry."),
178
+ }),
179
+ handler: async (args) => {
180
+ const projectId = pid(client, args.projectId);
181
+ return client.post(`/api/dashboard/${projectId}/scrapers/${encodeURIComponent(args.scraperId)}/runs`, { queueId: args.queueId });
182
+ },
183
+ }),
184
+ defineTool({
185
+ name: "scrapers_infer_selectors",
186
+ title: "Infer scraper selectors from HTML",
187
+ description: [
188
+ "Given an HTML fragment of a repeating list, infer the container selector and per-field relative selectors (key, label, type, selector) to build a scrape `config`.",
189
+ "Synchronous/interactive. Requires the project to have an OpenAI API key configured.",
190
+ ].join("\n"),
191
+ inputSchema: z.object({
192
+ projectId: projectIdArg,
193
+ html: z
194
+ .string()
195
+ .min(1)
196
+ .describe("HTML fragment of the list/grid (truncated to ~15k chars server-side)."),
197
+ sample: z
198
+ .object({
199
+ selector: z.string().optional(),
200
+ tagName: z.string().optional(),
201
+ text: z.string().optional(),
202
+ })
203
+ .optional()
204
+ .describe("The example element the user clicked inside one item."),
205
+ mode: z
206
+ .enum(["container", "fields"])
207
+ .optional()
208
+ .describe("Restrict inference to just the container or just the fields."),
209
+ }),
210
+ handler: async (args) => {
211
+ const { projectId: rawPid, ...body } = args;
212
+ const projectId = pid(client, rawPid);
213
+ return client.post(`/api/dashboard/${projectId}/scraper/infer-selectors`, body);
214
+ },
215
+ }),
216
+ ];
217
+ }
218
+ //# sourceMappingURL=scrapers.js.map
@@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AAG,IAAI,CAAC;gBAC5C,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBACtC,OAAO,MAAM,CAAC,IAAI,CAChB,kBAAkB,SAAS,0BAA0B,EACrD,IAAI,CACL,CAAC;YACJ,CAAC;SACF,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Verify a project-scoped API key against a backend, shared by the `login`
3
+ * CLI command and the `projects_add` MCP tool so both apply the same checks.
4
+ *
5
+ * In production the auth-service is fronted at the same origin, so
6
+ * POST /api/auth/api-keys/verify works. In local dev that endpoint 404s, so
7
+ * we fall back to pinging the dashboard documents route — the canonical
8
+ * authenticated surface — and infer acceptance from the status code.
9
+ */
10
+ export interface VerifyResult {
11
+ ok: boolean;
12
+ /** projectId the key is scoped to, when the verify endpoint reported one. */
13
+ scopedProjectId?: string;
14
+ /** Human-readable reason when ok is false. */
15
+ error?: string;
16
+ }
17
+ export declare function verifyKey(args: {
18
+ baseUrl: string;
19
+ projectId: string;
20
+ apiKey: string;
21
+ }): Promise<VerifyResult>;
22
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,YAAY,CAAC,CA+DxB"}
package/dist/verify.js ADDED
@@ -0,0 +1,59 @@
1
+ export async function verifyKey(args) {
2
+ const baseUrl = args.baseUrl.replace(/\/$/, "");
3
+ const verifyUrl = `${baseUrl}/api/auth/api-keys/verify`;
4
+ const pingUrl = `${baseUrl}/api/dashboard/${encodeURIComponent(args.projectId)}/documents?pageSize=1`;
5
+ // 1. auth-service verify endpoint (production path).
6
+ try {
7
+ const res = await fetch(verifyUrl, {
8
+ method: "POST",
9
+ headers: { "Content-Type": "application/json" },
10
+ body: JSON.stringify({ key: args.apiKey }),
11
+ });
12
+ if (res.status !== 404) {
13
+ const body = (await res.json().catch(() => ({})));
14
+ if (!res.ok || !body.valid) {
15
+ return { ok: false, error: body.error || `HTTP ${res.status}` };
16
+ }
17
+ if (body.projectId && body.projectId !== args.projectId) {
18
+ return {
19
+ ok: false,
20
+ scopedProjectId: body.projectId,
21
+ error: `API key is scoped to project ${body.projectId}, not ${args.projectId}.`,
22
+ };
23
+ }
24
+ return { ok: true, scopedProjectId: body.projectId };
25
+ }
26
+ // 404 → auth endpoint not at this origin (dev). Fall through to ping.
27
+ }
28
+ catch (err) {
29
+ return {
30
+ ok: false,
31
+ error: `Could not reach ${verifyUrl}: ${err.message}`,
32
+ };
33
+ }
34
+ // 2. Dashboard ping fallback (dev path).
35
+ try {
36
+ const res = await fetch(pingUrl, {
37
+ method: "GET",
38
+ headers: { Authorization: `Bearer ${args.apiKey}` },
39
+ });
40
+ if (res.status === 401) {
41
+ return { ok: false, error: "Key rejected by dashboard (401)." };
42
+ }
43
+ if (res.status === 403) {
44
+ return {
45
+ ok: false,
46
+ error: "Key accepted but not authorized for this project (403).",
47
+ };
48
+ }
49
+ // 200 or 404 (project not found) → key was accepted by the auth layer.
50
+ return { ok: true };
51
+ }
52
+ catch (err) {
53
+ return {
54
+ ok: false,
55
+ error: `Could not reach ${pingUrl}: ${err.message}`,
56
+ };
57
+ }
58
+ }
59
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAiBA,MAAM,CA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AE,IAAI,EAAE,eAAe,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QACvD,CAAC;QACD,sEAAsE;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,mBAAmB,SAAS,KAAM,GAAa,CAAC,OAAO,EAAE;SACjE,CAAC;IACJ,CAAC;IAED,yCAAyC;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE;YAC/B,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACvB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,kCAAkC,EAAE,CAAC;QAClE,CAAC;QACD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACvB,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,yDAAyD;aACjE,CAAC;QACJ,CAAC;QACD,uEAAuE;QACvE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,mBAAmB,OAAO,KAAM,GAAa,CAAC,OAAO,EAAE;SAC/D,CAAC;IACJ,CAAC;AACH,CAAC"}
package/llms.txt CHANGED
@@ -182,4 +182,4 @@ config_update({ patch: { systemPrompt: "You are the support agent for ACME..." }
182
182
 
183
183
  ## Versioning
184
184
 
185
- Server (`@aigentyc/mcp` on npm) and platform (`app.aigentyc.com`) version independently. The platform maintains backward compatibility with older MCP releases — endpoints aren't broken without deprecation.
185
+ Server (`@aigentyc/mcp` on npm) and platform (`app.aigentyc.ai`) version independently. The platform maintains backward compatibility with older MCP releases — endpoints aren't broken without deprecation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigentyc/mcp",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "Model Context Protocol server for aiGentyc — content & authoring tools for LLM agents",
5
5
  "license": "MIT",
6
6
  "type": "module",