@taghost/mcp 1.0.0 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -30,7 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ALL_MCP_SCOPES: () => ALL_MCP_SCOPES,
33
34
  InMemoryTransport: () => import_inMemory.InMemoryTransport,
35
+ MCP_SCOPES: () => MCP_SCOPES,
34
36
  TAGHOST_OPENAPI_SPEC: () => TAGHOST_OPENAPI_SPEC,
35
37
  TagHostClient: () => TagHostClient,
36
38
  bundleDirectory: () => bundleDirectory,
@@ -38,7 +40,10 @@ __export(index_exports, {
38
40
  createTagHostMcpServer: () => createTagHostMcpServer,
39
41
  findProjectBinding: () => findProjectBinding,
40
42
  getApiUrl: () => getApiUrl,
43
+ hasMcpScope: () => hasMcpScope,
44
+ normalizeMcpScopes: () => normalizeMcpScopes,
41
45
  resolveAuthToken: () => resolveAuthToken,
46
+ sanitizeAuthToken: () => sanitizeAuthToken,
42
47
  startServer: () => startServer,
43
48
  validateReadOnlySql: () => validateReadOnlySql
44
49
  });
@@ -60,19 +65,31 @@ function getApiUrl() {
60
65
  function credentialsPath(homeDir = process.env.TAGHOST_HOME || import_node_os.default.homedir()) {
61
66
  return import_node_path.default.join(homeDir, ".taghost", "credentials.json");
62
67
  }
68
+ var PLACEHOLDER_TOKEN_PATTERN = /^<?(your[_-].*token|replace[_-]?me|changeme|placeholder)>?$/i;
69
+ function sanitizeAuthToken(value) {
70
+ if (typeof value !== "string") return null;
71
+ const trimmed = value.trim();
72
+ if (!trimmed || PLACEHOLDER_TOKEN_PATTERN.test(trimmed)) {
73
+ return null;
74
+ }
75
+ return trimmed;
76
+ }
63
77
  function resolveAuthToken() {
64
- if (process.env.TAGHOST_API_TOKEN && process.env.TAGHOST_API_TOKEN.trim()) {
65
- return process.env.TAGHOST_API_TOKEN.trim();
78
+ const apiToken = sanitizeAuthToken(process.env.TAGHOST_API_TOKEN);
79
+ if (apiToken) {
80
+ return apiToken;
66
81
  }
67
- if (process.env.TAGHOST_TOKEN && process.env.TAGHOST_TOKEN.trim()) {
68
- return process.env.TAGHOST_TOKEN.trim();
82
+ const token = sanitizeAuthToken(process.env.TAGHOST_TOKEN);
83
+ if (token) {
84
+ return token;
69
85
  }
70
86
  const credsPath = credentialsPath();
71
87
  if (import_node_fs.default.existsSync(credsPath)) {
72
88
  try {
73
89
  const data = JSON.parse(import_node_fs.default.readFileSync(credsPath, "utf8"));
74
- if (data && typeof data.token === "string" && data.token.trim()) {
75
- return data.token.trim();
90
+ const stored = sanitizeAuthToken(data?.token);
91
+ if (stored) {
92
+ return stored;
76
93
  }
77
94
  } catch {
78
95
  }
@@ -112,16 +129,27 @@ function findProjectBinding(startDir = process.cwd()) {
112
129
  // src/client/taghost-client.ts
113
130
  var TagHostClient = class {
114
131
  apiUrl;
115
- token;
132
+ explicitToken;
116
133
  constructor(options = {}) {
117
134
  this.apiUrl = (options.apiUrl || getApiUrl()).replace(/\/+$/, "");
118
- this.token = options.token || resolveAuthToken();
135
+ this.explicitToken = sanitizeAuthToken(options.token);
136
+ }
137
+ getToken() {
138
+ return this.explicitToken || resolveAuthToken();
119
139
  }
120
140
  async request(endpoint, options = {}) {
121
141
  const url = endpoint.startsWith("http") ? endpoint : `${this.apiUrl}${endpoint.startsWith("/") ? "" : "/"}${endpoint}`;
122
142
  const headers = new Headers(options.headers || {});
123
- if (this.token && !headers.has("Authorization")) {
124
- headers.set("Authorization", `Bearer ${this.token}`);
143
+ if (!headers.has("Authorization")) {
144
+ const token = this.getToken();
145
+ if (!token) {
146
+ const error = new Error(
147
+ 'Not authenticated with TagHost. Run "tag login" (saved to ~/.taghost/credentials.json) or set TAGHOST_API_TOKEN.'
148
+ );
149
+ error.status = 401;
150
+ throw error;
151
+ }
152
+ headers.set("Authorization", `Bearer ${token}`);
125
153
  }
126
154
  const response = await fetch(url, {
127
155
  ...options,
@@ -345,6 +373,13 @@ var TagHostClient = class {
345
373
  body: JSON.stringify(payload)
346
374
  });
347
375
  }
376
+ async cloneWordPressSite(projectId, payload) {
377
+ return this.request(`/projects/${projectId}/migrations/wordpress/clone`, {
378
+ method: "POST",
379
+ headers: { "Content-Type": "application/json" },
380
+ body: JSON.stringify(payload)
381
+ });
382
+ }
348
383
  async listOrders(projectId, options = {}) {
349
384
  const params = new URLSearchParams();
350
385
  if (options.status) params.set("status", options.status);
@@ -567,154 +602,258 @@ var TagHostClient = class {
567
602
 
568
603
  // src/tools/projects.ts
569
604
  var import_zod = require("zod");
570
- function registerProjectTools(server, client) {
571
- server.tool(
572
- "taghost_project_create",
573
- "Create a new project on TagHost edge platform.",
574
- {
575
- name: import_zod.z.string().describe('Human readable name of the project (e.g. "Acme Storefront")'),
576
- slug: import_zod.z.string().optional().describe('URL slug for the project (e.g. "acme-storefront")'),
577
- framework: import_zod.z.string().optional().describe('Framework template (e.g. "html", "react", "nextjs", "vue")')
578
- },
579
- async ({ name, slug, framework }) => {
580
- try {
581
- const result = await client.createProject({ name, slug, framework });
582
- return {
583
- content: [
584
- {
585
- type: "text",
586
- text: JSON.stringify(
587
- {
588
- success: true,
589
- message: `Project "${name}" created successfully.`,
590
- project: result.project || result
591
- },
592
- null,
593
- 2
594
- )
595
- }
596
- ]
597
- };
598
- } catch (err) {
599
- return {
600
- isError: true,
601
- content: [{ type: "text", text: `Failed to create project: ${err.message}` }]
602
- };
603
- }
604
- }
605
- );
606
- server.tool(
607
- "taghost_project_list",
608
- "List all projects accessible within the current TagHost workspace.",
609
- {
610
- limit: import_zod.z.number().optional().describe("Maximum number of projects to return (default: 50)")
611
- },
612
- async ({ limit }) => {
613
- try {
614
- const result = await client.listProjects();
615
- const list = Array.isArray(result) ? result : result.projects || [];
616
- const items = limit ? list.slice(0, limit) : list;
617
- return {
618
- content: [
619
- {
620
- type: "text",
621
- text: JSON.stringify({ success: true, count: items.length, projects: items }, null, 2)
622
- }
623
- ]
624
- };
625
- } catch (err) {
626
- return {
627
- isError: true,
628
- content: [{ type: "text", text: `Failed to list projects: ${err.message}` }]
629
- };
630
- }
631
- }
632
- );
633
- server.tool(
634
- "taghost_project_get",
635
- "Get detailed information about a specific TagHost project, including active deployment and domains.",
636
- {
637
- projectId: import_zod.z.string().optional().describe('Project ID (e.g. "proj_..."). Defaults to active project.')
638
- },
639
- async ({ projectId }) => {
640
- try {
641
- const id = await client.resolveProjectId(projectId);
642
- const result = await client.getProject(id);
643
- return {
644
- content: [
645
- {
646
- type: "text",
647
- text: JSON.stringify({ success: true, project: result.project || result }, null, 2)
648
- }
649
- ]
650
- };
651
- } catch (err) {
652
- return {
653
- isError: true,
654
- content: [{ type: "text", text: `Failed to get project: ${err.message}` }]
655
- };
656
- }
657
- }
658
- );
659
- server.tool(
660
- "taghost_env_manage",
661
- "Manage environment variables for a TagHost project.",
662
- {
663
- projectId: import_zod.z.string().optional().describe("Project ID. Defaults to active project."),
664
- action: import_zod.z.enum(["list", "set", "delete"]).describe("Action to perform"),
665
- key: import_zod.z.string().optional().describe("Environment variable key"),
666
- value: import_zod.z.string().optional().describe("Environment variable value (for set action)"),
667
- target: import_zod.z.enum(["production", "preview", "all"]).optional().describe("Deployment target")
668
- },
669
- async ({ projectId, action, key, value, target }) => {
670
- try {
671
- const id = await client.resolveProjectId(projectId);
672
- if (action === "list") {
673
- const res = await client.getProjectEnv(id);
605
+
606
+ // src/scopes.ts
607
+ var MCP_SCOPES = [
608
+ {
609
+ id: "projects:read",
610
+ label: "Projects & quotas",
611
+ description: "List projects, inspect configuration, check quotas, and preview AST eject output.",
612
+ icon: "layers",
613
+ access: "read",
614
+ defaultSelected: true
615
+ },
616
+ {
617
+ id: "deployments:write",
618
+ label: "Deployments & environment",
619
+ description: "Deploy site bundles, publish partial files, manage env vars, set expiry, and rollback.",
620
+ icon: "deployed_code",
621
+ access: "write",
622
+ defaultSelected: true
623
+ },
624
+ {
625
+ id: "content:write",
626
+ label: "Edge content & collections",
627
+ description: "Edit [data-tag] bindings, patch HTML canvas elements, and publish CMS collection items.",
628
+ icon: "draw",
629
+ access: "write",
630
+ defaultSelected: true
631
+ },
632
+ {
633
+ id: "domains:write",
634
+ label: "Domains & DNS",
635
+ description: "Search/check domain availability, attach custom domains, verify SSL, and manage DNS records.",
636
+ icon: "language",
637
+ access: "write"
638
+ },
639
+ {
640
+ id: "mail:read",
641
+ label: "TagMail (read)",
642
+ description: "List and read TagMail threads and check mail domain DNS verification.",
643
+ icon: "inbox",
644
+ access: "read"
645
+ },
646
+ {
647
+ id: "mail:send",
648
+ label: "TagMail (send & mailboxes)",
649
+ description: "Send outbound transactional email and create workspace mailboxes.",
650
+ icon: "mail",
651
+ access: "write"
652
+ },
653
+ {
654
+ id: "commerce:write",
655
+ label: "Commerce & orders",
656
+ description: "Configure stores, manage coupons, view/fulfill orders, and migrate catalogs.",
657
+ icon: "storefront",
658
+ access: "write"
659
+ },
660
+ {
661
+ id: "forms:read",
662
+ label: "Forms, CRM & webhooks",
663
+ description: "Inspect form submissions, enroll leads in CRM sequences, and configure webhooks.",
664
+ icon: "assignment",
665
+ access: "write"
666
+ },
667
+ {
668
+ id: "sql:read",
669
+ label: "Serverless D1 SQL (read-only)",
670
+ description: "Introspect project database schemas and execute read-only SELECT queries.",
671
+ icon: "database",
672
+ access: "read"
673
+ },
674
+ {
675
+ id: "workspace:collaborate",
676
+ label: "Tasks, calendar, notes & Meet",
677
+ description: "Manage TagWork tasks, calendar events, notes, Meet rooms, and scheduled automations.",
678
+ icon: "event",
679
+ access: "write"
680
+ }
681
+ ];
682
+ var ALL_MCP_SCOPES = MCP_SCOPES.map((s) => s.id);
683
+ var VALID_SCOPE_SET = new Set(ALL_MCP_SCOPES);
684
+ function normalizeMcpScopes(input) {
685
+ if (!input) return [];
686
+ const raw = Array.isArray(input) ? input : input.split(/[\s,]+/);
687
+ const seen = /* @__PURE__ */ new Set();
688
+ for (const item of raw) {
689
+ const trimmed = item.trim();
690
+ if (VALID_SCOPE_SET.has(trimmed)) {
691
+ seen.add(trimmed);
692
+ }
693
+ }
694
+ return Array.from(seen);
695
+ }
696
+ function hasMcpScope(granted, required) {
697
+ if (granted == null) return true;
698
+ if (granted.includes("*")) return true;
699
+ return granted.includes(required);
700
+ }
701
+
702
+ // src/tools/projects.ts
703
+ function registerProjectTools(server, client, scopes) {
704
+ if (hasMcpScope(scopes, "deployments:write")) {
705
+ server.tool(
706
+ "taghost_project_create",
707
+ "Create a new project on TagHost edge platform.",
708
+ {
709
+ name: import_zod.z.string().describe('Human readable name of the project (e.g. "Acme Storefront")'),
710
+ slug: import_zod.z.string().optional().describe('URL slug for the project (e.g. "acme-storefront")'),
711
+ framework: import_zod.z.string().optional().describe('Framework template (e.g. "html", "react", "nextjs", "vue")')
712
+ },
713
+ async ({ name, slug, framework }) => {
714
+ try {
715
+ const result = await client.createProject({ name, slug, framework });
674
716
  return {
675
- content: [{ type: "text", text: JSON.stringify({ success: true, envVars: res }, null, 2) }]
717
+ content: [
718
+ {
719
+ type: "text",
720
+ text: JSON.stringify(
721
+ {
722
+ success: true,
723
+ message: `Project "${name}" created successfully.`,
724
+ project: result.project || result
725
+ },
726
+ null,
727
+ 2
728
+ )
729
+ }
730
+ ]
731
+ };
732
+ } catch (err) {
733
+ return {
734
+ isError: true,
735
+ content: [{ type: "text", text: `Failed to create project: ${err.message}` }]
676
736
  };
677
737
  }
678
- if (action === "set") {
679
- if (!key || value === void 0) {
680
- return {
681
- isError: true,
682
- content: [{ type: "text", text: 'Both key and value are required for "set" action.' }]
683
- };
684
- }
685
- const res = await client.setProjectEnv(id, key, value, target || "all");
738
+ }
739
+ );
740
+ }
741
+ if (hasMcpScope(scopes, "projects:read")) {
742
+ server.tool(
743
+ "taghost_project_list",
744
+ "List all projects accessible within the current TagHost workspace.",
745
+ {
746
+ limit: import_zod.z.number().optional().describe("Maximum number of projects to return (default: 50)")
747
+ },
748
+ async ({ limit }) => {
749
+ try {
750
+ const result = await client.listProjects();
751
+ const list = Array.isArray(result) ? result : result.projects || [];
752
+ const items = limit ? list.slice(0, limit) : list;
686
753
  return {
687
754
  content: [
688
755
  {
689
756
  type: "text",
690
- text: JSON.stringify({ success: true, message: `Environment variable "${key}" set.`, result: res }, null, 2)
757
+ text: JSON.stringify({ success: true, count: items.length, projects: items }, null, 2)
691
758
  }
692
759
  ]
693
760
  };
761
+ } catch (err) {
762
+ return {
763
+ isError: true,
764
+ content: [{ type: "text", text: `Failed to list projects: ${err.message}` }]
765
+ };
694
766
  }
695
- if (action === "delete") {
696
- if (!key) {
697
- return { isError: true, content: [{ type: "text", text: 'Key is required for "delete" action.' }] };
698
- }
699
- await client.deleteProjectEnv(id, key);
767
+ }
768
+ );
769
+ server.tool(
770
+ "taghost_project_get",
771
+ "Get detailed information about a specific TagHost project, including active deployment and domains.",
772
+ {
773
+ projectId: import_zod.z.string().optional().describe('Project ID (e.g. "proj_..."). Defaults to active project.')
774
+ },
775
+ async ({ projectId }) => {
776
+ try {
777
+ const id = await client.resolveProjectId(projectId);
778
+ const result = await client.getProject(id);
700
779
  return {
701
780
  content: [
702
781
  {
703
782
  type: "text",
704
- text: JSON.stringify({ success: true, message: `Environment variable "${key}" deleted.` }, null, 2)
783
+ text: JSON.stringify({ success: true, project: result.project || result }, null, 2)
705
784
  }
706
785
  ]
707
786
  };
787
+ } catch (err) {
788
+ return {
789
+ isError: true,
790
+ content: [{ type: "text", text: `Failed to get project: ${err.message}` }]
791
+ };
708
792
  }
709
- return { isError: true, content: [{ type: "text", text: `Unknown action: ${action}` }] };
710
- } catch (err) {
711
- return {
712
- isError: true,
713
- content: [{ type: "text", text: `Failed to manage env vars: ${err.message}` }]
714
- };
715
793
  }
716
- }
717
- );
794
+ );
795
+ }
796
+ if (hasMcpScope(scopes, "deployments:write")) {
797
+ server.tool(
798
+ "taghost_env_manage",
799
+ "Manage environment variables for a TagHost project.",
800
+ {
801
+ projectId: import_zod.z.string().optional().describe("Project ID. Defaults to active project."),
802
+ action: import_zod.z.enum(["list", "set", "delete"]).describe("Action to perform"),
803
+ key: import_zod.z.string().optional().describe("Environment variable key"),
804
+ value: import_zod.z.string().optional().describe("Environment variable value (for set action)"),
805
+ target: import_zod.z.enum(["production", "preview", "all"]).optional().describe("Deployment target")
806
+ },
807
+ async ({ projectId, action, key, value, target }) => {
808
+ try {
809
+ const id = await client.resolveProjectId(projectId);
810
+ if (action === "list") {
811
+ const res = await client.getProjectEnv(id);
812
+ return {
813
+ content: [{ type: "text", text: JSON.stringify({ success: true, envVars: res }, null, 2) }]
814
+ };
815
+ }
816
+ if (action === "set") {
817
+ if (!key || value === void 0) {
818
+ return {
819
+ isError: true,
820
+ content: [{ type: "text", text: 'Both key and value are required for "set" action.' }]
821
+ };
822
+ }
823
+ const res = await client.setProjectEnv(id, key, value, target || "all");
824
+ return {
825
+ content: [
826
+ {
827
+ type: "text",
828
+ text: JSON.stringify({ success: true, message: `Environment variable "${key}" set.`, result: res }, null, 2)
829
+ }
830
+ ]
831
+ };
832
+ }
833
+ if (action === "delete") {
834
+ if (!key) {
835
+ return { isError: true, content: [{ type: "text", text: 'Key is required for "delete" action.' }] };
836
+ }
837
+ await client.deleteProjectEnv(id, key);
838
+ return {
839
+ content: [
840
+ {
841
+ type: "text",
842
+ text: JSON.stringify({ success: true, message: `Environment variable "${key}" deleted.` }, null, 2)
843
+ }
844
+ ]
845
+ };
846
+ }
847
+ return { isError: true, content: [{ type: "text", text: `Unknown action: ${action}` }] };
848
+ } catch (err) {
849
+ return {
850
+ isError: true,
851
+ content: [{ type: "text", text: `Failed to manage env vars: ${err.message}` }]
852
+ };
853
+ }
854
+ }
855
+ );
856
+ }
718
857
  }
719
858
 
720
859
  // src/tools/deployments.ts
@@ -1009,199 +1148,205 @@ function registerDeploymentTools(server, client) {
1009
1148
 
1010
1149
  // src/tools/mail.ts
1011
1150
  var import_zod3 = require("zod");
1012
- function registerMailTools(server, client) {
1013
- server.tool(
1014
- "taghost_mail_threads_list",
1015
- "Check mail: list email threads and messages in the TagMail inbox with search and mailbox filters.",
1016
- {
1017
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1018
- mailboxId: import_zod3.z.string().optional().describe("Filter by specific mailbox ID"),
1019
- query: import_zod3.z.string().optional().describe("Search query for sender, subject or body text"),
1020
- limit: import_zod3.z.number().optional().describe("Maximum number of threads to return (default: 25)")
1021
- },
1022
- async ({ projectId, mailboxId, query, limit }) => {
1023
- try {
1024
- const id = await client.resolveProjectId(projectId);
1025
- const result = await client.listMailThreads(id, { mailboxId, query, limit: limit || 25 });
1026
- const threads = Array.isArray(result) ? result : result.threads || [];
1027
- return {
1028
- content: [
1029
- {
1030
- type: "text",
1031
- text: JSON.stringify(
1032
- {
1033
- success: true,
1034
- count: threads.length,
1035
- threads: threads.map((t) => ({
1036
- id: t.id,
1037
- subject: t.subject || "(no subject)",
1038
- from: t.fromAddress || t.snippetSender,
1039
- snippet: t.snippet,
1040
- unread: Boolean(t.unread),
1041
- messageCount: t.messageCount || 1,
1042
- receivedAt: t.lastMessageAt || t.receivedAt || t.createdAt
1043
- }))
1044
- },
1045
- null,
1046
- 2
1047
- )
1048
- }
1049
- ]
1050
- };
1051
- } catch (err) {
1052
- return {
1053
- isError: true,
1054
- content: [{ type: "text", text: `Failed to check mail: ${err.message}` }]
1055
- };
1151
+ function registerMailTools(server, client, scopes) {
1152
+ if (hasMcpScope(scopes, "mail:read")) {
1153
+ server.tool(
1154
+ "taghost_mail_threads_list",
1155
+ "Check mail: list email threads and messages in the TagMail inbox with search and mailbox filters.",
1156
+ {
1157
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1158
+ mailboxId: import_zod3.z.string().optional().describe("Filter by specific mailbox ID"),
1159
+ query: import_zod3.z.string().optional().describe("Search query for sender, subject or body text"),
1160
+ limit: import_zod3.z.number().optional().describe("Maximum number of threads to return (default: 25)")
1161
+ },
1162
+ async ({ projectId, mailboxId, query, limit }) => {
1163
+ try {
1164
+ const id = await client.resolveProjectId(projectId);
1165
+ const result = await client.listMailThreads(id, { mailboxId, query, limit: limit || 25 });
1166
+ const threads = Array.isArray(result) ? result : result.threads || [];
1167
+ return {
1168
+ content: [
1169
+ {
1170
+ type: "text",
1171
+ text: JSON.stringify(
1172
+ {
1173
+ success: true,
1174
+ count: threads.length,
1175
+ threads: threads.map((t) => ({
1176
+ id: t.id,
1177
+ subject: t.subject || "(no subject)",
1178
+ from: t.fromAddress || t.snippetSender,
1179
+ snippet: t.snippet,
1180
+ unread: Boolean(t.unread),
1181
+ messageCount: t.messageCount || 1,
1182
+ receivedAt: t.lastMessageAt || t.receivedAt || t.createdAt
1183
+ }))
1184
+ },
1185
+ null,
1186
+ 2
1187
+ )
1188
+ }
1189
+ ]
1190
+ };
1191
+ } catch (err) {
1192
+ return {
1193
+ isError: true,
1194
+ content: [{ type: "text", text: `Failed to check mail: ${err.message}` }]
1195
+ };
1196
+ }
1056
1197
  }
1057
- }
1058
- );
1059
- server.tool(
1060
- "taghost_mail_thread_get",
1061
- "Read the full contents of an email thread, including all inbound and outbound messages and attachment metadata.",
1062
- {
1063
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1064
- threadId: import_zod3.z.string().describe("The email thread ID to retrieve")
1065
- },
1066
- async ({ projectId, threadId }) => {
1067
- try {
1068
- const id = await client.resolveProjectId(projectId);
1069
- const result = await client.getMailThread(id, threadId);
1070
- return {
1071
- content: [
1072
- {
1073
- type: "text",
1074
- text: JSON.stringify({ success: true, thread: result.thread || result }, null, 2)
1075
- }
1076
- ]
1077
- };
1078
- } catch (err) {
1079
- return {
1080
- isError: true,
1081
- content: [{ type: "text", text: `Failed to read mail thread: ${err.message}` }]
1082
- };
1198
+ );
1199
+ server.tool(
1200
+ "taghost_mail_thread_get",
1201
+ "Read the full contents of an email thread, including all inbound and outbound messages and attachment metadata.",
1202
+ {
1203
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1204
+ threadId: import_zod3.z.string().describe("The email thread ID to retrieve")
1205
+ },
1206
+ async ({ projectId, threadId }) => {
1207
+ try {
1208
+ const id = await client.resolveProjectId(projectId);
1209
+ const result = await client.getMailThread(id, threadId);
1210
+ return {
1211
+ content: [
1212
+ {
1213
+ type: "text",
1214
+ text: JSON.stringify({ success: true, thread: result.thread || result }, null, 2)
1215
+ }
1216
+ ]
1217
+ };
1218
+ } catch (err) {
1219
+ return {
1220
+ isError: true,
1221
+ content: [{ type: "text", text: `Failed to read mail thread: ${err.message}` }]
1222
+ };
1223
+ }
1083
1224
  }
1084
- }
1085
- );
1086
- server.tool(
1087
- "taghost_mail_send",
1088
- "Send an email from a TagMail mailbox.",
1089
- {
1090
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1091
- mailboxId: import_zod3.z.string().optional().describe("Sender mailbox ID (defaults to project primary mailbox)"),
1092
- to: import_zod3.z.string().describe("Recipient email address"),
1093
- subject: import_zod3.z.string().describe("Email subject line"),
1094
- text: import_zod3.z.string().optional().describe("Plain text body content"),
1095
- html: import_zod3.z.string().optional().describe("HTML formatted body content"),
1096
- cc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional CC recipients"),
1097
- bcc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional BCC recipients")
1098
- },
1099
- async ({ projectId, mailboxId, to, subject, text, html, cc, bcc }) => {
1100
- try {
1101
- const id = await client.resolveProjectId(projectId);
1102
- const result = await client.sendMail(id, {
1103
- mailboxId,
1104
- to,
1105
- subject,
1106
- text,
1107
- html,
1108
- cc,
1109
- bcc
1110
- });
1111
- return {
1112
- content: [
1113
- {
1114
- type: "text",
1115
- text: JSON.stringify(
1116
- {
1117
- success: true,
1118
- message: `Email sent to ${to} successfully.`,
1119
- result
1120
- },
1121
- null,
1122
- 2
1123
- )
1124
- }
1125
- ]
1126
- };
1127
- } catch (err) {
1128
- return {
1129
- isError: true,
1130
- content: [{ type: "text", text: `Failed to send email: ${err.message}` }]
1131
- };
1225
+ );
1226
+ }
1227
+ if (hasMcpScope(scopes, "mail:send")) {
1228
+ server.tool(
1229
+ "taghost_mail_send",
1230
+ "Send an email from a TagMail mailbox.",
1231
+ {
1232
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1233
+ mailboxId: import_zod3.z.string().optional().describe("Sender mailbox ID (defaults to project primary mailbox)"),
1234
+ to: import_zod3.z.string().describe("Recipient email address"),
1235
+ subject: import_zod3.z.string().describe("Email subject line"),
1236
+ text: import_zod3.z.string().optional().describe("Plain text body content"),
1237
+ html: import_zod3.z.string().optional().describe("HTML formatted body content"),
1238
+ cc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional CC recipients"),
1239
+ bcc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional BCC recipients")
1240
+ },
1241
+ async ({ projectId, mailboxId, to, subject, text, html, cc, bcc }) => {
1242
+ try {
1243
+ const id = await client.resolveProjectId(projectId);
1244
+ const result = await client.sendMail(id, {
1245
+ mailboxId,
1246
+ to,
1247
+ subject,
1248
+ text,
1249
+ html,
1250
+ cc,
1251
+ bcc
1252
+ });
1253
+ return {
1254
+ content: [
1255
+ {
1256
+ type: "text",
1257
+ text: JSON.stringify(
1258
+ {
1259
+ success: true,
1260
+ message: `Email sent to ${to} successfully.`,
1261
+ result
1262
+ },
1263
+ null,
1264
+ 2
1265
+ )
1266
+ }
1267
+ ]
1268
+ };
1269
+ } catch (err) {
1270
+ return {
1271
+ isError: true,
1272
+ content: [{ type: "text", text: `Failed to send email: ${err.message}` }]
1273
+ };
1274
+ }
1132
1275
  }
1133
- }
1134
- );
1135
- server.tool(
1136
- "taghost_mail_create_mailbox",
1137
- 'Provision a new corporate mailbox (e.g. "sales@acme.com" or "hello@acme.com") on TagHost.',
1138
- {
1139
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1140
- localPart: import_zod3.z.string().describe('Local part of address before @ (e.g. "support", "orders", "hello")'),
1141
- domain: import_zod3.z.string().optional().describe("Domain name for mailbox (defaults to project custom domain)"),
1142
- displayName: import_zod3.z.string().optional().describe('Friendly display name (e.g. "Support Team")'),
1143
- password: import_zod3.z.string().optional().describe("Initial password for Webmail/IMAP/SMTP access")
1144
- },
1145
- async ({ projectId, localPart, domain, displayName, password }) => {
1146
- try {
1147
- const id = await client.resolveProjectId(projectId);
1148
- const result = await client.createMailbox(id, {
1149
- localPart,
1150
- domain,
1151
- displayName,
1152
- password
1153
- });
1154
- return {
1155
- content: [
1156
- {
1157
- type: "text",
1158
- text: JSON.stringify(
1159
- {
1160
- success: true,
1161
- message: `Mailbox "${localPart}@${domain || "custom-domain"}" created.`,
1162
- mailbox: result.mailbox || result
1163
- },
1164
- null,
1165
- 2
1166
- )
1167
- }
1168
- ]
1169
- };
1170
- } catch (err) {
1171
- return {
1172
- isError: true,
1173
- content: [{ type: "text", text: `Failed to create mailbox: ${err.message}` }]
1174
- };
1276
+ );
1277
+ server.tool(
1278
+ "taghost_mail_create_mailbox",
1279
+ 'Provision a new corporate mailbox (e.g. "sales@acme.com" or "hello@acme.com") on TagHost.',
1280
+ {
1281
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1282
+ localPart: import_zod3.z.string().describe('Local part of address before @ (e.g. "support", "orders", "hello")'),
1283
+ domain: import_zod3.z.string().optional().describe("Domain name for mailbox (defaults to project custom domain)"),
1284
+ displayName: import_zod3.z.string().optional().describe('Friendly display name (e.g. "Support Team")'),
1285
+ password: import_zod3.z.string().optional().describe("Initial password for Webmail/IMAP/SMTP access")
1286
+ },
1287
+ async ({ projectId, localPart, domain, displayName, password }) => {
1288
+ try {
1289
+ const id = await client.resolveProjectId(projectId);
1290
+ const result = await client.createMailbox(id, {
1291
+ localPart,
1292
+ domain,
1293
+ displayName,
1294
+ password
1295
+ });
1296
+ return {
1297
+ content: [
1298
+ {
1299
+ type: "text",
1300
+ text: JSON.stringify(
1301
+ {
1302
+ success: true,
1303
+ message: `Mailbox "${localPart}@${domain || "custom-domain"}" created.`,
1304
+ mailbox: result.mailbox || result
1305
+ },
1306
+ null,
1307
+ 2
1308
+ )
1309
+ }
1310
+ ]
1311
+ };
1312
+ } catch (err) {
1313
+ return {
1314
+ isError: true,
1315
+ content: [{ type: "text", text: `Failed to create mailbox: ${err.message}` }]
1316
+ };
1317
+ }
1175
1318
  }
1176
- }
1177
- );
1178
- server.tool(
1179
- "taghost_mail_domain_verify",
1180
- "Inspect DNS verification status for corporate email (MX, SPF, DKIM, DMARC records).",
1181
- {
1182
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1183
- domain: import_zod3.z.string().describe('Domain name to verify (e.g. "acme.com")')
1184
- },
1185
- async ({ projectId, domain }) => {
1186
- try {
1187
- const id = await client.resolveProjectId(projectId);
1188
- const result = await client.getMailDomainVerification(id, domain);
1189
- return {
1190
- content: [
1191
- {
1192
- type: "text",
1193
- text: JSON.stringify({ success: true, domain, verification: result }, null, 2)
1194
- }
1195
- ]
1196
- };
1197
- } catch (err) {
1198
- return {
1199
- isError: true,
1200
- content: [{ type: "text", text: `Failed to verify email domain: ${err.message}` }]
1201
- };
1319
+ );
1320
+ }
1321
+ if (hasMcpScope(scopes, "mail:read")) {
1322
+ server.tool(
1323
+ "taghost_mail_domain_verify",
1324
+ "Inspect DNS verification status for corporate email (MX, SPF, DKIM, DMARC records).",
1325
+ {
1326
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1327
+ domain: import_zod3.z.string().describe('Domain name to verify (e.g. "acme.com")')
1328
+ },
1329
+ async ({ projectId, domain }) => {
1330
+ try {
1331
+ const id = await client.resolveProjectId(projectId);
1332
+ const result = await client.getMailDomainVerification(id, domain);
1333
+ return {
1334
+ content: [
1335
+ {
1336
+ type: "text",
1337
+ text: JSON.stringify({ success: true, domain, verification: result }, null, 2)
1338
+ }
1339
+ ]
1340
+ };
1341
+ } catch (err) {
1342
+ return {
1343
+ isError: true,
1344
+ content: [{ type: "text", text: `Failed to verify email domain: ${err.message}` }]
1345
+ };
1346
+ }
1202
1347
  }
1203
- }
1204
- );
1348
+ );
1349
+ }
1205
1350
  }
1206
1351
 
1207
1352
  // src/tools/domains.ts
@@ -1691,7 +1836,7 @@ function registerCommerceTools(server, client) {
1691
1836
  );
1692
1837
  server.tool(
1693
1838
  "taghost_commerce_migrate_woocommerce",
1694
- "Migrate a WordPress/WooCommerce ecommerce site to TagHost. Migrates products into Edge Collections, customers, orders, and scrapes theme styling tokens.",
1839
+ "Migrate a WordPress/WooCommerce site to TagHost Edge. Migrates products, posts, pages, custom post types, customers, orders, R2 media, theme tokens, and 301 _redirects.",
1695
1840
  {
1696
1841
  projectId: import_zod5.z.string().optional().describe("Project ID. Defaults to active project."),
1697
1842
  url: import_zod5.z.string().optional().describe('WordPress/WooCommerce site URL (e.g. "https://my-store.com")'),
@@ -1699,19 +1844,24 @@ function registerCommerceTools(server, client) {
1699
1844
  consumerSecret: import_zod5.z.string().optional().describe("WooCommerce REST API Consumer Secret (cs_...)"),
1700
1845
  products: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce product objects to import (or parsed from CSV/JSON)"),
1701
1846
  posts: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WordPress blog post objects to import"),
1847
+ pages: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WordPress page objects to import"),
1702
1848
  customers: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce customer objects to import"),
1703
1849
  orders: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce order objects to import"),
1704
1850
  wxrXml: import_zod5.z.string().optional().describe("Raw WordPress WXR XML export content (from Tools > Export) for complete offline migration"),
1705
1851
  options: import_zod5.z.object({
1706
1852
  importProducts: import_zod5.z.boolean().optional().describe("Whether to import products (default: true)"),
1707
1853
  importPosts: import_zod5.z.boolean().optional().describe("Whether to import WordPress blog posts (default: true)"),
1854
+ importPages: import_zod5.z.boolean().optional().describe("Whether to import WordPress pages into a pages collection (default: true)"),
1708
1855
  importCustomers: import_zod5.z.boolean().optional().describe("Whether to import customers (default: true)"),
1709
1856
  importOrders: import_zod5.z.boolean().optional().describe("Whether to import orders (default: true)"),
1710
1857
  scrapeDesign: import_zod5.z.boolean().optional().describe("Whether to scrape brand design & font tokens from site HTML (default: true)"),
1711
- mirrorMedia: import_zod5.z.boolean().optional().describe("Whether to mirror remote images into Cloudflare R2 Edge Storage (default: true)")
1858
+ mirrorMedia: import_zod5.z.boolean().optional().describe("Whether to mirror remote images into Cloudflare R2 Edge Storage (default: true)"),
1859
+ cleanMarkup: import_zod5.z.boolean().optional().describe("Whether to strip Gutenberg comments and legacy page-builder shortcodes (default: true)"),
1860
+ writeRedirects: import_zod5.z.boolean().optional().describe("Whether to generate and merge 301 _redirects for legacy WordPress permalinks (default: true)"),
1861
+ maxPages: import_zod5.z.number().int().min(1).max(25).optional().describe("Max REST API pages to fetch per resource (100 items/page, default: 10)")
1712
1862
  }).optional().describe("Migration options")
1713
1863
  },
1714
- async ({ projectId, url, consumerKey, consumerSecret, products, posts, customers, orders, wxrXml, options }) => {
1864
+ async ({ projectId, url, consumerKey, consumerSecret, products, posts, pages, customers, orders, wxrXml, options }) => {
1715
1865
  try {
1716
1866
  const id = await client.resolveProjectId(projectId);
1717
1867
  const res = await client.migrateWooCommerce(id, {
@@ -1720,6 +1870,7 @@ function registerCommerceTools(server, client) {
1720
1870
  consumerSecret,
1721
1871
  products,
1722
1872
  posts,
1873
+ pages,
1723
1874
  customers,
1724
1875
  orders,
1725
1876
  wxrXml,
@@ -1732,11 +1883,17 @@ function registerCommerceTools(server, client) {
1732
1883
  text: JSON.stringify(
1733
1884
  {
1734
1885
  success: res.success,
1735
- message: `WooCommerce migration completed for project ${id}.`,
1886
+ message: `WordPress/WooCommerce migration completed for project ${id}.`,
1736
1887
  summary: {
1737
1888
  productsMigrated: res.productsMigrated,
1889
+ postsMigrated: res.postsMigrated,
1890
+ pagesMigrated: res.pagesMigrated,
1891
+ customItemsMigrated: res.customItemsMigrated,
1892
+ mediaMirrored: res.mediaMirrored,
1738
1893
  customersMigrated: res.customersMigrated,
1739
1894
  ordersMigrated: res.ordersMigrated,
1895
+ redirectsGenerated: res.redirectsGenerated,
1896
+ redirectsAppliedToDeployment: res.redirectsAppliedToDeployment,
1740
1897
  themeScraped: res.themeScraped
1741
1898
  },
1742
1899
  errors: res.errors
@@ -1750,7 +1907,62 @@ function registerCommerceTools(server, client) {
1750
1907
  } catch (err) {
1751
1908
  return {
1752
1909
  isError: true,
1753
- content: [{ type: "text", text: `Failed to execute WooCommerce migration: ${err.message}` }]
1910
+ content: [{ type: "text", text: `Failed to execute WordPress/WooCommerce migration: ${err.message}` }]
1911
+ };
1912
+ }
1913
+ }
1914
+ );
1915
+ server.tool(
1916
+ "taghost_wordpress_visual_clone",
1917
+ "Clone a live WordPress website into TagHost Edge preserving its exact visual design (HTML, theme/Elementor/Divi CSS, webfonts, images) as an immutable R2 deployment ready for Tier 2 Visual Studio editing, with WordPress forms auto-rewired to /_tag/forms/*.",
1918
+ {
1919
+ projectId: import_zod5.z.string().optional().describe("Project ID. Defaults to active project."),
1920
+ url: import_zod5.z.string().describe('Public live WordPress site URL (e.g. "https://example.com")'),
1921
+ maxPages: import_zod5.z.number().int().min(1).max(30).optional().describe("Max pages to clone (default: 15, max: 30)"),
1922
+ maxAssets: import_zod5.z.number().int().min(10).max(250).optional().describe("Max CSS/font/image assets to mirror (default: 120, max: 250)"),
1923
+ rewireForms: import_zod5.z.boolean().optional().describe("Auto-rewire WordPress contact forms to TagHost Edge Forms (default: true)"),
1924
+ syncCollections: import_zod5.z.boolean().optional().describe("Also import WP posts & pages into TagHost Collections CMS (default: false)")
1925
+ },
1926
+ async ({ projectId, url, maxPages, maxAssets, rewireForms, syncCollections }) => {
1927
+ try {
1928
+ const id = await client.resolveProjectId(projectId);
1929
+ const res = await client.cloneWordPressSite(id, {
1930
+ url,
1931
+ maxPages,
1932
+ maxAssets,
1933
+ rewireForms,
1934
+ syncCollections
1935
+ });
1936
+ return {
1937
+ content: [
1938
+ {
1939
+ type: "text",
1940
+ text: JSON.stringify(
1941
+ {
1942
+ success: res.success,
1943
+ message: `WordPress visual clone deployed for project ${id}.`,
1944
+ deployment: res.deployment,
1945
+ summary: {
1946
+ pagesCloned: res.pagesCloned,
1947
+ editablePagesCount: res.editablePagesCount,
1948
+ totalDiscoveredPages: res.totalDiscoveredPages,
1949
+ assetsMirrored: res.assetsMirrored,
1950
+ formsRewired: res.formsRewired,
1951
+ rewiredFormNames: res.rewiredFormNames,
1952
+ detectedDynamicWidgets: res.detectedDynamicWidgets
1953
+ },
1954
+ errors: res.errors
1955
+ },
1956
+ null,
1957
+ 2
1958
+ )
1959
+ }
1960
+ ]
1961
+ };
1962
+ } catch (err) {
1963
+ return {
1964
+ isError: true,
1965
+ content: [{ type: "text", text: `Failed to visually clone WordPress site: ${err.message}` }]
1754
1966
  };
1755
1967
  }
1756
1968
  }
@@ -3377,18 +3589,41 @@ function createTagHostMcpServer(options = {}) {
3377
3589
  version: options.version || "1.0.0"
3378
3590
  });
3379
3591
  const client = new TagHostClient(options);
3380
- registerProjectTools(server, client);
3381
- registerDeploymentTools(server, client);
3382
- registerMailTools(server, client);
3383
- registerDomainTools(server, client);
3384
- registerCommerceTools(server, client);
3385
- registerCollectionTools(server, client);
3386
- registerContentTools(server, client);
3387
- registerFormsCrmTools(server, client);
3388
- registerSqlTools(server, client);
3389
- registerObservabilityTools(server, client);
3390
- registerTasksCollaborationTools(server, client);
3391
- registerResources(server, client);
3592
+ const scopes = options.scopes ?? null;
3593
+ if (hasMcpScope(scopes, "projects:read") || hasMcpScope(scopes, "deployments:write")) {
3594
+ registerProjectTools(server, client, scopes);
3595
+ }
3596
+ if (hasMcpScope(scopes, "deployments:write")) {
3597
+ registerDeploymentTools(server, client);
3598
+ }
3599
+ if (hasMcpScope(scopes, "mail:read") || hasMcpScope(scopes, "mail:send")) {
3600
+ registerMailTools(server, client, scopes);
3601
+ }
3602
+ if (hasMcpScope(scopes, "domains:write")) {
3603
+ registerDomainTools(server, client);
3604
+ }
3605
+ if (hasMcpScope(scopes, "commerce:write")) {
3606
+ registerCommerceTools(server, client);
3607
+ }
3608
+ if (hasMcpScope(scopes, "content:write")) {
3609
+ registerCollectionTools(server, client);
3610
+ registerContentTools(server, client);
3611
+ }
3612
+ if (hasMcpScope(scopes, "forms:read")) {
3613
+ registerFormsCrmTools(server, client);
3614
+ }
3615
+ if (hasMcpScope(scopes, "sql:read")) {
3616
+ registerSqlTools(server, client);
3617
+ }
3618
+ if (hasMcpScope(scopes, "projects:read")) {
3619
+ registerObservabilityTools(server, client);
3620
+ }
3621
+ if (hasMcpScope(scopes, "workspace:collaborate")) {
3622
+ registerTasksCollaborationTools(server, client);
3623
+ }
3624
+ if (hasMcpScope(scopes, "projects:read")) {
3625
+ registerResources(server, client);
3626
+ }
3392
3627
  registerPrompts(server);
3393
3628
  return { server, client };
3394
3629
  }
@@ -3602,7 +3837,9 @@ var TAGHOST_OPENAPI_SPEC = {
3602
3837
  };
3603
3838
  // Annotate the CommonJS export names for ESM import in node:
3604
3839
  0 && (module.exports = {
3840
+ ALL_MCP_SCOPES,
3605
3841
  InMemoryTransport,
3842
+ MCP_SCOPES,
3606
3843
  TAGHOST_OPENAPI_SPEC,
3607
3844
  TagHostClient,
3608
3845
  bundleDirectory,
@@ -3610,7 +3847,10 @@ var TAGHOST_OPENAPI_SPEC = {
3610
3847
  createTagHostMcpServer,
3611
3848
  findProjectBinding,
3612
3849
  getApiUrl,
3850
+ hasMcpScope,
3851
+ normalizeMcpScopes,
3613
3852
  resolveAuthToken,
3853
+ sanitizeAuthToken,
3614
3854
  startServer,
3615
3855
  validateReadOnlySql
3616
3856
  });