@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/server.cjs CHANGED
@@ -49,19 +49,31 @@ function getApiUrl() {
49
49
  function credentialsPath(homeDir = process.env.TAGHOST_HOME || import_node_os.default.homedir()) {
50
50
  return import_node_path.default.join(homeDir, ".taghost", "credentials.json");
51
51
  }
52
+ var PLACEHOLDER_TOKEN_PATTERN = /^<?(your[_-].*token|replace[_-]?me|changeme|placeholder)>?$/i;
53
+ function sanitizeAuthToken(value) {
54
+ if (typeof value !== "string") return null;
55
+ const trimmed = value.trim();
56
+ if (!trimmed || PLACEHOLDER_TOKEN_PATTERN.test(trimmed)) {
57
+ return null;
58
+ }
59
+ return trimmed;
60
+ }
52
61
  function resolveAuthToken() {
53
- if (process.env.TAGHOST_API_TOKEN && process.env.TAGHOST_API_TOKEN.trim()) {
54
- return process.env.TAGHOST_API_TOKEN.trim();
62
+ const apiToken = sanitizeAuthToken(process.env.TAGHOST_API_TOKEN);
63
+ if (apiToken) {
64
+ return apiToken;
55
65
  }
56
- if (process.env.TAGHOST_TOKEN && process.env.TAGHOST_TOKEN.trim()) {
57
- return process.env.TAGHOST_TOKEN.trim();
66
+ const token = sanitizeAuthToken(process.env.TAGHOST_TOKEN);
67
+ if (token) {
68
+ return token;
58
69
  }
59
70
  const credsPath = credentialsPath();
60
71
  if (import_node_fs.default.existsSync(credsPath)) {
61
72
  try {
62
73
  const data = JSON.parse(import_node_fs.default.readFileSync(credsPath, "utf8"));
63
- if (data && typeof data.token === "string" && data.token.trim()) {
64
- return data.token.trim();
74
+ const stored = sanitizeAuthToken(data?.token);
75
+ if (stored) {
76
+ return stored;
65
77
  }
66
78
  } catch {
67
79
  }
@@ -101,16 +113,27 @@ function findProjectBinding(startDir = process.cwd()) {
101
113
  // src/client/taghost-client.ts
102
114
  var TagHostClient = class {
103
115
  apiUrl;
104
- token;
116
+ explicitToken;
105
117
  constructor(options = {}) {
106
118
  this.apiUrl = (options.apiUrl || getApiUrl()).replace(/\/+$/, "");
107
- this.token = options.token || resolveAuthToken();
119
+ this.explicitToken = sanitizeAuthToken(options.token);
120
+ }
121
+ getToken() {
122
+ return this.explicitToken || resolveAuthToken();
108
123
  }
109
124
  async request(endpoint, options = {}) {
110
125
  const url = endpoint.startsWith("http") ? endpoint : `${this.apiUrl}${endpoint.startsWith("/") ? "" : "/"}${endpoint}`;
111
126
  const headers = new Headers(options.headers || {});
112
- if (this.token && !headers.has("Authorization")) {
113
- headers.set("Authorization", `Bearer ${this.token}`);
127
+ if (!headers.has("Authorization")) {
128
+ const token = this.getToken();
129
+ if (!token) {
130
+ const error = new Error(
131
+ 'Not authenticated with TagHost. Run "tag login" (saved to ~/.taghost/credentials.json) or set TAGHOST_API_TOKEN.'
132
+ );
133
+ error.status = 401;
134
+ throw error;
135
+ }
136
+ headers.set("Authorization", `Bearer ${token}`);
114
137
  }
115
138
  const response = await fetch(url, {
116
139
  ...options,
@@ -334,6 +357,13 @@ var TagHostClient = class {
334
357
  body: JSON.stringify(payload)
335
358
  });
336
359
  }
360
+ async cloneWordPressSite(projectId, payload) {
361
+ return this.request(`/projects/${projectId}/migrations/wordpress/clone`, {
362
+ method: "POST",
363
+ headers: { "Content-Type": "application/json" },
364
+ body: JSON.stringify(payload)
365
+ });
366
+ }
337
367
  async listOrders(projectId, options = {}) {
338
368
  const params = new URLSearchParams();
339
369
  if (options.status) params.set("status", options.status);
@@ -556,154 +586,246 @@ var TagHostClient = class {
556
586
 
557
587
  // src/tools/projects.ts
558
588
  var import_zod = require("zod");
559
- function registerProjectTools(server, client) {
560
- server.tool(
561
- "taghost_project_create",
562
- "Create a new project on TagHost edge platform.",
563
- {
564
- name: import_zod.z.string().describe('Human readable name of the project (e.g. "Acme Storefront")'),
565
- slug: import_zod.z.string().optional().describe('URL slug for the project (e.g. "acme-storefront")'),
566
- framework: import_zod.z.string().optional().describe('Framework template (e.g. "html", "react", "nextjs", "vue")')
567
- },
568
- async ({ name, slug, framework }) => {
569
- try {
570
- const result = await client.createProject({ name, slug, framework });
571
- return {
572
- content: [
573
- {
574
- type: "text",
575
- text: JSON.stringify(
576
- {
577
- success: true,
578
- message: `Project "${name}" created successfully.`,
579
- project: result.project || result
580
- },
581
- null,
582
- 2
583
- )
584
- }
585
- ]
586
- };
587
- } catch (err) {
588
- return {
589
- isError: true,
590
- content: [{ type: "text", text: `Failed to create project: ${err.message}` }]
591
- };
592
- }
593
- }
594
- );
595
- server.tool(
596
- "taghost_project_list",
597
- "List all projects accessible within the current TagHost workspace.",
598
- {
599
- limit: import_zod.z.number().optional().describe("Maximum number of projects to return (default: 50)")
600
- },
601
- async ({ limit }) => {
602
- try {
603
- const result = await client.listProjects();
604
- const list = Array.isArray(result) ? result : result.projects || [];
605
- const items = limit ? list.slice(0, limit) : list;
606
- return {
607
- content: [
608
- {
609
- type: "text",
610
- text: JSON.stringify({ success: true, count: items.length, projects: items }, null, 2)
611
- }
612
- ]
613
- };
614
- } catch (err) {
615
- return {
616
- isError: true,
617
- content: [{ type: "text", text: `Failed to list projects: ${err.message}` }]
618
- };
619
- }
620
- }
621
- );
622
- server.tool(
623
- "taghost_project_get",
624
- "Get detailed information about a specific TagHost project, including active deployment and domains.",
625
- {
626
- projectId: import_zod.z.string().optional().describe('Project ID (e.g. "proj_..."). Defaults to active project.')
627
- },
628
- async ({ projectId }) => {
629
- try {
630
- const id = await client.resolveProjectId(projectId);
631
- const result = await client.getProject(id);
632
- return {
633
- content: [
634
- {
635
- type: "text",
636
- text: JSON.stringify({ success: true, project: result.project || result }, null, 2)
637
- }
638
- ]
639
- };
640
- } catch (err) {
641
- return {
642
- isError: true,
643
- content: [{ type: "text", text: `Failed to get project: ${err.message}` }]
644
- };
645
- }
646
- }
647
- );
648
- server.tool(
649
- "taghost_env_manage",
650
- "Manage environment variables for a TagHost project.",
651
- {
652
- projectId: import_zod.z.string().optional().describe("Project ID. Defaults to active project."),
653
- action: import_zod.z.enum(["list", "set", "delete"]).describe("Action to perform"),
654
- key: import_zod.z.string().optional().describe("Environment variable key"),
655
- value: import_zod.z.string().optional().describe("Environment variable value (for set action)"),
656
- target: import_zod.z.enum(["production", "preview", "all"]).optional().describe("Deployment target")
657
- },
658
- async ({ projectId, action, key, value, target }) => {
659
- try {
660
- const id = await client.resolveProjectId(projectId);
661
- if (action === "list") {
662
- const res = await client.getProjectEnv(id);
589
+
590
+ // src/scopes.ts
591
+ var MCP_SCOPES = [
592
+ {
593
+ id: "projects:read",
594
+ label: "Projects & quotas",
595
+ description: "List projects, inspect configuration, check quotas, and preview AST eject output.",
596
+ icon: "layers",
597
+ access: "read",
598
+ defaultSelected: true
599
+ },
600
+ {
601
+ id: "deployments:write",
602
+ label: "Deployments & environment",
603
+ description: "Deploy site bundles, publish partial files, manage env vars, set expiry, and rollback.",
604
+ icon: "deployed_code",
605
+ access: "write",
606
+ defaultSelected: true
607
+ },
608
+ {
609
+ id: "content:write",
610
+ label: "Edge content & collections",
611
+ description: "Edit [data-tag] bindings, patch HTML canvas elements, and publish CMS collection items.",
612
+ icon: "draw",
613
+ access: "write",
614
+ defaultSelected: true
615
+ },
616
+ {
617
+ id: "domains:write",
618
+ label: "Domains & DNS",
619
+ description: "Search/check domain availability, attach custom domains, verify SSL, and manage DNS records.",
620
+ icon: "language",
621
+ access: "write"
622
+ },
623
+ {
624
+ id: "mail:read",
625
+ label: "TagMail (read)",
626
+ description: "List and read TagMail threads and check mail domain DNS verification.",
627
+ icon: "inbox",
628
+ access: "read"
629
+ },
630
+ {
631
+ id: "mail:send",
632
+ label: "TagMail (send & mailboxes)",
633
+ description: "Send outbound transactional email and create workspace mailboxes.",
634
+ icon: "mail",
635
+ access: "write"
636
+ },
637
+ {
638
+ id: "commerce:write",
639
+ label: "Commerce & orders",
640
+ description: "Configure stores, manage coupons, view/fulfill orders, and migrate catalogs.",
641
+ icon: "storefront",
642
+ access: "write"
643
+ },
644
+ {
645
+ id: "forms:read",
646
+ label: "Forms, CRM & webhooks",
647
+ description: "Inspect form submissions, enroll leads in CRM sequences, and configure webhooks.",
648
+ icon: "assignment",
649
+ access: "write"
650
+ },
651
+ {
652
+ id: "sql:read",
653
+ label: "Serverless D1 SQL (read-only)",
654
+ description: "Introspect project database schemas and execute read-only SELECT queries.",
655
+ icon: "database",
656
+ access: "read"
657
+ },
658
+ {
659
+ id: "workspace:collaborate",
660
+ label: "Tasks, calendar, notes & Meet",
661
+ description: "Manage TagWork tasks, calendar events, notes, Meet rooms, and scheduled automations.",
662
+ icon: "event",
663
+ access: "write"
664
+ }
665
+ ];
666
+ var ALL_MCP_SCOPES = MCP_SCOPES.map((s) => s.id);
667
+ var VALID_SCOPE_SET = new Set(ALL_MCP_SCOPES);
668
+ function hasMcpScope(granted, required) {
669
+ if (granted == null) return true;
670
+ if (granted.includes("*")) return true;
671
+ return granted.includes(required);
672
+ }
673
+
674
+ // src/tools/projects.ts
675
+ function registerProjectTools(server, client, scopes) {
676
+ if (hasMcpScope(scopes, "deployments:write")) {
677
+ server.tool(
678
+ "taghost_project_create",
679
+ "Create a new project on TagHost edge platform.",
680
+ {
681
+ name: import_zod.z.string().describe('Human readable name of the project (e.g. "Acme Storefront")'),
682
+ slug: import_zod.z.string().optional().describe('URL slug for the project (e.g. "acme-storefront")'),
683
+ framework: import_zod.z.string().optional().describe('Framework template (e.g. "html", "react", "nextjs", "vue")')
684
+ },
685
+ async ({ name, slug, framework }) => {
686
+ try {
687
+ const result = await client.createProject({ name, slug, framework });
663
688
  return {
664
- content: [{ type: "text", text: JSON.stringify({ success: true, envVars: res }, null, 2) }]
689
+ content: [
690
+ {
691
+ type: "text",
692
+ text: JSON.stringify(
693
+ {
694
+ success: true,
695
+ message: `Project "${name}" created successfully.`,
696
+ project: result.project || result
697
+ },
698
+ null,
699
+ 2
700
+ )
701
+ }
702
+ ]
703
+ };
704
+ } catch (err) {
705
+ return {
706
+ isError: true,
707
+ content: [{ type: "text", text: `Failed to create project: ${err.message}` }]
665
708
  };
666
709
  }
667
- if (action === "set") {
668
- if (!key || value === void 0) {
669
- return {
670
- isError: true,
671
- content: [{ type: "text", text: 'Both key and value are required for "set" action.' }]
672
- };
673
- }
674
- const res = await client.setProjectEnv(id, key, value, target || "all");
710
+ }
711
+ );
712
+ }
713
+ if (hasMcpScope(scopes, "projects:read")) {
714
+ server.tool(
715
+ "taghost_project_list",
716
+ "List all projects accessible within the current TagHost workspace.",
717
+ {
718
+ limit: import_zod.z.number().optional().describe("Maximum number of projects to return (default: 50)")
719
+ },
720
+ async ({ limit }) => {
721
+ try {
722
+ const result = await client.listProjects();
723
+ const list = Array.isArray(result) ? result : result.projects || [];
724
+ const items = limit ? list.slice(0, limit) : list;
675
725
  return {
676
726
  content: [
677
727
  {
678
728
  type: "text",
679
- text: JSON.stringify({ success: true, message: `Environment variable "${key}" set.`, result: res }, null, 2)
729
+ text: JSON.stringify({ success: true, count: items.length, projects: items }, null, 2)
680
730
  }
681
731
  ]
682
732
  };
733
+ } catch (err) {
734
+ return {
735
+ isError: true,
736
+ content: [{ type: "text", text: `Failed to list projects: ${err.message}` }]
737
+ };
683
738
  }
684
- if (action === "delete") {
685
- if (!key) {
686
- return { isError: true, content: [{ type: "text", text: 'Key is required for "delete" action.' }] };
687
- }
688
- await client.deleteProjectEnv(id, key);
739
+ }
740
+ );
741
+ server.tool(
742
+ "taghost_project_get",
743
+ "Get detailed information about a specific TagHost project, including active deployment and domains.",
744
+ {
745
+ projectId: import_zod.z.string().optional().describe('Project ID (e.g. "proj_..."). Defaults to active project.')
746
+ },
747
+ async ({ projectId }) => {
748
+ try {
749
+ const id = await client.resolveProjectId(projectId);
750
+ const result = await client.getProject(id);
689
751
  return {
690
752
  content: [
691
753
  {
692
754
  type: "text",
693
- text: JSON.stringify({ success: true, message: `Environment variable "${key}" deleted.` }, null, 2)
755
+ text: JSON.stringify({ success: true, project: result.project || result }, null, 2)
694
756
  }
695
757
  ]
696
758
  };
759
+ } catch (err) {
760
+ return {
761
+ isError: true,
762
+ content: [{ type: "text", text: `Failed to get project: ${err.message}` }]
763
+ };
697
764
  }
698
- return { isError: true, content: [{ type: "text", text: `Unknown action: ${action}` }] };
699
- } catch (err) {
700
- return {
701
- isError: true,
702
- content: [{ type: "text", text: `Failed to manage env vars: ${err.message}` }]
703
- };
704
765
  }
705
- }
706
- );
766
+ );
767
+ }
768
+ if (hasMcpScope(scopes, "deployments:write")) {
769
+ server.tool(
770
+ "taghost_env_manage",
771
+ "Manage environment variables for a TagHost project.",
772
+ {
773
+ projectId: import_zod.z.string().optional().describe("Project ID. Defaults to active project."),
774
+ action: import_zod.z.enum(["list", "set", "delete"]).describe("Action to perform"),
775
+ key: import_zod.z.string().optional().describe("Environment variable key"),
776
+ value: import_zod.z.string().optional().describe("Environment variable value (for set action)"),
777
+ target: import_zod.z.enum(["production", "preview", "all"]).optional().describe("Deployment target")
778
+ },
779
+ async ({ projectId, action, key, value, target }) => {
780
+ try {
781
+ const id = await client.resolveProjectId(projectId);
782
+ if (action === "list") {
783
+ const res = await client.getProjectEnv(id);
784
+ return {
785
+ content: [{ type: "text", text: JSON.stringify({ success: true, envVars: res }, null, 2) }]
786
+ };
787
+ }
788
+ if (action === "set") {
789
+ if (!key || value === void 0) {
790
+ return {
791
+ isError: true,
792
+ content: [{ type: "text", text: 'Both key and value are required for "set" action.' }]
793
+ };
794
+ }
795
+ const res = await client.setProjectEnv(id, key, value, target || "all");
796
+ return {
797
+ content: [
798
+ {
799
+ type: "text",
800
+ text: JSON.stringify({ success: true, message: `Environment variable "${key}" set.`, result: res }, null, 2)
801
+ }
802
+ ]
803
+ };
804
+ }
805
+ if (action === "delete") {
806
+ if (!key) {
807
+ return { isError: true, content: [{ type: "text", text: 'Key is required for "delete" action.' }] };
808
+ }
809
+ await client.deleteProjectEnv(id, key);
810
+ return {
811
+ content: [
812
+ {
813
+ type: "text",
814
+ text: JSON.stringify({ success: true, message: `Environment variable "${key}" deleted.` }, null, 2)
815
+ }
816
+ ]
817
+ };
818
+ }
819
+ return { isError: true, content: [{ type: "text", text: `Unknown action: ${action}` }] };
820
+ } catch (err) {
821
+ return {
822
+ isError: true,
823
+ content: [{ type: "text", text: `Failed to manage env vars: ${err.message}` }]
824
+ };
825
+ }
826
+ }
827
+ );
828
+ }
707
829
  }
708
830
 
709
831
  // src/tools/deployments.ts
@@ -976,199 +1098,205 @@ function registerDeploymentTools(server, client) {
976
1098
 
977
1099
  // src/tools/mail.ts
978
1100
  var import_zod3 = require("zod");
979
- function registerMailTools(server, client) {
980
- server.tool(
981
- "taghost_mail_threads_list",
982
- "Check mail: list email threads and messages in the TagMail inbox with search and mailbox filters.",
983
- {
984
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
985
- mailboxId: import_zod3.z.string().optional().describe("Filter by specific mailbox ID"),
986
- query: import_zod3.z.string().optional().describe("Search query for sender, subject or body text"),
987
- limit: import_zod3.z.number().optional().describe("Maximum number of threads to return (default: 25)")
988
- },
989
- async ({ projectId, mailboxId, query, limit }) => {
990
- try {
991
- const id = await client.resolveProjectId(projectId);
992
- const result = await client.listMailThreads(id, { mailboxId, query, limit: limit || 25 });
993
- const threads = Array.isArray(result) ? result : result.threads || [];
994
- return {
995
- content: [
996
- {
997
- type: "text",
998
- text: JSON.stringify(
999
- {
1000
- success: true,
1001
- count: threads.length,
1002
- threads: threads.map((t) => ({
1003
- id: t.id,
1004
- subject: t.subject || "(no subject)",
1005
- from: t.fromAddress || t.snippetSender,
1006
- snippet: t.snippet,
1007
- unread: Boolean(t.unread),
1008
- messageCount: t.messageCount || 1,
1009
- receivedAt: t.lastMessageAt || t.receivedAt || t.createdAt
1010
- }))
1011
- },
1012
- null,
1013
- 2
1014
- )
1015
- }
1016
- ]
1017
- };
1018
- } catch (err) {
1019
- return {
1020
- isError: true,
1021
- content: [{ type: "text", text: `Failed to check mail: ${err.message}` }]
1022
- };
1101
+ function registerMailTools(server, client, scopes) {
1102
+ if (hasMcpScope(scopes, "mail:read")) {
1103
+ server.tool(
1104
+ "taghost_mail_threads_list",
1105
+ "Check mail: list email threads and messages in the TagMail inbox with search and mailbox filters.",
1106
+ {
1107
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1108
+ mailboxId: import_zod3.z.string().optional().describe("Filter by specific mailbox ID"),
1109
+ query: import_zod3.z.string().optional().describe("Search query for sender, subject or body text"),
1110
+ limit: import_zod3.z.number().optional().describe("Maximum number of threads to return (default: 25)")
1111
+ },
1112
+ async ({ projectId, mailboxId, query, limit }) => {
1113
+ try {
1114
+ const id = await client.resolveProjectId(projectId);
1115
+ const result = await client.listMailThreads(id, { mailboxId, query, limit: limit || 25 });
1116
+ const threads = Array.isArray(result) ? result : result.threads || [];
1117
+ return {
1118
+ content: [
1119
+ {
1120
+ type: "text",
1121
+ text: JSON.stringify(
1122
+ {
1123
+ success: true,
1124
+ count: threads.length,
1125
+ threads: threads.map((t) => ({
1126
+ id: t.id,
1127
+ subject: t.subject || "(no subject)",
1128
+ from: t.fromAddress || t.snippetSender,
1129
+ snippet: t.snippet,
1130
+ unread: Boolean(t.unread),
1131
+ messageCount: t.messageCount || 1,
1132
+ receivedAt: t.lastMessageAt || t.receivedAt || t.createdAt
1133
+ }))
1134
+ },
1135
+ null,
1136
+ 2
1137
+ )
1138
+ }
1139
+ ]
1140
+ };
1141
+ } catch (err) {
1142
+ return {
1143
+ isError: true,
1144
+ content: [{ type: "text", text: `Failed to check mail: ${err.message}` }]
1145
+ };
1146
+ }
1023
1147
  }
1024
- }
1025
- );
1026
- server.tool(
1027
- "taghost_mail_thread_get",
1028
- "Read the full contents of an email thread, including all inbound and outbound messages and attachment metadata.",
1029
- {
1030
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1031
- threadId: import_zod3.z.string().describe("The email thread ID to retrieve")
1032
- },
1033
- async ({ projectId, threadId }) => {
1034
- try {
1035
- const id = await client.resolveProjectId(projectId);
1036
- const result = await client.getMailThread(id, threadId);
1037
- return {
1038
- content: [
1039
- {
1040
- type: "text",
1041
- text: JSON.stringify({ success: true, thread: result.thread || result }, null, 2)
1042
- }
1043
- ]
1044
- };
1045
- } catch (err) {
1046
- return {
1047
- isError: true,
1048
- content: [{ type: "text", text: `Failed to read mail thread: ${err.message}` }]
1049
- };
1148
+ );
1149
+ server.tool(
1150
+ "taghost_mail_thread_get",
1151
+ "Read the full contents of an email thread, including all inbound and outbound messages and attachment metadata.",
1152
+ {
1153
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1154
+ threadId: import_zod3.z.string().describe("The email thread ID to retrieve")
1155
+ },
1156
+ async ({ projectId, threadId }) => {
1157
+ try {
1158
+ const id = await client.resolveProjectId(projectId);
1159
+ const result = await client.getMailThread(id, threadId);
1160
+ return {
1161
+ content: [
1162
+ {
1163
+ type: "text",
1164
+ text: JSON.stringify({ success: true, thread: result.thread || result }, null, 2)
1165
+ }
1166
+ ]
1167
+ };
1168
+ } catch (err) {
1169
+ return {
1170
+ isError: true,
1171
+ content: [{ type: "text", text: `Failed to read mail thread: ${err.message}` }]
1172
+ };
1173
+ }
1050
1174
  }
1051
- }
1052
- );
1053
- server.tool(
1054
- "taghost_mail_send",
1055
- "Send an email from a TagMail mailbox.",
1056
- {
1057
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1058
- mailboxId: import_zod3.z.string().optional().describe("Sender mailbox ID (defaults to project primary mailbox)"),
1059
- to: import_zod3.z.string().describe("Recipient email address"),
1060
- subject: import_zod3.z.string().describe("Email subject line"),
1061
- text: import_zod3.z.string().optional().describe("Plain text body content"),
1062
- html: import_zod3.z.string().optional().describe("HTML formatted body content"),
1063
- cc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional CC recipients"),
1064
- bcc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional BCC recipients")
1065
- },
1066
- async ({ projectId, mailboxId, to, subject, text, html, cc, bcc }) => {
1067
- try {
1068
- const id = await client.resolveProjectId(projectId);
1069
- const result = await client.sendMail(id, {
1070
- mailboxId,
1071
- to,
1072
- subject,
1073
- text,
1074
- html,
1075
- cc,
1076
- bcc
1077
- });
1078
- return {
1079
- content: [
1080
- {
1081
- type: "text",
1082
- text: JSON.stringify(
1083
- {
1084
- success: true,
1085
- message: `Email sent to ${to} successfully.`,
1086
- result
1087
- },
1088
- null,
1089
- 2
1090
- )
1091
- }
1092
- ]
1093
- };
1094
- } catch (err) {
1095
- return {
1096
- isError: true,
1097
- content: [{ type: "text", text: `Failed to send email: ${err.message}` }]
1098
- };
1175
+ );
1176
+ }
1177
+ if (hasMcpScope(scopes, "mail:send")) {
1178
+ server.tool(
1179
+ "taghost_mail_send",
1180
+ "Send an email from a TagMail mailbox.",
1181
+ {
1182
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1183
+ mailboxId: import_zod3.z.string().optional().describe("Sender mailbox ID (defaults to project primary mailbox)"),
1184
+ to: import_zod3.z.string().describe("Recipient email address"),
1185
+ subject: import_zod3.z.string().describe("Email subject line"),
1186
+ text: import_zod3.z.string().optional().describe("Plain text body content"),
1187
+ html: import_zod3.z.string().optional().describe("HTML formatted body content"),
1188
+ cc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional CC recipients"),
1189
+ bcc: import_zod3.z.array(import_zod3.z.string()).optional().describe("Optional BCC recipients")
1190
+ },
1191
+ async ({ projectId, mailboxId, to, subject, text, html, cc, bcc }) => {
1192
+ try {
1193
+ const id = await client.resolveProjectId(projectId);
1194
+ const result = await client.sendMail(id, {
1195
+ mailboxId,
1196
+ to,
1197
+ subject,
1198
+ text,
1199
+ html,
1200
+ cc,
1201
+ bcc
1202
+ });
1203
+ return {
1204
+ content: [
1205
+ {
1206
+ type: "text",
1207
+ text: JSON.stringify(
1208
+ {
1209
+ success: true,
1210
+ message: `Email sent to ${to} successfully.`,
1211
+ result
1212
+ },
1213
+ null,
1214
+ 2
1215
+ )
1216
+ }
1217
+ ]
1218
+ };
1219
+ } catch (err) {
1220
+ return {
1221
+ isError: true,
1222
+ content: [{ type: "text", text: `Failed to send email: ${err.message}` }]
1223
+ };
1224
+ }
1099
1225
  }
1100
- }
1101
- );
1102
- server.tool(
1103
- "taghost_mail_create_mailbox",
1104
- 'Provision a new corporate mailbox (e.g. "sales@acme.com" or "hello@acme.com") on TagHost.',
1105
- {
1106
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1107
- localPart: import_zod3.z.string().describe('Local part of address before @ (e.g. "support", "orders", "hello")'),
1108
- domain: import_zod3.z.string().optional().describe("Domain name for mailbox (defaults to project custom domain)"),
1109
- displayName: import_zod3.z.string().optional().describe('Friendly display name (e.g. "Support Team")'),
1110
- password: import_zod3.z.string().optional().describe("Initial password for Webmail/IMAP/SMTP access")
1111
- },
1112
- async ({ projectId, localPart, domain, displayName, password }) => {
1113
- try {
1114
- const id = await client.resolveProjectId(projectId);
1115
- const result = await client.createMailbox(id, {
1116
- localPart,
1117
- domain,
1118
- displayName,
1119
- password
1120
- });
1121
- return {
1122
- content: [
1123
- {
1124
- type: "text",
1125
- text: JSON.stringify(
1126
- {
1127
- success: true,
1128
- message: `Mailbox "${localPart}@${domain || "custom-domain"}" created.`,
1129
- mailbox: result.mailbox || result
1130
- },
1131
- null,
1132
- 2
1133
- )
1134
- }
1135
- ]
1136
- };
1137
- } catch (err) {
1138
- return {
1139
- isError: true,
1140
- content: [{ type: "text", text: `Failed to create mailbox: ${err.message}` }]
1141
- };
1226
+ );
1227
+ server.tool(
1228
+ "taghost_mail_create_mailbox",
1229
+ 'Provision a new corporate mailbox (e.g. "sales@acme.com" or "hello@acme.com") on TagHost.',
1230
+ {
1231
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1232
+ localPart: import_zod3.z.string().describe('Local part of address before @ (e.g. "support", "orders", "hello")'),
1233
+ domain: import_zod3.z.string().optional().describe("Domain name for mailbox (defaults to project custom domain)"),
1234
+ displayName: import_zod3.z.string().optional().describe('Friendly display name (e.g. "Support Team")'),
1235
+ password: import_zod3.z.string().optional().describe("Initial password for Webmail/IMAP/SMTP access")
1236
+ },
1237
+ async ({ projectId, localPart, domain, displayName, password }) => {
1238
+ try {
1239
+ const id = await client.resolveProjectId(projectId);
1240
+ const result = await client.createMailbox(id, {
1241
+ localPart,
1242
+ domain,
1243
+ displayName,
1244
+ password
1245
+ });
1246
+ return {
1247
+ content: [
1248
+ {
1249
+ type: "text",
1250
+ text: JSON.stringify(
1251
+ {
1252
+ success: true,
1253
+ message: `Mailbox "${localPart}@${domain || "custom-domain"}" created.`,
1254
+ mailbox: result.mailbox || result
1255
+ },
1256
+ null,
1257
+ 2
1258
+ )
1259
+ }
1260
+ ]
1261
+ };
1262
+ } catch (err) {
1263
+ return {
1264
+ isError: true,
1265
+ content: [{ type: "text", text: `Failed to create mailbox: ${err.message}` }]
1266
+ };
1267
+ }
1142
1268
  }
1143
- }
1144
- );
1145
- server.tool(
1146
- "taghost_mail_domain_verify",
1147
- "Inspect DNS verification status for corporate email (MX, SPF, DKIM, DMARC records).",
1148
- {
1149
- projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1150
- domain: import_zod3.z.string().describe('Domain name to verify (e.g. "acme.com")')
1151
- },
1152
- async ({ projectId, domain }) => {
1153
- try {
1154
- const id = await client.resolveProjectId(projectId);
1155
- const result = await client.getMailDomainVerification(id, domain);
1156
- return {
1157
- content: [
1158
- {
1159
- type: "text",
1160
- text: JSON.stringify({ success: true, domain, verification: result }, null, 2)
1161
- }
1162
- ]
1163
- };
1164
- } catch (err) {
1165
- return {
1166
- isError: true,
1167
- content: [{ type: "text", text: `Failed to verify email domain: ${err.message}` }]
1168
- };
1269
+ );
1270
+ }
1271
+ if (hasMcpScope(scopes, "mail:read")) {
1272
+ server.tool(
1273
+ "taghost_mail_domain_verify",
1274
+ "Inspect DNS verification status for corporate email (MX, SPF, DKIM, DMARC records).",
1275
+ {
1276
+ projectId: import_zod3.z.string().optional().describe("Project ID. Defaults to active project."),
1277
+ domain: import_zod3.z.string().describe('Domain name to verify (e.g. "acme.com")')
1278
+ },
1279
+ async ({ projectId, domain }) => {
1280
+ try {
1281
+ const id = await client.resolveProjectId(projectId);
1282
+ const result = await client.getMailDomainVerification(id, domain);
1283
+ return {
1284
+ content: [
1285
+ {
1286
+ type: "text",
1287
+ text: JSON.stringify({ success: true, domain, verification: result }, null, 2)
1288
+ }
1289
+ ]
1290
+ };
1291
+ } catch (err) {
1292
+ return {
1293
+ isError: true,
1294
+ content: [{ type: "text", text: `Failed to verify email domain: ${err.message}` }]
1295
+ };
1296
+ }
1169
1297
  }
1170
- }
1171
- );
1298
+ );
1299
+ }
1172
1300
  }
1173
1301
 
1174
1302
  // src/tools/domains.ts
@@ -1658,7 +1786,7 @@ function registerCommerceTools(server, client) {
1658
1786
  );
1659
1787
  server.tool(
1660
1788
  "taghost_commerce_migrate_woocommerce",
1661
- "Migrate a WordPress/WooCommerce ecommerce site to TagHost. Migrates products into Edge Collections, customers, orders, and scrapes theme styling tokens.",
1789
+ "Migrate a WordPress/WooCommerce site to TagHost Edge. Migrates products, posts, pages, custom post types, customers, orders, R2 media, theme tokens, and 301 _redirects.",
1662
1790
  {
1663
1791
  projectId: import_zod5.z.string().optional().describe("Project ID. Defaults to active project."),
1664
1792
  url: import_zod5.z.string().optional().describe('WordPress/WooCommerce site URL (e.g. "https://my-store.com")'),
@@ -1666,19 +1794,24 @@ function registerCommerceTools(server, client) {
1666
1794
  consumerSecret: import_zod5.z.string().optional().describe("WooCommerce REST API Consumer Secret (cs_...)"),
1667
1795
  products: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce product objects to import (or parsed from CSV/JSON)"),
1668
1796
  posts: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WordPress blog post objects to import"),
1797
+ pages: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WordPress page objects to import"),
1669
1798
  customers: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce customer objects to import"),
1670
1799
  orders: import_zod5.z.array(import_zod5.z.any()).optional().describe("Direct array of WooCommerce order objects to import"),
1671
1800
  wxrXml: import_zod5.z.string().optional().describe("Raw WordPress WXR XML export content (from Tools > Export) for complete offline migration"),
1672
1801
  options: import_zod5.z.object({
1673
1802
  importProducts: import_zod5.z.boolean().optional().describe("Whether to import products (default: true)"),
1674
1803
  importPosts: import_zod5.z.boolean().optional().describe("Whether to import WordPress blog posts (default: true)"),
1804
+ importPages: import_zod5.z.boolean().optional().describe("Whether to import WordPress pages into a pages collection (default: true)"),
1675
1805
  importCustomers: import_zod5.z.boolean().optional().describe("Whether to import customers (default: true)"),
1676
1806
  importOrders: import_zod5.z.boolean().optional().describe("Whether to import orders (default: true)"),
1677
1807
  scrapeDesign: import_zod5.z.boolean().optional().describe("Whether to scrape brand design & font tokens from site HTML (default: true)"),
1678
- mirrorMedia: import_zod5.z.boolean().optional().describe("Whether to mirror remote images into Cloudflare R2 Edge Storage (default: true)")
1808
+ mirrorMedia: import_zod5.z.boolean().optional().describe("Whether to mirror remote images into Cloudflare R2 Edge Storage (default: true)"),
1809
+ cleanMarkup: import_zod5.z.boolean().optional().describe("Whether to strip Gutenberg comments and legacy page-builder shortcodes (default: true)"),
1810
+ writeRedirects: import_zod5.z.boolean().optional().describe("Whether to generate and merge 301 _redirects for legacy WordPress permalinks (default: true)"),
1811
+ 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)")
1679
1812
  }).optional().describe("Migration options")
1680
1813
  },
1681
- async ({ projectId, url, consumerKey, consumerSecret, products, posts, customers, orders, wxrXml, options }) => {
1814
+ async ({ projectId, url, consumerKey, consumerSecret, products, posts, pages, customers, orders, wxrXml, options }) => {
1682
1815
  try {
1683
1816
  const id = await client.resolveProjectId(projectId);
1684
1817
  const res = await client.migrateWooCommerce(id, {
@@ -1687,6 +1820,7 @@ function registerCommerceTools(server, client) {
1687
1820
  consumerSecret,
1688
1821
  products,
1689
1822
  posts,
1823
+ pages,
1690
1824
  customers,
1691
1825
  orders,
1692
1826
  wxrXml,
@@ -1699,11 +1833,17 @@ function registerCommerceTools(server, client) {
1699
1833
  text: JSON.stringify(
1700
1834
  {
1701
1835
  success: res.success,
1702
- message: `WooCommerce migration completed for project ${id}.`,
1836
+ message: `WordPress/WooCommerce migration completed for project ${id}.`,
1703
1837
  summary: {
1704
1838
  productsMigrated: res.productsMigrated,
1839
+ postsMigrated: res.postsMigrated,
1840
+ pagesMigrated: res.pagesMigrated,
1841
+ customItemsMigrated: res.customItemsMigrated,
1842
+ mediaMirrored: res.mediaMirrored,
1705
1843
  customersMigrated: res.customersMigrated,
1706
1844
  ordersMigrated: res.ordersMigrated,
1845
+ redirectsGenerated: res.redirectsGenerated,
1846
+ redirectsAppliedToDeployment: res.redirectsAppliedToDeployment,
1707
1847
  themeScraped: res.themeScraped
1708
1848
  },
1709
1849
  errors: res.errors
@@ -1717,7 +1857,62 @@ function registerCommerceTools(server, client) {
1717
1857
  } catch (err) {
1718
1858
  return {
1719
1859
  isError: true,
1720
- content: [{ type: "text", text: `Failed to execute WooCommerce migration: ${err.message}` }]
1860
+ content: [{ type: "text", text: `Failed to execute WordPress/WooCommerce migration: ${err.message}` }]
1861
+ };
1862
+ }
1863
+ }
1864
+ );
1865
+ server.tool(
1866
+ "taghost_wordpress_visual_clone",
1867
+ "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/*.",
1868
+ {
1869
+ projectId: import_zod5.z.string().optional().describe("Project ID. Defaults to active project."),
1870
+ url: import_zod5.z.string().describe('Public live WordPress site URL (e.g. "https://example.com")'),
1871
+ maxPages: import_zod5.z.number().int().min(1).max(30).optional().describe("Max pages to clone (default: 15, max: 30)"),
1872
+ maxAssets: import_zod5.z.number().int().min(10).max(250).optional().describe("Max CSS/font/image assets to mirror (default: 120, max: 250)"),
1873
+ rewireForms: import_zod5.z.boolean().optional().describe("Auto-rewire WordPress contact forms to TagHost Edge Forms (default: true)"),
1874
+ syncCollections: import_zod5.z.boolean().optional().describe("Also import WP posts & pages into TagHost Collections CMS (default: false)")
1875
+ },
1876
+ async ({ projectId, url, maxPages, maxAssets, rewireForms, syncCollections }) => {
1877
+ try {
1878
+ const id = await client.resolveProjectId(projectId);
1879
+ const res = await client.cloneWordPressSite(id, {
1880
+ url,
1881
+ maxPages,
1882
+ maxAssets,
1883
+ rewireForms,
1884
+ syncCollections
1885
+ });
1886
+ return {
1887
+ content: [
1888
+ {
1889
+ type: "text",
1890
+ text: JSON.stringify(
1891
+ {
1892
+ success: res.success,
1893
+ message: `WordPress visual clone deployed for project ${id}.`,
1894
+ deployment: res.deployment,
1895
+ summary: {
1896
+ pagesCloned: res.pagesCloned,
1897
+ editablePagesCount: res.editablePagesCount,
1898
+ totalDiscoveredPages: res.totalDiscoveredPages,
1899
+ assetsMirrored: res.assetsMirrored,
1900
+ formsRewired: res.formsRewired,
1901
+ rewiredFormNames: res.rewiredFormNames,
1902
+ detectedDynamicWidgets: res.detectedDynamicWidgets
1903
+ },
1904
+ errors: res.errors
1905
+ },
1906
+ null,
1907
+ 2
1908
+ )
1909
+ }
1910
+ ]
1911
+ };
1912
+ } catch (err) {
1913
+ return {
1914
+ isError: true,
1915
+ content: [{ type: "text", text: `Failed to visually clone WordPress site: ${err.message}` }]
1721
1916
  };
1722
1917
  }
1723
1918
  }
@@ -3344,18 +3539,41 @@ function createTagHostMcpServer(options = {}) {
3344
3539
  version: options.version || "1.0.0"
3345
3540
  });
3346
3541
  const client = new TagHostClient(options);
3347
- registerProjectTools(server, client);
3348
- registerDeploymentTools(server, client);
3349
- registerMailTools(server, client);
3350
- registerDomainTools(server, client);
3351
- registerCommerceTools(server, client);
3352
- registerCollectionTools(server, client);
3353
- registerContentTools(server, client);
3354
- registerFormsCrmTools(server, client);
3355
- registerSqlTools(server, client);
3356
- registerObservabilityTools(server, client);
3357
- registerTasksCollaborationTools(server, client);
3358
- registerResources(server, client);
3542
+ const scopes = options.scopes ?? null;
3543
+ if (hasMcpScope(scopes, "projects:read") || hasMcpScope(scopes, "deployments:write")) {
3544
+ registerProjectTools(server, client, scopes);
3545
+ }
3546
+ if (hasMcpScope(scopes, "deployments:write")) {
3547
+ registerDeploymentTools(server, client);
3548
+ }
3549
+ if (hasMcpScope(scopes, "mail:read") || hasMcpScope(scopes, "mail:send")) {
3550
+ registerMailTools(server, client, scopes);
3551
+ }
3552
+ if (hasMcpScope(scopes, "domains:write")) {
3553
+ registerDomainTools(server, client);
3554
+ }
3555
+ if (hasMcpScope(scopes, "commerce:write")) {
3556
+ registerCommerceTools(server, client);
3557
+ }
3558
+ if (hasMcpScope(scopes, "content:write")) {
3559
+ registerCollectionTools(server, client);
3560
+ registerContentTools(server, client);
3561
+ }
3562
+ if (hasMcpScope(scopes, "forms:read")) {
3563
+ registerFormsCrmTools(server, client);
3564
+ }
3565
+ if (hasMcpScope(scopes, "sql:read")) {
3566
+ registerSqlTools(server, client);
3567
+ }
3568
+ if (hasMcpScope(scopes, "projects:read")) {
3569
+ registerObservabilityTools(server, client);
3570
+ }
3571
+ if (hasMcpScope(scopes, "workspace:collaborate")) {
3572
+ registerTasksCollaborationTools(server, client);
3573
+ }
3574
+ if (hasMcpScope(scopes, "projects:read")) {
3575
+ registerResources(server, client);
3576
+ }
3359
3577
  registerPrompts(server);
3360
3578
  return { server, client };
3361
3579
  }