@teamnetwork-nz/mailstore-spe-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +360 -0
  2. package/dist/config/env.d.ts +14 -0
  3. package/dist/config/env.js +45 -0
  4. package/dist/config/env.js.map +1 -0
  5. package/dist/config/schema.d.ts +86 -0
  6. package/dist/config/schema.js +55 -0
  7. package/dist/config/schema.js.map +1 -0
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.js +60 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/logging/logger.d.ts +12 -0
  12. package/dist/logging/logger.js +80 -0
  13. package/dist/logging/logger.js.map +1 -0
  14. package/dist/mailstore/authentication.d.ts +7 -0
  15. package/dist/mailstore/authentication.js +15 -0
  16. package/dist/mailstore/authentication.js.map +1 -0
  17. package/dist/mailstore/capability-registry.d.ts +40 -0
  18. package/dist/mailstore/capability-registry.js +152 -0
  19. package/dist/mailstore/capability-registry.js.map +1 -0
  20. package/dist/mailstore/client.d.ts +33 -0
  21. package/dist/mailstore/client.js +274 -0
  22. package/dist/mailstore/client.js.map +1 -0
  23. package/dist/mailstore/encoder.d.ts +14 -0
  24. package/dist/mailstore/encoder.js +42 -0
  25. package/dist/mailstore/encoder.js.map +1 -0
  26. package/dist/mailstore/errors.d.ts +44 -0
  27. package/dist/mailstore/errors.js +49 -0
  28. package/dist/mailstore/errors.js.map +1 -0
  29. package/dist/mailstore/instance-resolver.d.ts +43 -0
  30. package/dist/mailstore/instance-resolver.js +143 -0
  31. package/dist/mailstore/instance-resolver.js.map +1 -0
  32. package/dist/mailstore/metadata.d.ts +21 -0
  33. package/dist/mailstore/metadata.js +50 -0
  34. package/dist/mailstore/metadata.js.map +1 -0
  35. package/dist/mailstore/operation-poller.d.ts +19 -0
  36. package/dist/mailstore/operation-poller.js +72 -0
  37. package/dist/mailstore/operation-poller.js.map +1 -0
  38. package/dist/mailstore/response-parser.d.ts +11 -0
  39. package/dist/mailstore/response-parser.js +66 -0
  40. package/dist/mailstore/response-parser.js.map +1 -0
  41. package/dist/mailstore/types.d.ts +79 -0
  42. package/dist/mailstore/types.js +6 -0
  43. package/dist/mailstore/types.js.map +1 -0
  44. package/dist/output/normalizers.d.ts +11 -0
  45. package/dist/output/normalizers.js +40 -0
  46. package/dist/output/normalizers.js.map +1 -0
  47. package/dist/output/tool-result.d.ts +30 -0
  48. package/dist/output/tool-result.js +24 -0
  49. package/dist/output/tool-result.js.map +1 -0
  50. package/dist/output/truncation.d.ts +17 -0
  51. package/dist/output/truncation.js +27 -0
  52. package/dist/output/truncation.js.map +1 -0
  53. package/dist/policy/access-mode.d.ts +16 -0
  54. package/dist/policy/access-mode.js +21 -0
  55. package/dist/policy/access-mode.js.map +1 -0
  56. package/dist/policy/confirmations.d.ts +24 -0
  57. package/dist/policy/confirmations.js +49 -0
  58. package/dist/policy/confirmations.js.map +1 -0
  59. package/dist/policy/redaction.d.ts +15 -0
  60. package/dist/policy/redaction.js +63 -0
  61. package/dist/policy/redaction.js.map +1 -0
  62. package/dist/policy/tool-policy.d.ts +15 -0
  63. package/dist/policy/tool-policy.js +2 -0
  64. package/dist/policy/tool-policy.js.map +1 -0
  65. package/dist/resources/health.d.ts +17 -0
  66. package/dist/resources/health.js +55 -0
  67. package/dist/resources/health.js.map +1 -0
  68. package/dist/resources/register-resources.d.ts +7 -0
  69. package/dist/resources/register-resources.js +37 -0
  70. package/dist/resources/register-resources.js.map +1 -0
  71. package/dist/server.d.ts +17 -0
  72. package/dist/server.js +62 -0
  73. package/dist/server.js.map +1 -0
  74. package/dist/tools/compliance.d.ts +6 -0
  75. package/dist/tools/compliance.js +96 -0
  76. package/dist/tools/compliance.js.map +1 -0
  77. package/dist/tools/instances.d.ts +4 -0
  78. package/dist/tools/instances.js +197 -0
  79. package/dist/tools/instances.js.map +1 -0
  80. package/dist/tools/jobs.d.ts +2 -0
  81. package/dist/tools/jobs.js +125 -0
  82. package/dist/tools/jobs.js.map +1 -0
  83. package/dist/tools/maintenance.d.ts +3 -0
  84. package/dist/tools/maintenance.js +22 -0
  85. package/dist/tools/maintenance.js.map +1 -0
  86. package/dist/tools/platform.d.ts +4 -0
  87. package/dist/tools/platform.js +134 -0
  88. package/dist/tools/platform.js.map +1 -0
  89. package/dist/tools/profiles.d.ts +2 -0
  90. package/dist/tools/profiles.js +140 -0
  91. package/dist/tools/profiles.js.map +1 -0
  92. package/dist/tools/raw-api.d.ts +16 -0
  93. package/dist/tools/raw-api.js +109 -0
  94. package/dist/tools/raw-api.js.map +1 -0
  95. package/dist/tools/register-tools.d.ts +14 -0
  96. package/dist/tools/register-tools.js +121 -0
  97. package/dist/tools/register-tools.js.map +1 -0
  98. package/dist/tools/smtp.d.ts +2 -0
  99. package/dist/tools/smtp.js +39 -0
  100. package/dist/tools/smtp.js.map +1 -0
  101. package/dist/tools/stores.d.ts +2 -0
  102. package/dist/tools/stores.js +116 -0
  103. package/dist/tools/stores.js.map +1 -0
  104. package/dist/tools/tool.d.ts +41 -0
  105. package/dist/tools/tool.js +33 -0
  106. package/dist/tools/tool.js.map +1 -0
  107. package/dist/tools/users.d.ts +2 -0
  108. package/dist/tools/users.js +266 -0
  109. package/dist/tools/users.js.map +1 -0
  110. package/package.json +52 -0
