-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
2197 lines (1973 loc) · 86.3 KB
/
server.js
File metadata and controls
2197 lines (1973 loc) · 86.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { google } from 'googleapis';
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import dotenv from 'dotenv';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Load .env from the same directory as server.js (not cwd)
dotenv.config({ path: join(__dirname, '.env') });
const credentials = JSON.parse(fs.readFileSync(join(__dirname, 'credentials.json'), 'utf8'));
const ADMIN_EMAIL = process.env.GOOGLE_WORKSPACE_ADMIN_EMAIL;
// Compliance framework mappings for each check
const COMPLIANCE_MAPPINGS = {
check_2fa_status: {
CMMC: 'IA.L2-3.5.3',
NIST_800_171: '3.5.3',
NIST_CSF: 'PR.AA-01',
ISO_27001: 'A.5.17',
HIPAA: '164.312(d)',
FTC: '314.4(c)(5)'
},
check_admin_roles: {
CMMC: 'AC.L2-3.1.1',
NIST_800_171: '3.1.1',
NIST_CSF: 'PR.AA-05',
ISO_27001: 'A.9.2.3',
HIPAA: '164.308(a)(4)',
FTC: '314.4(c)(1)'
},
check_session_settings: {
CMMC: 'AC.L2-3.1.11',
NIST_800_171: '3.1.11',
NIST_CSF: 'PR.AC-01',
ISO_27001: 'A.8.2',
HIPAA: '164.312(a)(2)(iii)',
FTC: '314.4(c)(1)'
},
check_external_sharing: {
CMMC: 'AC.L2-3.1.20',
NIST_800_171: '3.1.20',
NIST_CSF: 'PR.DS-05',
ISO_27001: 'A.8.12',
HIPAA: '164.312(e)(1)',
FTC: '314.4(c)(3)'
},
check_api_access: {
CMMC: 'AC.L2-3.1.2',
NIST_800_171: '3.1.2',
NIST_CSF: 'PR.AA-05',
ISO_27001: 'A.9.4.1',
HIPAA: '164.312(a)(1)',
FTC: '314.4(c)(1)'
},
check_groups_external_members: {
CMMC: 'AC.L2-3.1.20',
NIST_800_171: '3.1.20',
NIST_CSF: 'PR.AC-04',
ISO_27001: 'A.9.2.5',
HIPAA: '164.312(a)(1)',
FTC: '314.4(c)(3)'
},
check_password_policy: {
CMMC: 'IA.L2-3.5.7',
NIST_800_171: '3.5.7',
NIST_CSF: 'PR.AA-01',
ISO_27001: 'A.5.17',
HIPAA: '164.308(a)(5)(ii)(D)',
FTC: '314.4(c)(5)'
},
check_inactive_accounts: {
CMMC: 'AC.L2-3.1.1',
NIST_800_171: '3.1.1',
NIST_CSF: 'PR.AA-05',
ISO_27001: 'A.9.2.6',
HIPAA: '164.308(a)(4)(ii)(C)',
FTC: '314.4(c)(1)'
},
check_audit_log_settings: {
CMMC: 'AU.L2-3.3.1',
NIST_800_171: '3.3.1',
NIST_CSF: 'DE.AE-01',
ISO_27001: 'A.8.15',
HIPAA: '164.312(b)',
FTC: '314.4(c)(2)'
},
check_suspicious_activity: {
CMMC: 'AU.L2-3.3.4',
NIST_800_171: '3.3.4',
NIST_CSF: 'DE.AE-03',
ISO_27001: 'A.8.16',
HIPAA: '164.308(a)(1)(ii)(D)',
FTC: '314.4(c)(2)'
},
check_mobile_devices: {
CMMC: 'SC.L2-3.13.11',
NIST_800_171: '3.13.11',
NIST_CSF: 'PR.DS-01',
ISO_27001: 'A.8.24',
HIPAA: '164.312(a)(2)(iv)',
FTC: '314.4(c)(4)'
},
check_email_authentication: {
CMMC: 'SC.L2-3.13.8',
NIST_800_171: '3.13.8',
NIST_CSF: 'PR.DS-02',
ISO_27001: 'A.8.21',
HIPAA: '164.312(e)(2)(ii)',
FTC: '314.4(c)(4)'
},
check_email_forwarding: {
CMMC: 'AC.L2-3.1.20',
NIST_800_171: '3.1.20',
NIST_CSF: 'PR.DS-05',
ISO_27001: 'A.8.12',
HIPAA: '164.312(e)(1)',
FTC: '314.4(c)(3)'
},
check_calendar_sharing: {
CMMC: 'AC.L2-3.1.20',
NIST_800_171: '3.1.20',
NIST_CSF: 'PR.DS-05',
ISO_27001: 'A.8.12',
HIPAA: '164.312(e)(1)',
FTC: '314.4(c)(3)'
},
check_data_regions: {
CMMC: 'SC.L2-3.13.16',
NIST_800_171: '3.13.16',
NIST_CSF: 'PR.DS-01',
ISO_27001: 'A.8.10',
HIPAA: '164.312(a)(2)(iv)'
// FTC not applicable for data regions
},
check_shared_drives: {
CMMC: 'AC.L2-3.1.20',
NIST_800_171: '3.1.20',
NIST_CSF: 'PR.DS-05',
ISO_27001: 'A.8.12',
HIPAA: '164.312(e)(1)',
FTC: '314.4(c)(3)'
},
check_license_utilization: {
// Operational check, not directly mapped to compliance controls
CMMC: 'CM.L2-3.4.1',
NIST_800_171: '3.4.1',
NIST_CSF: 'ID.AM-01'
},
check_storage_usage: {
// Operational check, limited compliance mapping
CMMC: 'CM.L2-3.4.1',
NIST_800_171: '3.4.1',
NIST_CSF: 'ID.AM-01'
},
check_baa_status: {
// HIPAA-only
HIPAA: '164.308(b)(1)'
},
check_less_secure_apps: {
CMMC: 'IA.L2-3.5.3', NIST_800_171: '3.5.3', NIST_CSF: 'PR.AA-01',
ISO_27001: 'A.5.17', HIPAA: '164.312(d)', FTC: '314.4(c)(5)'
},
check_2fa_enforcement_method: {
CMMC: 'IA.L2-3.5.3', NIST_800_171: '3.5.3', NIST_CSF: 'PR.AA-01',
ISO_27001: 'A.5.17', HIPAA: '164.312(d)', FTC: '314.4(c)(5)'
},
check_super_admin_recovery: {
CMMC: 'AC.L2-3.1.5', NIST_800_171: '3.1.5', NIST_CSF: 'PR.AA-05',
ISO_27001: 'A.9.2.3', HIPAA: '164.308(a)(4)', FTC: '314.4(c)(1)'
},
check_advanced_protection: {
CMMC: 'IA.L2-3.5.3', NIST_800_171: '3.5.3', NIST_CSF: 'PR.AA-01',
ISO_27001: 'A.5.17', HIPAA: '164.312(d)', FTC: '314.4(c)(5)'
},
check_calendar_external_sharing_policy: {
CMMC: 'AC.L2-3.1.3', NIST_800_171: '3.1.3', NIST_CSF: 'PR.DS-05',
ISO_27001: 'A.8.12', HIPAA: '164.312(e)(1)', FTC: '314.4(c)(3)'
},
check_chat_external_restrictions: {
CMMC: 'AC.L2-3.1.3', NIST_800_171: '3.1.3', NIST_CSF: 'PR.AC-04',
ISO_27001: 'A.9.2.5', HIPAA: '164.312(a)(1)', FTC: '314.4(c)(3)'
},
check_meet_safety: {
CMMC: 'AC.L2-3.1.1', NIST_800_171: '3.1.1', NIST_CSF: 'PR.AC-01',
ISO_27001: 'A.8.2', HIPAA: '164.312(a)(2)(iii)', FTC: '314.4(c)(1)'
}
};
if (!ADMIN_EMAIL) {
console.error('ERROR: GOOGLE_WORKSPACE_ADMIN_EMAIL environment variable is not set');
console.error('Please create a .env file with: GOOGLE_WORKSPACE_ADMIN_EMAIL=your-admin@yourdomain.com');
process.exit(1);
}
const server = new Server(
{
name: 'workspace-compliance-audit',
version: '2.0.0',
},
{
capabilities: {
tools: {},
},
}
);
function getAdminClient(scopes) {
const auth = new google.auth.JWT({
email: credentials.client_email,
key: credentials.private_key,
scopes: scopes,
subject: ADMIN_EMAIL
});
return google.admin({ version: 'directory_v1', auth });
}
function getReportsClient(scopes) {
const auth = new google.auth.JWT({
email: credentials.client_email,
key: credentials.private_key,
scopes: scopes,
subject: ADMIN_EMAIL
});
return google.admin({ version: 'reports_v1', auth });
}
function getDriveClient(scopes) {
const auth = new google.auth.JWT({
email: credentials.client_email,
key: credentials.private_key,
scopes: scopes,
subject: ADMIN_EMAIL
});
return google.drive({ version: 'v3', auth });
}
function getPolicyClient(scopes) {
const auth = new google.auth.JWT({
email: credentials.client_email,
key: credentials.private_key,
scopes: scopes,
subject: ADMIN_EMAIL
});
return google.cloudidentity({ version: 'v1beta1', auth });
}
// Policy API rate limit: 1 QPS per customer
let lastPolicyApiCall = 0;
async function getPolicySetting(settingType) {
// Rate limiting: ensure 1 second between calls
const now = Date.now();
const timeSinceLastCall = now - lastPolicyApiCall;
if (timeSinceLastCall < 1100) {
await sleep(1100 - timeSinceLastCall);
}
lastPolicyApiCall = Date.now();
try {
const policy = getPolicyClient([
'https://www.googleapis.com/auth/cloud-identity.policies.readonly'
]);
const filter = `setting.type == "${settingType}"`;
const response = await policy.policies.list({ filter, pageSize: 100 });
if (!response.data.policies?.length) {
return { data_source: 'policy_api', status: 'no_policy_found', setting_type: settingType, value: null };
}
return {
data_source: 'policy_api',
status: 'success',
setting_type: settingType,
value: response.data.policies[0].setting?.value || {}
};
} catch (error) {
if (error.code === 403 || error.code === 401) {
return { data_source: 'manual_verification', status: 'api_permission_denied', error: error.message };
}
throw error;
}
}
// Helper: Sleep for rate limiting
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Helper: Fetch all users with pagination
async function fetchAllUsers(admin) {
const allUsers = [];
let pageToken = undefined;
do {
const response = await admin.users.list({
customer: 'my_customer',
maxResults: 500,
pageToken: pageToken
});
if (response.data.users) {
allUsers.push(...response.data.users);
}
pageToken = response.data.nextPageToken;
} while (pageToken);
return allUsers;
}
// Helper: Fetch all shared drives with pagination
async function fetchAllSharedDrives(drive) {
const allDrives = [];
let pageToken = undefined;
do {
const response = await drive.drives.list({
pageSize: 100,
pageToken: pageToken
});
if (response.data.drives) {
allDrives.push(...response.data.drives);
}
pageToken = response.data.nextPageToken;
} while (pageToken);
return allDrives;
}
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
// WORKFLOW ORCHESTRATION
{
name: 'start_compliance_audit',
description: 'Start a comprehensive Google Workspace compliance audit. IMPORTANT: Before calling this tool, you MUST first ask the user which compliance framework(s) they want to assess against. Present these options: CMMC (defense contractors), NIST 800-171 (government contractors), NIST CSF (general cybersecurity), ISO 27001 (international standard), HIPAA (healthcare), FTC Safeguards Rule (financial services). Do NOT call this tool until the user has selected their framework(s).',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to audit' },
frameworks: {
type: 'array',
items: {
type: 'string',
enum: ['CMMC', 'NIST_800_171', 'NIST_CSF', 'ISO_27001', 'HIPAA', 'FTC']
},
description: 'REQUIRED: Compliance frameworks selected by user. Must ask user first. Options: CMMC, NIST_800_171, NIST_CSF, ISO_27001, HIPAA, FTC'
}
},
required: ['domain', 'frameworks']
}
},
// ACCESS CONTROL
{
name: 'check_2fa_status',
description: 'Check if 2FA is enforced for all users in the domain',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_admin_roles',
description: 'List all users with admin privileges and their role assignments',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_session_settings',
description: 'Check session length and timeout settings',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_external_sharing',
description: 'Check external sharing settings and restrictions',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_api_access',
description: 'Check third-party API access and OAuth app permissions',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_groups_external_members',
description: 'Check for Google Groups that include external members',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// AUTHENTICATION
{
name: 'check_password_policy',
description: 'Check password strength and policy requirements',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_inactive_accounts',
description: 'Identify user accounts that have not logged in for 90+ days',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// AUDIT & ACCOUNTABILITY
{
name: 'check_audit_log_settings',
description: 'Check audit log retention and monitoring configuration',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_suspicious_activity',
description: 'Check for recent security alerts and suspicious login attempts',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// SYSTEM PROTECTION
{
name: 'check_mobile_devices',
description: 'Check mobile device management enrollment and encryption status',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_email_authentication',
description: 'Check SPF, DKIM, and DMARC email authentication status',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_email_forwarding',
description: 'Check for email forwarding rules to external addresses',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_calendar_sharing',
description: 'Check calendar external sharing settings',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_data_regions',
description: 'Check data residency and storage regions',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// MSP OPERATIONS
{
name: 'check_shared_drives',
description: 'Check shared drive permissions and external access',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_license_utilization',
description: 'Check license assignment and utilization',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_storage_usage',
description: 'Check storage quota usage across users',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// HIPAA-SPECIFIC
{
name: 'check_baa_status',
description: 'Check HIPAA Business Associate Agreement (BAA) status. Only relevant for HIPAA compliance.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// SECURITY SETTINGS (Policy API)
{
name: 'check_less_secure_apps',
description: 'Check if less secure app access is blocked. Less secure apps use basic authentication which is vulnerable to credential theft.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_2fa_enforcement_method',
description: 'Check the 2FA enforcement method and allowed second factors (security key, phone, etc.)',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_super_admin_recovery',
description: 'Check super admin account recovery settings. Weak recovery settings can be exploited to take over admin accounts.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_advanced_protection',
description: 'Check Advanced Protection Program enrollment settings. APP provides the strongest account security for high-risk users.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_calendar_external_sharing_policy',
description: 'Check the organization-wide calendar external sharing policy via Policy API.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_chat_external_restrictions',
description: 'Check Google Chat external messaging restrictions. Controls who users can message outside the organization.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
{
name: 'check_meet_safety',
description: 'Check Google Meet safety settings including host controls and external participant restrictions.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain to check' }
},
required: ['domain']
}
},
// REPORTING
{
name: 'generate_comprehensive_report',
description: 'Generate a comprehensive compliance audit report from collected findings. Supports multiple frameworks.',
inputSchema: {
type: 'object',
properties: {
domain: { type: 'string', description: 'The Google Workspace domain audited' },
findings: {
type: 'object',
description: 'Collected audit findings from all checks (as JSON object)'
},
active_frameworks: {
type: 'array',
items: {
type: 'string',
enum: ['CMMC', 'NIST_800_171', 'NIST_CSF', 'ISO_27001', 'HIPAA', 'FTC']
},
description: 'Frameworks the audit was conducted against'
},
context_notes: {
type: 'string',
description: 'Optional additional context gathered during Q&A sessions'
}
},
required: ['domain', 'findings', 'active_frameworks']
}
}
]
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const toolName = request.params.name;
const domain = request.params.arguments.domain;
try {
// WORKFLOW ORCHESTRATION
if (toolName === 'start_compliance_audit') {
const frameworks = request.params.arguments.frameworks;
if (!frameworks || frameworks.length === 0) {
return {
content: [{
type: 'text',
text: 'ERROR: No compliance frameworks selected. Please ask the user which framework(s) they want to assess against:\n\n- CMMC (defense contractors)\n- NIST 800-171 (government contractors)\n- NIST CSF (general cybersecurity)\n- ISO 27001 (international standard)\n- HIPAA (healthcare)\n- FTC Safeguards Rule (financial services)\n\nThen call this tool again with the selected frameworks.'
}]
};
}
const frameworkList = frameworks.join(', ');
const includesHIPAA = frameworks.includes('HIPAA');
const workflowInstructions = `
# Compliance Audit Workflow Started for ${domain}
## Selected Frameworks: ${frameworkList}
Follow this structured workflow to conduct a comprehensive audit:
## PHASE 0: BUSINESS CONTEXT (START HERE - DO NOT SKIP)
Before running ANY checks, ask the user these questions:
1. "Can you describe in a couple of sentences what your business does?"
2. "How many employees does your organization have?"
${includesHIPAA ? '3. "Does your organization handle Protected Health Information (PHI)?"' : ''}
**Store this information** - you'll use it to contextualize findings and include in the final report.
---
## PHASE 1: ACCESS CONTROL (9 checks)
Run these tools:
- check_2fa_status
- check_2fa_enforcement_method
- check_admin_roles
- check_super_admin_recovery
- check_session_settings
- check_external_sharing
- check_api_access
- check_groups_external_members
- check_less_secure_apps
**After displaying ALL results, STOP and ask:**
1. "Are there any users without 2FA that should be exceptions (service accounts)?"
2. "Can you provide context on external group members or sharing?"
**WAIT FOR THE USER'S RESPONSE. DO NOT PROCEED TO PHASE 2 UNTIL THE USER ANSWERS.**
Store their responses, then continue to Phase 2.
---
## PHASE 2: AUTHENTICATION (3 checks)
Run these tools:
- check_password_policy
- check_inactive_accounts
- check_advanced_protection
**After displaying results, STOP and ask:**
1. "Are any inactive accounts intentional (seasonal workers, extended leave)?"
**WAIT FOR THE USER'S RESPONSE. DO NOT PROCEED TO PHASE 3 UNTIL THE USER ANSWERS.**
Store responses, then continue to Phase 3.
---
## PHASE 3: AUDIT & ACCOUNTABILITY (2 checks)
Run these tools:
- check_audit_log_settings
- check_suspicious_activity
**After displaying results, STOP and ask:**
1. "Do you have a SIEM or log aggregation system?"
2. "Are you exporting audit logs for long-term retention (1+ year for CMMC)?"
**WAIT FOR THE USER'S RESPONSE. DO NOT PROCEED TO PHASE 4 UNTIL THE USER ANSWERS.**
Store responses, then continue to Phase 4.
---
## PHASE 4: SYSTEM PROTECTION (8 checks)
Run these tools:
- check_mobile_devices
- check_email_authentication
- check_email_forwarding
- check_calendar_sharing
- check_calendar_external_sharing_policy
- check_chat_external_restrictions
- check_meet_safety
- check_data_regions
**After displaying results, STOP and ask:**
1. "Do you have a BYOD policy or corporate device policy?"
2. "Are you handling ITAR-controlled data that requires US-only residency?"
**WAIT FOR THE USER'S RESPONSE. DO NOT PROCEED TO PHASE 5 UNTIL THE USER ANSWERS.**
Store responses, then continue to Phase 5.
---
## PHASE 5: MSP OPERATIONS (3 checks)
Run these tools:
- check_shared_drives
- check_license_utilization
- check_storage_usage
${includesHIPAA ? '- check_baa_status (HIPAA only)' : ''}
**After displaying results, STOP and ask:**
1. "Would you like recommendations on removing inactive licenses for cost savings?"
2. "Are external shared drive accesses business-critical?"
**WAIT FOR THE USER'S RESPONSE. DO NOT PROCEED TO PHASE 6 UNTIL THE USER ANSWERS.**
Store responses, then continue to Phase 6.
---
## PHASE 6: MANUAL VERIFICATION (CRITICAL - DO NOT SKIP)
**Say to the user:**
"Before generating the final report, I need to verify several settings that require manual checks in Google Admin Console. I'll walk you through each one."
For EACH manual check that returned "Manual verification required", request a screenshot:
### Session Settings (if applicable)
"Let's verify your session control settings:
1. Go to: Google Admin Console > Security > Session control
2. Take a screenshot showing session length and idle timeout
3. Share the screenshot
This verifies CMMC's 15-minute idle timeout requirement."
**When screenshot provided:**
- Analyze it carefully
- Note actual values (e.g., "Web: 8 hours, Idle: 15 min")
- Determine: PASS or FAIL
### External Sharing (if applicable)
"Let's verify external sharing:
1. Go to: Google Admin Console > Apps > Google Workspace > Drive and Docs
2. Click Sharing settings
3. Screenshot the sharing configuration
4. Share it"
**When provided:** Analyze and store findings.
### Password Policy (if applicable)
"Let's verify password policy:
1. Go to: Google Admin Console > Security > Password management
2. Screenshot minimum length and reuse prevention settings
3. Share it"
**When provided:** Check if ≥12 chars and ≥24 password history.
### Email Authentication (if applicable)
"Let's verify email authentication (SPF/DKIM/DMARC):
**For DNS records, you'll need to check manually:**
Option 1 (Recommended) - Use MXToolbox:
1. Go to https://mxtoolbox.com/SuperTool.aspx
2. Enter your domain: ${domain}
3. Check: SPF Record, DKIM Record, DMARC Record
4. Copy and paste the results here
Option 2 - Command line (if you have access):
Run these commands:
- nslookup -type=TXT ${domain}
- nslookup -type=TXT google._domainkey.${domain}
- nslookup -type=TXT _dmarc.${domain}
Option 3 - Google Admin Console:
1. Go to Admin Console > Apps > Gmail > Authenticate email
2. Screenshot the DKIM and SPF settings
3. Share the screenshot
**Note:** I cannot perform DNS lookups directly. Please use one of the methods above and share the results."
**Continue this pattern for all manual checks.**
After ALL screenshots collected, say:
"Thank you! I've verified all manual settings. Now generating your comprehensive report..."
---
## PHASE 7: GENERATE COMPREHENSIVE REPORT
Compile everything:
1. Business context (Phase 0)
2. All automated check results (Phases 1-5)
3. Manual verification findings from screenshots (Phase 6)
4. All Q&A responses
**IMPORTANT: Create a findings object structured like this:**
findings = {
"check_2fa_status": { result from that check },
"check_admin_roles": { result from that check },
"check_password_policy": { result from that check, including manual verification if done },
... (all checks performed)
}
**Then call: generate_comprehensive_report**
Parameters:
- domain: ${domain}
- findings: The findings object above (as a JSON object, not a string)
- active_frameworks: ${JSON.stringify(frameworks)}
- context_notes: Text containing all context:
"BUSINESS CONTEXT:
Organization: [from Phase 0]
Employees: [from Phase 0]
PHASE 1-5 CONTEXT:
[All Q&A responses]
MANUAL VERIFICATION RESULTS:
Session Settings: [findings from screenshot]
Password Policy: [findings from screenshot]
Email Authentication: [findings from DNS lookup or screenshot]
... [other manual verifications]
"
Present the final report with:
- Executive summary (include business context)
- Compliance score per framework (${frameworkList})
- Findings grouped by selected framework controls
- Priority recommendations
- Cost optimization opportunities
- Next steps
---
## IMPORTANT REMINDERS
✓ DO NOT skip Phase 0 (business context)
✓ DO NOT skip Phase 6 (screenshot verification)
✓ DO request screenshots with specific navigation instructions
✓ DO analyze screenshots when provided
✓ DO include ALL context in the final report
✓ DO tailor recommendations to organization size and industry
Start with Phase 0 now!
`;
return {
content: [{
type: 'text',
text: workflowInstructions
}]
};
}
// ACCESS CONTROL CHECKS
if (toolName === 'check_2fa_status') {
const admin = getAdminClient(['https://www.googleapis.com/auth/admin.directory.user.readonly']);
const users = await fetchAllUsers(admin);
let usersWithout2FA = 0;
let totalUsers = 0;
let adminWithout2FA = 0;
for (const user of users) {
totalUsers++;
if (!user.isEnrolledIn2Sv) {
usersWithout2FA++;
if (user.isAdmin) adminWithout2FA++;
}
}
const result = {
domain: domain,
data_source: 'admin_sdk',
total_users: totalUsers,
mfa_enforced: usersWithout2FA === 0,
users_without_mfa: usersWithout2FA,
admin_accounts_without_mfa: adminWithout2FA,
compliance_mappings: COMPLIANCE_MAPPINGS.check_2fa_status,
recommendation: usersWithout2FA > 0
? 'Enable 2FA enforcement for all users. Require hardware security keys for admin accounts.'
: 'All users have 2FA enabled. Consider requiring hardware security keys for privileged accounts.',
licensing_note: '2FA is included in all Google Workspace editions.'
};
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
}
if (toolName === 'check_admin_roles') {
const admin = getAdminClient([
'https://www.googleapis.com/auth/admin.directory.user.readonly',
'https://www.googleapis.com/auth/admin.directory.rolemanagement.readonly'
]);
const users = await fetchAllUsers(admin);