@@ -0,0 +1,134 @@
1
+ import { z } from 'zod';
2
+ import { defineTool } from './tool.js';
3
+ import { buildResult } from '../output/tool-result.js';
4
+ import { asArray, asRecord, pickStr, str } from '../output/normalizers.js';
5
+ import { normaliseInstance } from '../mailstore/instance-resolver.js';
6
+ const readPolicy = {
7
+ minimumMode: 'read-only',
8
+ risk: 'read',
9
+ requiresConfirmation: false,
10
+ permitsBulkTargets: false,
11
+ };
12
+ export const platformTools = [
13
+ defineTool({
14
+ name: 'mailstore_ping',
15
+ description: 'Verify connectivity and authentication to the MailStore SPE Management server. Read-only, fast. Returns server host and round-trip time.',
16
+ policy: readPolicy,
17
+ requiredFunctions: ['Ping'],
18
+ inputShape: {},
19
+ handler: async (ctx) => {
20
+ const started = Date.now();
21
+ await ctx.client.ping();
22
+ const responseTimeMs = Date.now() - started;
23
+ const server = new URL(ctx.config.baseUrl).host;
24
+ return buildResult({
25
+ summary: `MailStore reachable at ${server} (${responseTimeMs} ms)`,
26
+ data: { ok: true, server, responseTimeMs },
27
+ });
28
+ },
29
+ }),
30
+ defineTool({
31
+ name: 'mailstore_get_environment',
32
+ description: 'Retrieve MailStore SPE version and environment information (GetEnvironmentInfo). Read-only. Secrets and unnecessary hardware identifiers are redacted.',
33
+ policy: readPolicy,
34
+ requiredFunctions: ['GetEnvironmentInfo'],
35
+ inputShape: {},
36
+ handler: async (ctx) => {
37
+ const info = await ctx.client.invokeAndWait('GetEnvironmentInfo', {}, { retrySafe: true });
38
+ const rec = asRecord(info);
39
+ const version = pickStr(rec, ['version', 'productVersion', 'mailStoreVersion']);
40
+ return buildResult({
41
+ summary: version ? `MailStore SPE ${version}` : 'MailStore environment info',
42
+ data: info,
43
+ });
44
+ },
45
+ }),
46
+ defineTool({
47
+ name: 'mailstore_get_service_status',
48
+ description: 'Return the status of MailStore SPE services (GetServiceStatus). Read-only; requires no arguments.',
49
+ policy: readPolicy,
50
+ requiredFunctions: ['GetServiceStatus'],
51
+ inputShape: {},
52
+ handler: async (ctx) => {
53
+ const status = await ctx.client.invokeAndWait('GetServiceStatus', {}, { retrySafe: true });
54
+ return buildResult({ summary: 'MailStore SPE service status', data: status });
55
+ },
56
+ }),
57
+ defineTool({
58
+ name: 'mailstore_get_platform_summary',
59
+ description: 'Combined operational summary of the SPE platform: version, service health, instance counts by state, instance-host and client-access-server health. Composed from several read-only calls. Read-only.',
60
+ policy: readPolicy,
61
+ requiredFunctions: ['GetEnvironmentInfo', 'GetServiceStatus', 'GetInstances'],
62
+ inputShape: {
63
+ includeInstances: z
64
+ .boolean()
65
+ .optional()
66
+ .describe('Include a normalised list of instances (default false; counts are always included).'),
67
+ includeStopped: z
68
+ .boolean()
69
+ .optional()
70
+ .describe('When listing instances, include stopped ones (default true).'),
71
+ },
72
+ handler: async (ctx, input) => {
73
+ const warnings = [];
74
+ const env = asRecord(await ctx.client.invokeAndWait('GetEnvironmentInfo', {}, { retrySafe: true }));
75
+ const serviceStatus = await ctx.client.invokeAndWait('GetServiceStatus', {}, { retrySafe: true });
76
+ const instances = await ctx.resolver.list('*', true);
77
+ // Optional platform topology calls — only if available.
78
+ let instanceHosts = undefined;
79
+ if (ctx.registry.has('GetInstanceHosts')) {
80
+ instanceHosts = await ctx.client.invokeAndWait('GetInstanceHosts', {}, { retrySafe: true });
81
+ }
82
+ else {
83
+ warnings.push('GetInstanceHosts unavailable — instance host health omitted');
84
+ }
85
+ let clientAccessServers = undefined;
86
+ if (ctx.registry.has('GetClientAccessServers')) {
87
+ // withServiceStatus is a required (non-nullable) argument.
88
+ clientAccessServers = await ctx.client.invokeAndWait('GetClientAccessServers', { withServiceStatus: true }, { retrySafe: true });
89
+ }
90
+ else {
91
+ warnings.push('GetClientAccessServers unavailable — client access server health omitted');
92
+ }
93
+ const countsByState = {};
94
+ for (const inst of instances) {
95
+ const state = inst.state ?? 'unknown';
96
+ countsByState[state] = (countsByState[state] ?? 0) + 1;
97
+ }
98
+ const includeStopped = input.includeStopped ?? true;
99
+ const listed = input.includeInstances
100
+ ? instances
101
+ .filter((i) => includeStopped || (i.state ?? '').toLowerCase() !== 'stopped')
102
+ .map(({ raw: _raw, ...rest }) => rest)
103
+ : undefined;
104
+ const version = pickStr(env, ['version', 'productVersion', 'mailStoreVersion']);
105
+ return buildResult({
106
+ summary: `${version ? `MailStore SPE ${version}. ` : ''}${instances.length} instance(s): ${Object.entries(countsByState)
107
+ .map(([s, n]) => `${n} ${s}`)
108
+ .join(', ') || 'none'}`,
109
+ data: {
110
+ version,
111
+ serverName: pickStr(env, ['machineName', 'serverName', 'computerName']),
112
+ serviceStatus,
113
+ instanceCount: instances.length,
114
+ instanceCountsByState: countsByState,
115
+ instanceHosts,
116
+ clientAccessServers,
117
+ ...(listed ? { instances: listed } : {}),
118
+ },
119
+ ...(warnings.length > 0 ? { warnings } : {}),
120
+ });
121
+ },
122
+ }),
123
+ ];
124
+ // (helpers retained for future normalisation of host records)
125
+ export function summariseInstances(result) {
126
+ return asArray(result)
127
+ .map((r) => normaliseInstance(asRecord(r)))
128
+ .filter((x) => x !== undefined)
129
+ .map(({ raw: _raw, ...rest }) => rest);
130
+ }
131
+ export function stateOf(rec) {
132
+ return str(rec['state']) ?? 'unknown';
133
+ }
134
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/tools/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAmB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,MAAM,UAAU,GAAG;IACjB,WAAW,EAAE,WAAW;IACxB,IAAI,EAAE,MAAM;IACZ,oBAAoB,EAAE,KAAK;IAC3B,kBAAkB,EAAE,KAAK;CACjB,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAiB;IACzC,UAAU,CAAC;QACT,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,0IAA0I;QAC5I,MAAM,EAAE,UAAU;QAClB,iBAAiB,EAAE,CAAC,MAAM,CAAC;QAC3B,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACxB,MAAM,cAAc,GAAG,IAAI,CAAC,GAA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K,SAAS,CAAC;SAC1D,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAA4B;IAClD,OAAO,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC;AACxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type ToolModule } from './tool.js';
2
+ export declare const profileTools: ToolModule[];
@@ -0,0 +1,140 @@
1
+ import { z } from 'zod';
2
+ import { defineTool, instanceField, confirmationField, searchField, limitField, resolveInstance } from './tool.js';
3
+ import { buildResult } from '../output/tool-result.js';
4
+ import { limitItems, searchFilter } from '../output/truncation.js';
5
+ import { asArray, asRecord, num, str } from '../output/normalizers.js';
6
+ import { assertConfirmation, confirmations } from '../policy/confirmations.js';
7
+ import { Errors } from '../mailstore/errors.js';
8
+ /** Find a profile record by id within GetProfiles output. GetProfiles requires a `raw` flag. */
9
+ async function findProfile(ctx, instanceID, profileId) {
10
+ const raw = await ctx.client.invokeAndWait('GetProfiles', { instanceID, raw: true }, { retrySafe: true });
11
+ const match = asArray(raw)
12
+ .map((p) => asRecord(p))
13
+ .find((p) => num(p['id']) === profileId || num(p['profileId']) === profileId);
14
+ if (!match) {
15
+ throw Errors.objectNotFound(`Profile ${profileId} not found in ${instanceID}`, { instanceID, profileId });
16
+ }
17
+ return match;
18
+ }
19
+ export const profileTools = [
20
+ defineTool({
21
+ name: 'mailstore_list_profiles',
22
+ description: 'List archiving/export profiles in an instance (GetProfiles). Read-only. Set raw=true for the unnormalised records.',
23
+ policy: { minimumMode: 'read-only', risk: 'read', requiresConfirmation: false, permitsBulkTargets: false },
24
+ requiredFunctions: ['GetProfiles'],
25
+ inputShape: {
26
+ instance: instanceField,
27
+ raw: z.boolean().optional().describe('Return raw profile records instead of a normalised summary (default false).'),
28
+ search: searchField,
29
+ limit: limitField,
30
+ },
31
+ handler: async (ctx, input) => {
32
+ const inst = await resolveInstance(ctx, input.instance);
33
+ // GetProfiles requires a `raw` bool argument. We always request the full
34
+ // (raw) records so ids are available, then normalise unless raw was asked for.
35
+ const raw = await ctx.client.invokeAndWait('GetProfiles', { instanceID: inst.instanceID, raw: true }, { retrySafe: true });
36
+ const profiles = asArray(raw).map((p) => asRecord(p));
37
+ const shaped = input.raw
38
+ ? profiles
39
+ : profiles.map((p) => ({
40
+ id: num(p['id']) ?? num(p['profileId']),
41
+ name: str(p['name']),
42
+ type: str(p['type']) ?? str(p['profileType']),
43
+ serverSideExecution: p['serverSideExecution'] ?? p['runOnServer'],
44
+ }));
45
+ const filtered = searchFilter(shaped, input.search, ['name', 'type']);
46
+ const { items, truncated, totalCount, returnedCount } = limitItems(filtered, {
47
+ ...(input.limit !== undefined ? { limit: input.limit } : {}),
48
+ maxItems: ctx.config.maxResultItems,
49
+ });
50
+ return buildResult({
51
+ summary: `${returnedCount} of ${totalCount} profile(s) in ${inst.instanceID}`,
52
+ data: items,
53
+ truncated,
54
+ totalCount,
55
+ returnedCount,
56
+ });
57
+ },
58
+ }),
59
+ defineTool({
60
+ name: 'mailstore_run_profile',
61
+ description: 'Run a server-side archiving/export profile now (RunProfile). Operational action; may be long-running (waited to completion). Verifies the profile exists first. Requires the exact confirmation string "RUN PROFILE <profileId> IN <instanceID>".',
62
+ policy: { minimumMode: 'operator', risk: 'operational', requiresConfirmation: true, permitsBulkTargets: false },
63
+ requiredFunctions: ['RunProfile', 'GetProfiles'],
64
+ inputShape: {
65
+ instance: instanceField,
66
+ profileId: z.number().int().describe('The profile id to run.'),
67
+ confirmation: confirmationField,
68
+ },
69
+ handler: async (ctx, input) => {
70
+ const inst = await resolveInstance(ctx, input.instance);
71
+ const profile = await findProfile(ctx, inst.instanceID, input.profileId);
72
+ assertConfirmation(confirmations.runProfile(input.profileId, inst.instanceID), input.confirmation);
73
+ const result = await ctx.client.invokeAndWait('RunProfile', {
74
+ instanceID: inst.instanceID,
75
+ id: input.profileId,
76
+ });
77
+ return buildResult({
78
+ summary: `Ran profile ${input.profileId} (${str(profile['name']) ?? 'unnamed'}) in ${inst.instanceID}`,
79
+ data: {
80
+ instanceID: inst.instanceID,
81
+ profileId: input.profileId,
82
+ profileName: str(profile['name']),
83
+ profileType: str(profile['type']) ?? str(profile['profileType']),
84
+ result,
85
+ },
86
+ });
87
+ },
88
+ }),
89
+ defineTool({
90
+ name: 'mailstore_get_profile_results',
91
+ description: 'Get profile execution results over a time range (GetWorkerResults, optionally GetWorkerResultReport). Read-only. Dates are ISO 8601; timeZoneId defaults to $Local. Note MailStore spells this parameter "timeZoneID" for GetWorkerResults.',
92
+ policy: { minimumMode: 'read-only', risk: 'read', requiresConfirmation: false, permitsBulkTargets: false },
93
+ requiredFunctions: ['GetWorkerResults'],
94
+ inputShape: {
95
+ instance: instanceField,
96
+ from: z.string().describe('Start of the range (ISO 8601).'),
97
+ to: z.string().describe('End of the range (ISO 8601).'),
98
+ timeZoneId: z.string().optional().describe('MailStore time zone id (default $Local).'),
99
+ profileId: z.number().int().optional().describe('Restrict to a single profile id.'),
100
+ includeReports: z.boolean().optional().describe('Include per-result detailed reports (default false).'),
101
+ limit: limitField,
102
+ },
103
+ handler: async (ctx, input) => {
104
+ const inst = await resolveInstance(ctx, input.instance);
105
+ const tz = input.timeZoneId ?? '$Local';
106
+ // GetWorkerResults uses the capitalisation "timeZoneID".
107
+ const raw = await ctx.client.invokeAndWait('GetWorkerResults', {
108
+ instanceID: inst.instanceID,
109
+ fromIncluding: input.from,
110
+ toExcluding: input.to,
111
+ timeZoneID: tz,
112
+ ...(input.profileId !== undefined ? { profileID: input.profileId } : {}),
113
+ }, { retrySafe: true });
114
+ const results = asArray(raw).map((r) => asRecord(r));
115
+ const { items, truncated, totalCount, returnedCount } = limitItems(results, {
116
+ ...(input.limit !== undefined ? { limit: input.limit } : {}),
117
+ maxItems: ctx.config.maxResultItems,
118
+ });
119
+ let reports;
120
+ if (input.includeReports && ctx.registry.has('GetWorkerResultReport')) {
121
+ reports = [];
122
+ for (const r of items) {
123
+ const id = num(r['id']) ?? num(r['resultId']);
124
+ if (id === undefined)
125
+ continue;
126
+ const report = await ctx.client.invokeAndWait('GetWorkerResultReport', { instanceID: inst.instanceID, id }, { retrySafe: true });
127
+ reports.push({ id, report });
128
+ }
129
+ }
130
+ return buildResult({
131
+ summary: `${returnedCount} of ${totalCount} profile result(s) in ${inst.instanceID}`,
132
+ data: { instanceID: inst.instanceID, timeZoneId: tz, results: items, ...(reports ? { reports } : {}) },
133
+ truncated,
134
+ totalCount,
135
+ returnedCount,
136
+ });
137
+ },
138
+ }),
139
+ ];
140
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/tools/profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAqC,MAAM,WAAW,CAAC;AACtJ,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,gGAAgG;AAChG,KAAK,UAAU,WAAW,CAAC,GAAgB,EAAE,UAAkB,EAAE,SAAiB;IAChF,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,aAAa,CAAU,aAAa,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,IA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G,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;oBAC9C,IAAI,EAAE,KAAK,SAAS;wBAAE,SAAS;oBAC/B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,aAAa,CAC3C,uBAAuB,EACvB,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,EACnC,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;oBACF,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;YAED,OAAO,WAAW,CAAC;gBACjB,OAAO,EAAE,GAAG,aAAa,OAAO,UAAU,yBAAyB,IAAI,CAAC,UAAU,EAAE;gBACpF,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBACtG,SAAS;gBACT,UAAU;gBACV,aAAa;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC;CACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type ToolModule } from './tool.js';
2
+ /** Functions that must never be callable via the generic tool (§14). */
3
+ export declare const RAW_API_DENYLIST: Set<string>;
4
+ type RawRisk = 'read' | 'operational';
5
+ /**
6
+ * Explicit allow-map: only functions listed here may be invoked via the raw API,
7
+ * each with a known risk category. Unknown functions default to DENIED, never
8
+ * read-only (§14). Mutating/destructive administration has dedicated, stronger
9
+ * tools and is intentionally absent here.
10
+ */
11
+ export declare const RAW_API_ALLOW: Map<string, {
12
+ risk: RawRisk;
13
+ requiresConfirmation: boolean;
14
+ }>;
15
+ export declare const rawApiTools: ToolModule[];
16
+ export {};
@@ -0,0 +1,109 @@
1
+ import { z } from 'zod';
2
+ import { defineTool } from './tool.js';
3
+ import { buildResult } from '../output/tool-result.js';
4
+ import { assertConfirmation } from '../policy/confirmations.js';
5
+ import { isSensitiveKey } from '../policy/redaction.js';
6
+ import { Errors } from '../mailstore/errors.js';
7
+ /** Functions that must never be callable via the generic tool (§14). */
8
+ export const RAW_API_DENYLIST = new Set([
9
+ 'DeleteInstances',
10
+ 'DeleteInstanceHost',
11
+ 'DeleteClientAccessServer',
12
+ 'DeleteSystemAdministrator',
13
+ 'SetSystemAdministratorPassword',
14
+ 'CreateSystemAdministratorAPIPassword',
15
+ 'UnlockStore',
16
+ 'RecoverStore',
17
+ 'RepairStoreDatabase',
18
+ 'SetStorePath',
19
+ 'TransferStores',
20
+ 'MergeStore',
21
+ 'SetComplianceConfiguration',
22
+ 'SetRetentionPolicies',
23
+ ]);
24
+ /**
25
+ * Explicit allow-map: only functions listed here may be invoked via the raw API,
26
+ * each with a known risk category. Unknown functions default to DENIED, never
27
+ * read-only (§14). Mutating/destructive administration has dedicated, stronger
28
+ * tools and is intentionally absent here.
29
+ */
30
+ export const RAW_API_ALLOW = new Map([
31
+ ['Ping', { risk: 'read', requiresConfirmation: false }],
32
+ ['GetEnvironmentInfo', { risk: 'read', requiresConfirmation: false }],
33
+ ['GetServiceStatus', { risk: 'read', requiresConfirmation: false }],
34
+ ['GetInstances', { risk: 'read', requiresConfirmation: false }],
35
+ ['GetInstanceHosts', { risk: 'read', requiresConfirmation: false }],
36
+ ['GetClientAccessServers', { risk: 'read', requiresConfirmation: false }],
37
+ ['GetInstanceConfiguration', { risk: 'read', requiresConfirmation: false }],
38
+ ['GetInstanceStatistics', { risk: 'read', requiresConfirmation: false }],
39
+ ['GetInstanceProcessLiveStatistics', { risk: 'read', requiresConfirmation: false }],
40
+ ['GetFolderStatistics', { risk: 'read', requiresConfirmation: false }],
41
+ ['GetUsers', { risk: 'read', requiresConfirmation: false }],
42
+ ['GetUserInfo', { risk: 'read', requiresConfirmation: false }],
43
+ ['GetProfiles', { risk: 'read', requiresConfirmation: false }],
44
+ ['GetJobs', { risk: 'read', requiresConfirmation: false }],
45
+ ['GetStores', { risk: 'read', requiresConfirmation: false }],
46
+ ['GetSmtpSettings', { risk: 'read', requiresConfirmation: false }],
47
+ ['GetComplianceConfiguration', { risk: 'read', requiresConfirmation: false }],
48
+ ['GetRetentionPolicies', { risk: 'read', requiresConfirmation: false }],
49
+ ['GetWorkerResults', { risk: 'read', requiresConfirmation: false }],
50
+ ['GetJobResults', { risk: 'read', requiresConfirmation: false }],
51
+ ]);
52
+ const MAX_RAW_RESPONSE_CHARS = 100_000;
53
+ export const rawApiTools = [
54
+ defineTool({
55
+ name: 'mailstore_invoke_api',
56
+ description: 'Generic escape hatch to invoke an allow-listed MailStore API function by name. Disabled unless MCP_ENABLE_RAW_API=true; administrator-only. Only explicitly permitted functions are callable; unknown or denylisted functions are refused. No secrets may be passed, and no wildcard instance filters for mutating calls. Prefer the dedicated tools.',
57
+ policy: { minimumMode: 'administrator', risk: 'operational', requiresConfirmation: false, permitsBulkTargets: false },
58
+ requiredFunctions: [],
59
+ inputShape: {
60
+ functionName: z.string().min(1).describe('The MailStore API function name to invoke.'),
61
+ arguments: z.record(z.string(), z.unknown()).optional().describe('Arguments for the function (validated against metadata).'),
62
+ confirmation: z.string().optional().describe('Exact confirmation "INVOKE <functionName>", required for non-read functions.'),
63
+ },
64
+ handler: async (ctx, input) => {
65
+ const fn = input.functionName;
66
+ if (RAW_API_DENYLIST.has(fn)) {
67
+ throw Errors.accessDenied(`Function "${fn}" is denylisted and cannot be invoked via the raw API`, { functionName: fn });
68
+ }
69
+ const policy = RAW_API_ALLOW.get(fn);
70
+ if (!policy) {
71
+ throw Errors.accessDenied(`Function "${fn}" is not permitted via the raw API. Use a dedicated tool, or extend the raw API allow-list.`, { functionName: fn });
72
+ }
73
+ if (!ctx.registry.has(fn)) {
74
+ throw Errors.unsupported(`Function "${fn}" is not available on this MailStore server`, { functionName: fn });
75
+ }
76
+ const args = (input.arguments ?? {});
77
+ // Never allow secrets through the generic tool.
78
+ for (const key of Object.keys(args)) {
79
+ if (isSensitiveKey(key)) {
80
+ throw Errors.invalidArgument(`Argument "${key}" is not permitted via the raw API (potential secret)`, { functionName: fn, argument: key });
81
+ }
82
+ }
83
+ // Validate against metadata (existence, known args, nullability).
84
+ ctx.registry.validateCall(fn, args);
85
+ if (policy.risk !== 'read') {
86
+ // No wildcard instance filters for mutating calls.
87
+ for (const [k, v] of Object.entries(args)) {
88
+ if (typeof v === 'string' && v.includes('*') && /instance|filter/i.test(k)) {
89
+ throw Errors.invalidArgument(`Wildcard filters are not permitted for non-read raw API calls (argument "${k}")`, { functionName: fn });
90
+ }
91
+ }
92
+ if (policy.requiresConfirmation) {
93
+ assertConfirmation(`INVOKE ${fn}`, input.confirmation);
94
+ }
95
+ }
96
+ const result = await ctx.client.invokeAndWait(fn, args, { retrySafe: policy.risk === 'read' });
97
+ // Bound the response size.
98
+ const serialized = JSON.stringify(result ?? null);
99
+ if (serialized.length > MAX_RAW_RESPONSE_CHARS) {
100
+ throw Errors.resultTooLarge(`Response from "${fn}" exceeds the size limit (${serialized.length} chars)`, {
101
+ functionName: fn,
102
+ limit: MAX_RAW_RESPONSE_CHARS,
103
+ });
104
+ }
105
+ return buildResult({ summary: `Invoked ${fn}`, data: { functionName: fn, result } });
106
+ },
107
+ }),
108
+ ];
109
+ //# sourceMappingURL=raw-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-api.js","sourceRoot":"","sources":["../../src/tools/raw-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAmB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAA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sB,EAAE,CAAC;gBAC/C,MAAM,MAAM,CAAC,cAAc,CAAC,kBAAkB,EAAE,6BAA6B,UAAU,CAAC,MAAM,SAAS,EAAE;oBACvG,YAAY,EAAE,EAAE;oBAChB,KAAK,EAAE,sBAAsB;iBAC9B,CAAC,CAAC;YACL,CAAC;YAED,OAAO,WAAW,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACvF,CAAC;KACF,CAAC;CACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { ToolContext } from './tool.js';
3
+ export interface RegistrationSummary {
4
+ registered: string[];
5
+ skippedByMode: string[];
6
+ skippedByCapability: string[];
7
+ }
8
+ /**
9
+ * Register every eligible tool with the MCP server. A tool is registered only
10
+ * when the current access mode (and destructive flag) permit it AND all of its
11
+ * required MailStore functions are available in the live metadata. This means
12
+ * read-only mode exposes no mutating tools at all (§15.5).
13
+ */
14
+ export declare function registerTools(server: McpServer, ctx: ToolContext): RegistrationSummary;
@@ -0,0 +1,121 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ import { shouldRegisterTool } from '../policy/access-mode.js';
4
+ import { redact } from '../policy/redaction.js';
5
+ import { toMcpContent } from '../output/tool-result.js';
6
+ import { McpError } from '../mailstore/errors.js';
7
+ import { platformTools } from './platform.js';
8
+ import { instanceTools } from './instances.js';
9
+ import { userTools } from './users.js';
10
+ import { profileTools } from './profiles.js';
11
+ import { jobTools } from './jobs.js';
12
+ import { storeTools } from './stores.js';
13
+ import { smtpTools } from './smtp.js';
14
+ import { complianceTools } from './compliance.js';
15
+ import { maintenanceTools } from './maintenance.js';
16
+ import { rawApiTools } from './raw-api.js';
17
+ /** All tool modules in the phase-one catalogue plus the (gated) raw API. */
18
+ function allToolModules(ctx) {
19
+ const modules = [
20
+ ...platformTools,
21
+ ...instanceTools,
22
+ ...userTools,
23
+ ...profileTools,
24
+ ...jobTools,
25
+ ...storeTools,
26
+ ...smtpTools,
27
+ ...complianceTools,
28
+ ...maintenanceTools,
29
+ ];
30
+ // The raw API tool is only ever included when explicitly enabled.
31
+ if (ctx.config.enableRawApi)
32
+ modules.push(...rawApiTools);
33
+ return modules;
34
+ }
35
+ /**
36
+ * Register every eligible tool with the MCP server. A tool is registered only
37
+ * when the current access mode (and destructive flag) permit it AND all of its
38
+ * required MailStore functions are available in the live metadata. This means
39
+ * read-only mode exposes no mutating tools at all (§15.5).
40
+ */
41
+ export function registerTools(server, ctx) {
42
+ const summary = { registered: [], skippedByMode: [], skippedByCapability: [] };
43
+ for (const tool of allToolModules(ctx)) {
44
+ if (!shouldRegisterTool(tool.policy, { accessMode: ctx.config.accessMode, allowDestructive: ctx.config.allowDestructive })) {
45
+ summary.skippedByMode.push(tool.name);
46
+ continue;
47
+ }
48
+ if (tool.requiredFunctions.length > 0 && !ctx.registry.hasAll(tool.requiredFunctions)) {
49
+ summary.skippedByCapability.push(tool.name);
50
+ ctx.logger.warn({ tool: tool.name, requiredFunctions: tool.requiredFunctions }, 'tool disabled: required MailStore function(s) unavailable');
51
+ continue;
52
+ }
53
+ registerOne(server, ctx, tool);
54
+ summary.registered.push(tool.name);
55
+ }
56
+ ctx.logger.info({
57
+ registered: summary.registered.length,
58
+ skippedByMode: summary.skippedByMode.length,
59
+ skippedByCapability: summary.skippedByCapability.length,
60
+ accessMode: ctx.config.accessMode,
61
+ }, 'tool registration complete');
62
+ return summary;
63
+ }
64
+ function registerOne(server, ctx, tool) {
65
+ server.tool(tool.name, tool.description, tool.inputShape, async (rawInput) => {
66
+ const requestId = randomUUID();
67
+ const started = Date.now();
68
+ const log = ctx.logger.child({ component: 'tool', tool: tool.name, requestId });
69
+ let instanceID;
70
+ try {
71
+ // Validate input against the tool's own schema (defensive; SDK also validates).
72
+ const parsed = z.object(tool.inputShape).parse(rawInput ?? {});
73
+ const result = await tool.handler(ctx, parsed);
74
+ instanceID = extractInstanceId(result.data);
75
+ log.info({
76
+ mailstoreFunction: undefined,
77
+ instanceID,
78
+ outcome: 'success',
79
+ durationMs: Date.now() - started,
80
+ }, 'tool call succeeded');
81
+ return toMcpContent(result);
82
+ }
83
+ catch (err) {
84
+ const mcpErr = err instanceof McpError ? err : undefined;
85
+ log.error({
86
+ instanceID,
87
+ outcome: mcpErr && isDenied(mcpErr) ? 'denied' : 'failure',
88
+ errorCode: mcpErr?.code ?? 'UNEXPECTED',
89
+ durationMs: Date.now() - started,
90
+ // The full error (message only) is logged; never a stack to the client.
91
+ detail: redact(mcpErr?.details ?? {}),
92
+ }, mcpErr ? mcpErr.message : 'tool call failed with an unexpected error');
93
+ return errorContent(err);
94
+ }
95
+ });
96
+ }
97
+ function extractInstanceId(data) {
98
+ if (data && typeof data === 'object' && !Array.isArray(data)) {
99
+ const v = data['instanceID'];
100
+ if (typeof v === 'string')
101
+ return v;
102
+ }
103
+ return undefined;
104
+ }
105
+ function isDenied(err) {
106
+ return (err.code === 'ACCESS_MODE_DENIED' ||
107
+ err.code === 'DESTRUCTIVE_ACTION_DISABLED' ||
108
+ err.code === 'CONFIRMATION_REQUIRED' ||
109
+ err.code === 'CONFIRMATION_MISMATCH');
110
+ }
111
+ /** Build an MCP error response with a stable, secret-free payload. */
112
+ function errorContent(err) {
113
+ const payload = err instanceof McpError
114
+ ? err.toResponse()
115
+ : { code: 'MAILSTORE_API_ERROR', message: 'An unexpected error occurred while handling the request' };
116
+ return {
117
+ content: [{ type: 'text', text: JSON.stringify(redact(payload), null, 2) }],
118
+ isError: true,
119
+ };
120
+ }
121
+ //# sourceMappingURL=register-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-tools.js","sourceRoot":"","sources":["../../src/tools/register-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,CAAC,EAAE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IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QAC3E,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type ToolModule } from './tool.js';
2
+ export declare const smtpTools: ToolModule[];
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ import { defineTool, instanceField, confirmationField, resolveInstance } from './tool.js';
3
+ import { buildResult } from '../output/tool-result.js';
4
+ import { assertConfirmation, confirmations } from '../policy/confirmations.js';
5
+ export const smtpTools = [
6
+ defineTool({
7
+ name: 'mailstore_get_smtp_settings',
8
+ description: 'Get the SMTP settings for an instance (GetSmtpSettings). Read-only. Passwords, credential secrets and tokens are redacted. allSettings=false by default.',
9
+ policy: { minimumMode: 'read-only', risk: 'read', requiresConfirmation: false, permitsBulkTargets: false },
10
+ requiredFunctions: ['GetSmtpSettings'],
11
+ inputShape: {
12
+ instance: instanceField,
13
+ allSettings: z.boolean().optional().describe('Return the full settings object (default false).'),
14
+ },
15
+ handler: async (ctx, input) => {
16
+ const inst = await resolveInstance(ctx, input.instance);
17
+ const settings = await ctx.client.invokeAndWait('GetSmtpSettings', { instanceID: inst.instanceID, allSettings: input.allSettings ?? false }, { retrySafe: true });
18
+ // Secrets are stripped centrally by the output redactor before serialisation.
19
+ return buildResult({ summary: `SMTP settings for ${inst.instanceID}`, data: settings });
20
+ },
21
+ }),
22
+ defineTool({
23
+ name: 'mailstore_test_smtp',
24
+ description: 'Send a test message using the instance SMTP settings (TestSmtpSettings). Operational action. Requires the exact confirmation string "TEST SMTP IN <instanceID>".',
25
+ policy: { minimumMode: 'operator', risk: 'operational', requiresConfirmation: true, permitsBulkTargets: false },
26
+ requiredFunctions: ['TestSmtpSettings'],
27
+ inputShape: {
28
+ instance: instanceField,
29
+ confirmation: confirmationField,
30
+ },
31
+ handler: async (ctx, input) => {
32
+ const inst = await resolveInstance(ctx, input.instance);
33
+ assertConfirmation(confirmations.testSmtp(inst.instanceID), input.confirmation);
34
+ const result = await ctx.client.invokeAndWait('TestSmtpSettings', { instanceID: inst.instanceID });
35
+ return buildResult({ summary: `SMTP test executed for ${inst.instanceID}`, data: { instanceID: inst.instanceID, result } });
36
+ },
37
+ }),
38
+ ];
39
+ //# sourceMappingURL=smtp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smtp.js","sourceRoot":"","sources":["../../src/tools/smtp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,WAAW,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAiB;IACrC,UAAU,CAAC;QACT,IAAI,EAAE,6BAA6B;QACnC,WAAW,EACT,0JAA0J;QAC5J,MAAM,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,oBAAoB,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE;QAC1G,iBAAiB,EAAE,CAAC,iBAAiB,CAAC;QACtC,UAAU,EAAE;YACV,QAAQ,EAAE,aAAa;YACvB,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kDAAkD,CAAC;SACjG;QACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YAC5B,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;YACxD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,aAAa,CAC7C,iBAAiB,EACjB,EAAE,UAAU,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