misp-mcp 1.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.
package/dist/index.js ADDED
@@ -0,0 +1,2359 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+
7
+ // src/config.ts
8
+ function getConfig() {
9
+ const url = process.env.MISP_URL;
10
+ if (!url) {
11
+ throw new Error("MISP_URL environment variable is required");
12
+ }
13
+ const apiKey = process.env.MISP_API_KEY;
14
+ if (!apiKey) {
15
+ throw new Error("MISP_API_KEY environment variable is required");
16
+ }
17
+ const verifySsl = process.env.MISP_VERIFY_SSL !== "false";
18
+ const timeout = parseInt(process.env.MISP_TIMEOUT ?? "30", 10) * 1e3;
19
+ return {
20
+ url: url.replace(/\/+$/, ""),
21
+ apiKey,
22
+ verifySsl,
23
+ timeout
24
+ };
25
+ }
26
+
27
+ // src/client.ts
28
+ var MispClient = class {
29
+ baseUrl;
30
+ apiKey;
31
+ verifySsl;
32
+ timeout;
33
+ constructor(config2) {
34
+ this.baseUrl = config2.url;
35
+ this.apiKey = config2.apiKey;
36
+ this.verifySsl = config2.verifySsl;
37
+ this.timeout = config2.timeout;
38
+ }
39
+ async request(method, path, body, rawResponse = false) {
40
+ const url = `${this.baseUrl}${path}`;
41
+ const headers = {
42
+ Authorization: this.apiKey,
43
+ Accept: "application/json",
44
+ "Content-Type": "application/json"
45
+ };
46
+ const controller = new AbortController();
47
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
48
+ const options = {
49
+ method,
50
+ headers,
51
+ body: body ? JSON.stringify(body) : void 0,
52
+ signal: controller.signal
53
+ };
54
+ let response;
55
+ try {
56
+ response = await fetch(url, options);
57
+ } catch (err) {
58
+ if (err instanceof Error && err.name === "AbortError") {
59
+ throw new Error(`MISP API timeout after ${this.timeout}ms`);
60
+ }
61
+ const message = err instanceof Error ? err.message : String(err);
62
+ throw new Error(`MISP API request failed: ${message}`);
63
+ } finally {
64
+ clearTimeout(timeoutId);
65
+ }
66
+ const text = await response.text();
67
+ if (!response.ok) {
68
+ const statusMessages = {
69
+ 401: "Invalid API key or unauthorized",
70
+ 403: "Insufficient permissions",
71
+ 404: "Resource not found",
72
+ 405: "Method not allowed"
73
+ };
74
+ const prefix = statusMessages[response.status] || `HTTP ${response.status}`;
75
+ let detail = "";
76
+ try {
77
+ const parsed = JSON.parse(text);
78
+ detail = parsed.message || parsed.errors || text;
79
+ } catch {
80
+ detail = text;
81
+ }
82
+ throw new Error(`${prefix}: ${detail}`);
83
+ }
84
+ if (rawResponse) {
85
+ return text;
86
+ }
87
+ try {
88
+ return JSON.parse(text);
89
+ } catch {
90
+ throw new Error(`Failed to parse MISP response as JSON: ${text.slice(0, 200)}`);
91
+ }
92
+ }
93
+ // --- Event methods ---
94
+ async searchEvents(params) {
95
+ const body = {
96
+ returnFormat: "json",
97
+ limit: params.limit ?? 50
98
+ };
99
+ if (params.value) body.value = params.value;
100
+ if (params.type) body.type = params.type;
101
+ if (params.category) body.category = params.category;
102
+ if (params.tags) body.tags = params.tags;
103
+ if (params.eventid) body.eventid = params.eventid;
104
+ if (params.org) body.org = params.org;
105
+ if (params.dateFrom) body.from = params.dateFrom;
106
+ if (params.dateTo) body.to = params.dateTo;
107
+ if (params.last) body.last = params.last;
108
+ if (params.published !== void 0) body.published = params.published ? 1 : 0;
109
+ if (params.page) body.page = params.page;
110
+ const data = await this.request(
111
+ "POST",
112
+ "/events/restSearch",
113
+ body
114
+ );
115
+ return (data.response || []).map((r) => r.Event);
116
+ }
117
+ async getEvent(eventId) {
118
+ const data = await this.request(
119
+ "GET",
120
+ `/events/view/${eventId}`
121
+ );
122
+ return data.Event;
123
+ }
124
+ async createEvent(params) {
125
+ const eventData = {
126
+ info: params.info,
127
+ distribution: params.distribution,
128
+ threat_level_id: params.threat_level_id,
129
+ analysis: params.analysis
130
+ };
131
+ if (params.date) eventData.date = params.date;
132
+ if (params.published) eventData.published = params.published;
133
+ const data = await this.request("POST", "/events/add", {
134
+ Event: eventData
135
+ });
136
+ if (params.tags && params.tags.length > 0 && data.Event.id) {
137
+ for (const tag of params.tags) {
138
+ await this.tagEvent(data.Event.id, tag);
139
+ }
140
+ return this.getEvent(data.Event.id);
141
+ }
142
+ return data.Event;
143
+ }
144
+ async updateEvent(eventId, params) {
145
+ const eventData = {};
146
+ if (params.info !== void 0) eventData.info = params.info;
147
+ if (params.threat_level_id !== void 0)
148
+ eventData.threat_level_id = params.threat_level_id;
149
+ if (params.analysis !== void 0) eventData.analysis = params.analysis;
150
+ if (params.published !== void 0) eventData.published = params.published;
151
+ const data = await this.request(
152
+ "POST",
153
+ `/events/edit/${eventId}`,
154
+ { Event: eventData }
155
+ );
156
+ return data.Event;
157
+ }
158
+ async publishEvent(eventId) {
159
+ return this.request(
160
+ "POST",
161
+ `/events/publish/${eventId}`
162
+ );
163
+ }
164
+ async tagEvent(eventId, tag) {
165
+ return this.request("POST", "/events/addTag", {
166
+ event: eventId,
167
+ tag
168
+ });
169
+ }
170
+ async untagEvent(eventId, tag) {
171
+ return this.request("POST", "/events/removeTag", {
172
+ event: eventId,
173
+ tag
174
+ });
175
+ }
176
+ // --- Attribute methods ---
177
+ async searchAttributes(params) {
178
+ const body = {
179
+ returnFormat: "json",
180
+ limit: params.limit ?? 50
181
+ };
182
+ if (params.value) body.value = params.value;
183
+ if (params.type) body.type = params.type;
184
+ if (params.category) body.category = params.category;
185
+ if (params.tags) body.tags = params.tags;
186
+ if (params.to_ids !== void 0) body.to_ids = params.to_ids ? 1 : 0;
187
+ if (params.includeCorrelations)
188
+ body.includeCorrelations = 1;
189
+ if (params.last) body.last = params.last;
190
+ const data = await this.request(
191
+ "POST",
192
+ "/attributes/restSearch",
193
+ body
194
+ );
195
+ return data.response?.Attribute || [];
196
+ }
197
+ async addAttribute(eventId, params) {
198
+ const attrData = {
199
+ type: params.type,
200
+ value: params.value
201
+ };
202
+ if (params.category) attrData.category = params.category;
203
+ if (params.to_ids !== void 0) attrData.to_ids = params.to_ids;
204
+ if (params.comment) attrData.comment = params.comment;
205
+ if (params.distribution !== void 0)
206
+ attrData.distribution = params.distribution;
207
+ const data = await this.request(
208
+ "POST",
209
+ `/attributes/add/${eventId}`,
210
+ attrData
211
+ );
212
+ if (params.tags && params.tags.length > 0 && data.Attribute?.id) {
213
+ for (const tag of params.tags) {
214
+ await this.request("POST", "/attributes/addTag", {
215
+ attribute: data.Attribute.id,
216
+ tag
217
+ });
218
+ }
219
+ }
220
+ return data.Attribute;
221
+ }
222
+ async deleteAttribute(attributeId, hard = false) {
223
+ const body = hard ? { hard: 1 } : {};
224
+ return this.request(
225
+ "POST",
226
+ `/attributes/delete/${attributeId}`,
227
+ body
228
+ );
229
+ }
230
+ // --- Describe types ---
231
+ async describeTypes() {
232
+ const data = await this.request(
233
+ "GET",
234
+ "/attributes/describeTypes"
235
+ );
236
+ return data.result;
237
+ }
238
+ // --- Tags ---
239
+ async listTags(search) {
240
+ const path = search ? `/tags/search/${encodeURIComponent(search)}` : "/tags";
241
+ const data = await this.request("GET", path);
242
+ return data.Tag || [];
243
+ }
244
+ // --- Sightings ---
245
+ async addSighting(params) {
246
+ const body = {
247
+ type: params.type
248
+ };
249
+ if (params.value) body.value = params.value;
250
+ if (params.source) body.source = params.source;
251
+ if (params.timestamp) body.timestamp = params.timestamp;
252
+ const path = params.attributeId ? `/sightings/add/${params.attributeId}` : "/sightings/add";
253
+ const data = await this.request("POST", path, body);
254
+ return data.Sighting;
255
+ }
256
+ // --- Warninglists ---
257
+ async checkWarninglists(value) {
258
+ return this.request(
259
+ "POST",
260
+ "/warninglists/checkValue",
261
+ [value]
262
+ );
263
+ }
264
+ // --- Statistics ---
265
+ async getStatistics() {
266
+ return this.request("GET", "/events/index");
267
+ }
268
+ // --- Taxonomies ---
269
+ async listTaxonomies() {
270
+ const data = await this.request("GET", "/taxonomies");
271
+ return (data || []).map((t) => t.Taxonomy);
272
+ }
273
+ // --- Exports ---
274
+ async exportEvents(params) {
275
+ const formatEndpoints = {
276
+ csv: "/events/csv/download",
277
+ stix: "/events/stix/download",
278
+ suricata: "/events/nids/suricata/download",
279
+ snort: "/events/nids/snort/download",
280
+ text: "/attributes/text/download",
281
+ rpz: "/attributes/rpz/download"
282
+ };
283
+ const endpoint = formatEndpoints[params.format];
284
+ if (!endpoint) {
285
+ throw new Error(
286
+ `Unsupported export format: ${params.format}. Supported: ${Object.keys(formatEndpoints).join(", ")}`
287
+ );
288
+ }
289
+ const body = {};
290
+ if (params.eventId) body.eventid = params.eventId;
291
+ if (params.type) body.type = params.type;
292
+ if (params.tags) body.tags = params.tags;
293
+ if (params.last) body.last = params.last;
294
+ return this.request("POST", endpoint, body, true);
295
+ }
296
+ async exportHashes(params) {
297
+ const validFormats = ["md5", "sha1", "sha256"];
298
+ if (!validFormats.includes(params.format)) {
299
+ throw new Error(
300
+ `Unsupported hash format: ${params.format}. Supported: ${validFormats.join(", ")}`
301
+ );
302
+ }
303
+ let path = `/events/hids/${params.format}/download`;
304
+ const queryParts = [];
305
+ if (params.last) queryParts.push(`last=${encodeURIComponent(params.last)}`);
306
+ if (params.tags) queryParts.push(`tags=${encodeURIComponent(params.tags.join(","))}`);
307
+ if (queryParts.length > 0) path += `?${queryParts.join("&")}`;
308
+ return this.request("GET", path, void 0, true);
309
+ }
310
+ // --- Objects ---
311
+ async listObjectTemplates() {
312
+ const data = await this.request("GET", "/objectTemplates");
313
+ return (data || []).map((t) => t.ObjectTemplate);
314
+ }
315
+ async getObjectTemplate(templateId) {
316
+ const data = await this.request(
317
+ "GET",
318
+ `/objectTemplates/view/${templateId}`
319
+ );
320
+ return data.ObjectTemplate;
321
+ }
322
+ async addObject(eventId, params) {
323
+ const body = {
324
+ name: params.name,
325
+ Attribute: params.attributes.map((a) => ({
326
+ object_relation: a.object_relation,
327
+ type: a.type,
328
+ value: a.value,
329
+ to_ids: a.to_ids ?? false,
330
+ comment: a.comment
331
+ }))
332
+ };
333
+ if (params.comment) body.comment = params.comment;
334
+ if (params.distribution !== void 0)
335
+ body.distribution = params.distribution;
336
+ const data = await this.request(
337
+ "POST",
338
+ `/objects/add/${eventId}`,
339
+ body
340
+ );
341
+ return data.Object;
342
+ }
343
+ async deleteObject(objectId, hard = false) {
344
+ const body = hard ? { hard: 1 } : {};
345
+ return this.request(
346
+ "POST",
347
+ `/objects/delete/${objectId}`,
348
+ body
349
+ );
350
+ }
351
+ // --- Galaxies ---
352
+ async listGalaxies() {
353
+ const data = await this.request("GET", "/galaxies");
354
+ return (data || []).map((g) => g.Galaxy);
355
+ }
356
+ async getGalaxy(galaxyId) {
357
+ const data = await this.request("GET", `/galaxies/view/${galaxyId}`);
358
+ return {
359
+ ...data.Galaxy,
360
+ GalaxyCluster: data.GalaxyCluster
361
+ };
362
+ }
363
+ async searchGalaxyClusters(search, galaxyType) {
364
+ const body = {
365
+ searchall: search
366
+ };
367
+ if (galaxyType) body.context = galaxyType;
368
+ const data = await this.request("POST", "/galaxy_clusters/restSearch", body);
369
+ return (data || []).map((c) => c.GalaxyCluster);
370
+ }
371
+ async attachGalaxyCluster(targetType, targetId, galaxyClusterId) {
372
+ return this.request(
373
+ "POST",
374
+ `/galaxies/attachCluster/${targetId}/${targetType}`,
375
+ { Galaxy: { target_id: galaxyClusterId } }
376
+ );
377
+ }
378
+ // --- Feeds ---
379
+ async listFeeds() {
380
+ const data = await this.request(
381
+ "GET",
382
+ "/feeds"
383
+ );
384
+ return (data || []).map((f) => f.Feed);
385
+ }
386
+ async toggleFeed(feedId, enable) {
387
+ return this.request(
388
+ "POST",
389
+ `/feeds/${enable ? "enable" : "disable"}/${feedId}`
390
+ );
391
+ }
392
+ async fetchFeed(feedId) {
393
+ return this.request(
394
+ "GET",
395
+ `/feeds/fetchFromFeed/${feedId}`
396
+ );
397
+ }
398
+ async cacheFeed(feedId) {
399
+ return this.request(
400
+ "GET",
401
+ `/feeds/cacheFeeds/${feedId}`
402
+ );
403
+ }
404
+ // --- Organisations ---
405
+ async listOrganisations(scope = "all") {
406
+ const data = await this.request("GET", `/organisations/index/scope:${scope}`);
407
+ return (data || []).map((o) => o.Organisation);
408
+ }
409
+ async getOrganisation(orgId) {
410
+ const data = await this.request(
411
+ "GET",
412
+ `/organisations/view/${orgId}`
413
+ );
414
+ return data.Organisation;
415
+ }
416
+ // --- Server ---
417
+ async getVersion() {
418
+ return this.request("GET", "/servers/getVersion");
419
+ }
420
+ async getServerSettings() {
421
+ try {
422
+ return await this.request(
423
+ "GET",
424
+ "/servers/serverSettings"
425
+ );
426
+ } catch {
427
+ return {};
428
+ }
429
+ }
430
+ async listSharingGroups() {
431
+ const data = await this.request("GET", "/sharing_groups");
432
+ return (data.response || []).map((g) => g.SharingGroup);
433
+ }
434
+ async deleteEvent(eventId) {
435
+ return this.request(
436
+ "POST",
437
+ `/events/delete/${eventId}`
438
+ );
439
+ }
440
+ };
441
+
442
+ // src/tools/events.ts
443
+ import { z } from "zod";
444
+ function registerEventTools(server2, client2) {
445
+ server2.tool(
446
+ "misp_search_events",
447
+ "Search MISP events by IOC value, type, tags, date range, or organization",
448
+ {
449
+ value: z.string().optional().describe("IOC value to search across all attributes"),
450
+ type: z.string().optional().describe("Attribute type filter (ip-src, ip-dst, domain, md5, sha256, url, email-src, etc.)"),
451
+ category: z.string().optional().describe("Category filter (Network activity, Payload delivery, External analysis, etc.)"),
452
+ tags: z.array(z.string()).optional().describe("Tag filters (e.g., tlp:white, misp-galaxy:mitre-attack-pattern)"),
453
+ eventId: z.string().optional().describe("Specific event ID"),
454
+ org: z.string().optional().describe("Organization filter"),
455
+ dateFrom: z.string().optional().describe("Start date (YYYY-MM-DD)"),
456
+ dateTo: z.string().optional().describe("End date (YYYY-MM-DD)"),
457
+ last: z.string().optional().describe("Relative time (e.g., 1d, 7d, 30d, 6m)"),
458
+ published: z.boolean().optional().describe("Only published events"),
459
+ limit: z.number().optional().describe("Max results (default 50)"),
460
+ page: z.number().optional().describe("Page number for pagination")
461
+ },
462
+ async (params) => {
463
+ try {
464
+ const events = await client2.searchEvents({
465
+ value: params.value,
466
+ type: params.type,
467
+ category: params.category,
468
+ tags: params.tags,
469
+ eventid: params.eventId,
470
+ org: params.org,
471
+ dateFrom: params.dateFrom,
472
+ dateTo: params.dateTo,
473
+ last: params.last,
474
+ published: params.published,
475
+ limit: params.limit,
476
+ page: params.page
477
+ });
478
+ if (events.length === 0) {
479
+ return {
480
+ content: [{ type: "text", text: "No events found matching the search criteria." }]
481
+ };
482
+ }
483
+ const summary = events.map((e) => ({
484
+ id: e.id,
485
+ info: e.info,
486
+ date: e.date,
487
+ threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(e.threat_level_id) || 0],
488
+ analysis: ["Initial", "Ongoing", "Complete"][parseInt(e.analysis) || 0],
489
+ published: e.published,
490
+ org: e.Orgc?.name || "Unknown",
491
+ attribute_count: e.attribute_count,
492
+ tags: (e.Tag || []).map((t) => t.name)
493
+ }));
494
+ return {
495
+ content: [
496
+ {
497
+ type: "text",
498
+ text: JSON.stringify(summary, null, 2)
499
+ }
500
+ ]
501
+ };
502
+ } catch (err) {
503
+ return {
504
+ content: [
505
+ { type: "text", text: `Error searching events: ${err instanceof Error ? err.message : String(err)}` }
506
+ ],
507
+ isError: true
508
+ };
509
+ }
510
+ }
511
+ );
512
+ server2.tool(
513
+ "misp_get_event",
514
+ "Get full details of a specific MISP event including all attributes, objects, tags, and related events",
515
+ {
516
+ eventId: z.string().describe("Event ID to retrieve")
517
+ },
518
+ async ({ eventId }) => {
519
+ try {
520
+ const event = await client2.getEvent(eventId);
521
+ const result = {
522
+ id: event.id,
523
+ uuid: event.uuid,
524
+ info: event.info,
525
+ date: event.date,
526
+ threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(event.threat_level_id) || 0],
527
+ analysis: ["Initial", "Ongoing", "Complete"][parseInt(event.analysis) || 0],
528
+ distribution: ["Organization", "Community", "Connected communities", "All communities", "Sharing group"][parseInt(event.distribution) || 0],
529
+ published: event.published,
530
+ org: event.Orgc?.name || "Unknown",
531
+ tags: (event.Tag || []).map((t) => t.name),
532
+ attribute_count: event.attribute_count,
533
+ attributes: (event.Attribute || []).map((a) => ({
534
+ id: a.id,
535
+ type: a.type,
536
+ category: a.category,
537
+ value: a.value,
538
+ to_ids: a.to_ids,
539
+ comment: a.comment
540
+ })),
541
+ objects: (event.Object || []).map((o) => ({
542
+ id: o.id,
543
+ name: o.name,
544
+ meta_category: o.meta_category,
545
+ attributes: (o.Attribute || []).map((a) => ({
546
+ type: a.type,
547
+ value: a.value
548
+ }))
549
+ })),
550
+ galaxies: (event.Galaxy || []).map((g) => ({
551
+ name: g.name,
552
+ type: g.type,
553
+ clusters: (g.GalaxyCluster || []).map((c) => c.value)
554
+ })),
555
+ related_events: (event.RelatedEvent || []).map((r) => ({
556
+ id: r.Event.id,
557
+ info: r.Event.info,
558
+ date: r.Event.date
559
+ }))
560
+ };
561
+ return {
562
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
563
+ };
564
+ } catch (err) {
565
+ return {
566
+ content: [
567
+ { type: "text", text: `Error getting event: ${err instanceof Error ? err.message : String(err)}` }
568
+ ],
569
+ isError: true
570
+ };
571
+ }
572
+ }
573
+ );
574
+ server2.tool(
575
+ "misp_create_event",
576
+ "Create a new MISP event for documenting incidents or threat intelligence",
577
+ {
578
+ info: z.string().describe("Event description/title"),
579
+ distribution: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).describe("0=Organization only, 1=Community, 2=Connected communities, 3=All communities, 4=Sharing group"),
580
+ threatLevel: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).describe("1=High, 2=Medium, 3=Low, 4=Undefined"),
581
+ analysis: z.union([z.literal(0), z.literal(1), z.literal(2)]).describe("0=Initial, 1=Ongoing, 2=Complete"),
582
+ date: z.string().optional().describe("Event date (YYYY-MM-DD)"),
583
+ tags: z.array(z.string()).optional().describe("Tags to apply"),
584
+ published: z.boolean().optional().describe("Publish immediately")
585
+ },
586
+ async (params) => {
587
+ try {
588
+ const event = await client2.createEvent({
589
+ info: params.info,
590
+ distribution: params.distribution,
591
+ threat_level_id: params.threatLevel,
592
+ analysis: params.analysis,
593
+ date: params.date,
594
+ tags: params.tags,
595
+ published: params.published
596
+ });
597
+ return {
598
+ content: [
599
+ {
600
+ type: "text",
601
+ text: JSON.stringify(
602
+ {
603
+ id: event.id,
604
+ uuid: event.uuid,
605
+ info: event.info,
606
+ date: event.date,
607
+ published: event.published,
608
+ tags: (event.Tag || []).map((t) => t.name)
609
+ },
610
+ null,
611
+ 2
612
+ )
613
+ }
614
+ ]
615
+ };
616
+ } catch (err) {
617
+ return {
618
+ content: [
619
+ { type: "text", text: `Error creating event: ${err instanceof Error ? err.message : String(err)}` }
620
+ ],
621
+ isError: true
622
+ };
623
+ }
624
+ }
625
+ );
626
+ server2.tool(
627
+ "misp_update_event",
628
+ "Update an existing MISP event's metadata (info, threat level, analysis status, publish state)",
629
+ {
630
+ eventId: z.string().describe("Event ID to update"),
631
+ info: z.string().optional().describe("New event description"),
632
+ threatLevel: z.number().optional().describe("1=High, 2=Medium, 3=Low, 4=Undefined"),
633
+ analysis: z.number().optional().describe("0=Initial, 1=Ongoing, 2=Complete"),
634
+ published: z.boolean().optional().describe("Set published status")
635
+ },
636
+ async ({ eventId, info, threatLevel, analysis, published }) => {
637
+ try {
638
+ const event = await client2.updateEvent(eventId, {
639
+ info,
640
+ threat_level_id: threatLevel,
641
+ analysis,
642
+ published
643
+ });
644
+ return {
645
+ content: [
646
+ {
647
+ type: "text",
648
+ text: JSON.stringify(
649
+ {
650
+ id: event.id,
651
+ info: event.info,
652
+ threat_level_id: event.threat_level_id,
653
+ analysis: event.analysis,
654
+ published: event.published
655
+ },
656
+ null,
657
+ 2
658
+ )
659
+ }
660
+ ]
661
+ };
662
+ } catch (err) {
663
+ return {
664
+ content: [
665
+ { type: "text", text: `Error updating event: ${err instanceof Error ? err.message : String(err)}` }
666
+ ],
667
+ isError: true
668
+ };
669
+ }
670
+ }
671
+ );
672
+ server2.tool(
673
+ "misp_publish_event",
674
+ "Publish a MISP event, triggering alerts and notifications to sharing partners",
675
+ {
676
+ eventId: z.string().describe("Event ID to publish")
677
+ },
678
+ async ({ eventId }) => {
679
+ try {
680
+ const result = await client2.publishEvent(eventId);
681
+ return {
682
+ content: [
683
+ { type: "text", text: result.message || `Event ${eventId} published successfully.` }
684
+ ]
685
+ };
686
+ } catch (err) {
687
+ return {
688
+ content: [
689
+ { type: "text", text: `Error publishing event: ${err instanceof Error ? err.message : String(err)}` }
690
+ ],
691
+ isError: true
692
+ };
693
+ }
694
+ }
695
+ );
696
+ server2.tool(
697
+ "misp_tag_event",
698
+ "Add or remove a tag from a MISP event (TLP, MITRE ATT&CK, custom tags)",
699
+ {
700
+ eventId: z.string().describe("Event ID to tag"),
701
+ tag: z.string().describe("Tag name (e.g., tlp:white, misp-galaxy:mitre-attack-pattern)"),
702
+ remove: z.boolean().optional().describe("Set to true to remove the tag instead of adding")
703
+ },
704
+ async ({ eventId, tag, remove }) => {
705
+ try {
706
+ if (remove) {
707
+ await client2.untagEvent(eventId, tag);
708
+ return {
709
+ content: [
710
+ { type: "text", text: `Tag "${tag}" removed from event ${eventId}.` }
711
+ ]
712
+ };
713
+ } else {
714
+ await client2.tagEvent(eventId, tag);
715
+ return {
716
+ content: [
717
+ { type: "text", text: `Tag "${tag}" added to event ${eventId}.` }
718
+ ]
719
+ };
720
+ }
721
+ } catch (err) {
722
+ return {
723
+ content: [
724
+ { type: "text", text: `Error tagging event: ${err instanceof Error ? err.message : String(err)}` }
725
+ ],
726
+ isError: true
727
+ };
728
+ }
729
+ }
730
+ );
731
+ }
732
+
733
+ // src/tools/attributes.ts
734
+ import { z as z2 } from "zod";
735
+ function registerAttributeTools(server2, client2) {
736
+ server2.tool(
737
+ "misp_search_attributes",
738
+ "Search for specific attributes (IOCs) across all MISP events",
739
+ {
740
+ value: z2.string().optional().describe("IOC value to search"),
741
+ type: z2.string().optional().describe("Attribute type (ip-src, ip-dst, domain, md5, sha256, url, email-src, hostname, etc.)"),
742
+ category: z2.string().optional().describe("Category filter"),
743
+ tags: z2.array(z2.string()).optional().describe("Tag filters"),
744
+ toIds: z2.boolean().optional().describe("Only IDS-flagged attributes"),
745
+ includeCorrelations: z2.boolean().optional().describe("Include correlation data"),
746
+ last: z2.string().optional().describe("Relative time filter (e.g., 1d, 7d, 30d)"),
747
+ limit: z2.number().optional().describe("Max results (default 50)")
748
+ },
749
+ async (params) => {
750
+ try {
751
+ const attributes = await client2.searchAttributes({
752
+ value: params.value,
753
+ type: params.type,
754
+ category: params.category,
755
+ tags: params.tags,
756
+ to_ids: params.toIds,
757
+ includeCorrelations: params.includeCorrelations,
758
+ last: params.last,
759
+ limit: params.limit
760
+ });
761
+ if (attributes.length === 0) {
762
+ return {
763
+ content: [{ type: "text", text: "No attributes found matching the search criteria." }]
764
+ };
765
+ }
766
+ const summary = attributes.map((a) => ({
767
+ id: a.id,
768
+ event_id: a.event_id,
769
+ type: a.type,
770
+ category: a.category,
771
+ value: a.value,
772
+ to_ids: a.to_ids,
773
+ comment: a.comment || void 0,
774
+ tags: (a.Tag || []).map((t) => t.name),
775
+ event_info: a.Event?.info,
776
+ correlations: a.RelatedAttribute ? a.RelatedAttribute.map((r) => ({
777
+ value: r.value,
778
+ type: r.type,
779
+ event_id: r.event_id
780
+ })) : void 0
781
+ }));
782
+ return {
783
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
784
+ };
785
+ } catch (err) {
786
+ return {
787
+ content: [
788
+ { type: "text", text: `Error searching attributes: ${err instanceof Error ? err.message : String(err)}` }
789
+ ],
790
+ isError: true
791
+ };
792
+ }
793
+ }
794
+ );
795
+ server2.tool(
796
+ "misp_add_attribute",
797
+ "Add an IOC/attribute to a MISP event",
798
+ {
799
+ eventId: z2.string().describe("Event ID to add the attribute to"),
800
+ type: z2.string().describe("Attribute type (ip-src, ip-dst, domain, md5, sha256, sha1, url, email-src, hostname, filename, etc.)"),
801
+ value: z2.string().describe("The IOC value"),
802
+ category: z2.string().optional().describe("Category (auto-determined from type if omitted)"),
803
+ toIds: z2.boolean().optional().describe("Flag for IDS export (default true for applicable types)"),
804
+ comment: z2.string().optional().describe("Context/notes about this IOC"),
805
+ distribution: z2.number().optional().describe("Distribution level (0-4)"),
806
+ tags: z2.array(z2.string()).optional().describe("Tags to apply to the attribute")
807
+ },
808
+ async (params) => {
809
+ try {
810
+ const attribute = await client2.addAttribute(params.eventId, {
811
+ type: params.type,
812
+ value: params.value,
813
+ category: params.category,
814
+ to_ids: params.toIds,
815
+ comment: params.comment,
816
+ distribution: params.distribution,
817
+ tags: params.tags
818
+ });
819
+ return {
820
+ content: [
821
+ {
822
+ type: "text",
823
+ text: JSON.stringify(
824
+ {
825
+ id: attribute.id,
826
+ event_id: attribute.event_id,
827
+ type: attribute.type,
828
+ category: attribute.category,
829
+ value: attribute.value,
830
+ to_ids: attribute.to_ids
831
+ },
832
+ null,
833
+ 2
834
+ )
835
+ }
836
+ ]
837
+ };
838
+ } catch (err) {
839
+ return {
840
+ content: [
841
+ { type: "text", text: `Error adding attribute: ${err instanceof Error ? err.message : String(err)}` }
842
+ ],
843
+ isError: true
844
+ };
845
+ }
846
+ }
847
+ );
848
+ server2.tool(
849
+ "misp_add_attributes_bulk",
850
+ "Add multiple attributes (IOCs) to a MISP event at once",
851
+ {
852
+ eventId: z2.string().describe("Event ID to add attributes to"),
853
+ attributes: z2.array(
854
+ z2.object({
855
+ type: z2.string().describe("Attribute type"),
856
+ value: z2.string().describe("IOC value"),
857
+ category: z2.string().optional().describe("Category"),
858
+ toIds: z2.boolean().optional().describe("IDS flag"),
859
+ comment: z2.string().optional().describe("Comment")
860
+ })
861
+ ).describe("Array of attributes to add")
862
+ },
863
+ async ({ eventId, attributes }) => {
864
+ try {
865
+ const results = [];
866
+ for (const attr of attributes) {
867
+ try {
868
+ const created = await client2.addAttribute(eventId, {
869
+ type: attr.type,
870
+ value: attr.value,
871
+ category: attr.category,
872
+ to_ids: attr.toIds,
873
+ comment: attr.comment
874
+ });
875
+ results.push({
876
+ value: attr.value,
877
+ type: attr.type,
878
+ id: created.id
879
+ });
880
+ } catch (err) {
881
+ results.push({
882
+ value: attr.value,
883
+ type: attr.type,
884
+ error: err instanceof Error ? err.message : String(err)
885
+ });
886
+ }
887
+ }
888
+ const succeeded = results.filter((r) => r.id);
889
+ const failed = results.filter((r) => r.error);
890
+ return {
891
+ content: [
892
+ {
893
+ type: "text",
894
+ text: JSON.stringify(
895
+ {
896
+ total: attributes.length,
897
+ succeeded: succeeded.length,
898
+ failed: failed.length,
899
+ results
900
+ },
901
+ null,
902
+ 2
903
+ )
904
+ }
905
+ ]
906
+ };
907
+ } catch (err) {
908
+ return {
909
+ content: [
910
+ { type: "text", text: `Error adding attributes: ${err instanceof Error ? err.message : String(err)}` }
911
+ ],
912
+ isError: true
913
+ };
914
+ }
915
+ }
916
+ );
917
+ server2.tool(
918
+ "misp_delete_attribute",
919
+ "Delete (soft or hard) an attribute from MISP",
920
+ {
921
+ attributeId: z2.string().describe("Attribute ID to delete"),
922
+ hard: z2.boolean().optional().describe("Hard delete (permanent) instead of soft delete")
923
+ },
924
+ async ({ attributeId, hard }) => {
925
+ try {
926
+ const result = await client2.deleteAttribute(attributeId, hard);
927
+ return {
928
+ content: [
929
+ { type: "text", text: result.message || `Attribute ${attributeId} deleted successfully.` }
930
+ ]
931
+ };
932
+ } catch (err) {
933
+ return {
934
+ content: [
935
+ { type: "text", text: `Error deleting attribute: ${err instanceof Error ? err.message : String(err)}` }
936
+ ],
937
+ isError: true
938
+ };
939
+ }
940
+ }
941
+ );
942
+ }
943
+
944
+ // src/tools/correlation.ts
945
+ import { z as z3 } from "zod";
946
+ function registerCorrelationTools(server2, client2) {
947
+ server2.tool(
948
+ "misp_correlate",
949
+ "Find correlations for a specific observable value across all MISP events",
950
+ {
951
+ value: z3.string().describe("Observable value to correlate (IP, domain, hash, etc.)")
952
+ },
953
+ async ({ value }) => {
954
+ try {
955
+ const attributes = await client2.searchAttributes({
956
+ value,
957
+ includeCorrelations: true
958
+ });
959
+ if (attributes.length === 0) {
960
+ return {
961
+ content: [{ type: "text", text: `No results found for "${value}" in MISP.` }]
962
+ };
963
+ }
964
+ const eventMap = /* @__PURE__ */ new Map();
965
+ for (const attr of attributes) {
966
+ const eid = attr.event_id;
967
+ if (!eventMap.has(eid)) {
968
+ eventMap.set(eid, {
969
+ event_id: eid,
970
+ event_info: attr.Event?.info || "Unknown",
971
+ attributes: []
972
+ });
973
+ }
974
+ eventMap.get(eid).attributes.push({
975
+ id: attr.id,
976
+ type: attr.type,
977
+ category: attr.category,
978
+ value: attr.value
979
+ });
980
+ }
981
+ const correlations = [];
982
+ for (const attr of attributes) {
983
+ if (attr.RelatedAttribute) {
984
+ for (const rel of attr.RelatedAttribute) {
985
+ correlations.push({
986
+ value: rel.value,
987
+ type: rel.type,
988
+ event_id: rel.event_id
989
+ });
990
+ }
991
+ }
992
+ }
993
+ const result = {
994
+ searched_value: value,
995
+ found_in_events: Array.from(eventMap.values()),
996
+ total_events: eventMap.size,
997
+ total_attributes: attributes.length,
998
+ correlations: correlations.length > 0 ? correlations : void 0
999
+ };
1000
+ return {
1001
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1002
+ };
1003
+ } catch (err) {
1004
+ return {
1005
+ content: [
1006
+ { type: "text", text: `Error correlating value: ${err instanceof Error ? err.message : String(err)}` }
1007
+ ],
1008
+ isError: true
1009
+ };
1010
+ }
1011
+ }
1012
+ );
1013
+ server2.tool(
1014
+ "misp_get_related_events",
1015
+ "Get events related to a specific event through shared attributes and correlations",
1016
+ {
1017
+ eventId: z3.string().describe("Event ID to find related events for")
1018
+ },
1019
+ async ({ eventId }) => {
1020
+ try {
1021
+ const event = await client2.getEvent(eventId);
1022
+ const eventAttributes = event.Attribute || [];
1023
+ if (eventAttributes.length === 0) {
1024
+ return {
1025
+ content: [{ type: "text", text: `Event ${eventId} has no attributes to correlate.` }]
1026
+ };
1027
+ }
1028
+ const relatedMap = /* @__PURE__ */ new Map();
1029
+ if (event.RelatedEvent && event.RelatedEvent.length > 0) {
1030
+ for (const rel of event.RelatedEvent) {
1031
+ relatedMap.set(rel.Event.id, {
1032
+ event_id: rel.Event.id,
1033
+ event_info: rel.Event.info,
1034
+ overlapping_iocs: [],
1035
+ correlation_count: 0
1036
+ });
1037
+ }
1038
+ }
1039
+ const valuesToSearch = eventAttributes.filter((a) => a.to_ids).slice(0, 20).map((a) => a.value);
1040
+ for (const value of valuesToSearch) {
1041
+ const matches = await client2.searchAttributes({
1042
+ value,
1043
+ includeCorrelations: true
1044
+ });
1045
+ for (const match of matches) {
1046
+ if (match.event_id !== eventId) {
1047
+ if (!relatedMap.has(match.event_id)) {
1048
+ relatedMap.set(match.event_id, {
1049
+ event_id: match.event_id,
1050
+ event_info: match.Event?.info || "Unknown",
1051
+ overlapping_iocs: [],
1052
+ correlation_count: 0
1053
+ });
1054
+ }
1055
+ const entry = relatedMap.get(match.event_id);
1056
+ if (!entry.overlapping_iocs.includes(value)) {
1057
+ entry.overlapping_iocs.push(value);
1058
+ }
1059
+ entry.correlation_count++;
1060
+ }
1061
+ }
1062
+ }
1063
+ const related = Array.from(relatedMap.values()).sort(
1064
+ (a, b) => b.correlation_count - a.correlation_count
1065
+ );
1066
+ return {
1067
+ content: [
1068
+ {
1069
+ type: "text",
1070
+ text: JSON.stringify(
1071
+ {
1072
+ event_id: eventId,
1073
+ event_info: event.info,
1074
+ related_events: related,
1075
+ total_related: related.length
1076
+ },
1077
+ null,
1078
+ 2
1079
+ )
1080
+ }
1081
+ ]
1082
+ };
1083
+ } catch (err) {
1084
+ return {
1085
+ content: [
1086
+ { type: "text", text: `Error finding related events: ${err instanceof Error ? err.message : String(err)}` }
1087
+ ],
1088
+ isError: true
1089
+ };
1090
+ }
1091
+ }
1092
+ );
1093
+ server2.tool(
1094
+ "misp_describe_types",
1095
+ "Get all available MISP attribute types and categories with their mappings",
1096
+ {},
1097
+ async () => {
1098
+ try {
1099
+ const types = await client2.describeTypes();
1100
+ return {
1101
+ content: [{ type: "text", text: JSON.stringify(types, null, 2) }]
1102
+ };
1103
+ } catch (err) {
1104
+ return {
1105
+ content: [
1106
+ { type: "text", text: `Error getting types: ${err instanceof Error ? err.message : String(err)}` }
1107
+ ],
1108
+ isError: true
1109
+ };
1110
+ }
1111
+ }
1112
+ );
1113
+ }
1114
+
1115
+ // src/tools/tags.ts
1116
+ import { z as z4 } from "zod";
1117
+ function registerTagTools(server2, client2) {
1118
+ server2.tool(
1119
+ "misp_list_tags",
1120
+ "List available MISP tags with usage statistics",
1121
+ {
1122
+ search: z4.string().optional().describe("Search filter for tag names"),
1123
+ limit: z4.number().optional().describe("Max results to return")
1124
+ },
1125
+ async ({ search, limit }) => {
1126
+ try {
1127
+ let tags = await client2.listTags(search);
1128
+ if (limit && limit > 0) {
1129
+ tags = tags.slice(0, limit);
1130
+ }
1131
+ if (tags.length === 0) {
1132
+ return {
1133
+ content: [{ type: "text", text: "No tags found." }]
1134
+ };
1135
+ }
1136
+ const summary = tags.map((t) => ({
1137
+ id: t.id,
1138
+ name: t.name,
1139
+ colour: t.colour,
1140
+ event_count: t.event_count,
1141
+ attribute_count: t.attribute_count
1142
+ }));
1143
+ return {
1144
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1145
+ };
1146
+ } catch (err) {
1147
+ return {
1148
+ content: [
1149
+ { type: "text", text: `Error listing tags: ${err instanceof Error ? err.message : String(err)}` }
1150
+ ],
1151
+ isError: true
1152
+ };
1153
+ }
1154
+ }
1155
+ );
1156
+ server2.tool(
1157
+ "misp_search_by_tag",
1158
+ "Search MISP events or attributes by tag (MITRE ATT&CK, TLP, custom tags)",
1159
+ {
1160
+ tag: z4.string().describe("Tag name to search for (e.g., tlp:white, mitre-attack:T1059)"),
1161
+ type: z4.enum(["event", "attribute"]).optional().describe("Search events or attributes (default: event)")
1162
+ },
1163
+ async ({ tag, type: searchType }) => {
1164
+ try {
1165
+ if (searchType === "attribute") {
1166
+ const attributes = await client2.searchAttributes({ tags: [tag] });
1167
+ if (attributes.length === 0) {
1168
+ return {
1169
+ content: [{ type: "text", text: `No attributes found with tag "${tag}".` }]
1170
+ };
1171
+ }
1172
+ const summary2 = attributes.map((a) => ({
1173
+ id: a.id,
1174
+ event_id: a.event_id,
1175
+ type: a.type,
1176
+ value: a.value,
1177
+ category: a.category,
1178
+ event_info: a.Event?.info
1179
+ }));
1180
+ return {
1181
+ content: [{ type: "text", text: JSON.stringify(summary2, null, 2) }]
1182
+ };
1183
+ }
1184
+ const events = await client2.searchEvents({ tags: [tag] });
1185
+ if (events.length === 0) {
1186
+ return {
1187
+ content: [{ type: "text", text: `No events found with tag "${tag}".` }]
1188
+ };
1189
+ }
1190
+ const summary = events.map((e) => ({
1191
+ id: e.id,
1192
+ info: e.info,
1193
+ date: e.date,
1194
+ threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(e.threat_level_id) || 0],
1195
+ org: e.Orgc?.name || "Unknown",
1196
+ tags: (e.Tag || []).map((t) => t.name)
1197
+ }));
1198
+ return {
1199
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1200
+ };
1201
+ } catch (err) {
1202
+ return {
1203
+ content: [
1204
+ { type: "text", text: `Error searching by tag: ${err instanceof Error ? err.message : String(err)}` }
1205
+ ],
1206
+ isError: true
1207
+ };
1208
+ }
1209
+ }
1210
+ );
1211
+ }
1212
+
1213
+ // src/tools/exports.ts
1214
+ import { z as z5 } from "zod";
1215
+ function registerExportTools(server2, client2) {
1216
+ server2.tool(
1217
+ "misp_export_iocs",
1218
+ "Export IOCs from MISP in various formats (CSV, STIX, Suricata, Snort, text, RPZ)",
1219
+ {
1220
+ format: z5.enum(["csv", "stix", "suricata", "snort", "text", "rpz"]).describe("Export format"),
1221
+ eventId: z5.string().optional().describe("Specific event ID (or all events if omitted)"),
1222
+ type: z5.string().optional().describe("Filter by attribute type"),
1223
+ tags: z5.array(z5.string()).optional().describe("Filter by tags"),
1224
+ last: z5.string().optional().describe("Relative time filter (e.g., 1d, 7d)")
1225
+ },
1226
+ async (params) => {
1227
+ try {
1228
+ const output = await client2.exportEvents({
1229
+ format: params.format,
1230
+ eventId: params.eventId,
1231
+ type: params.type,
1232
+ tags: params.tags,
1233
+ last: params.last
1234
+ });
1235
+ if (!output || output.trim().length === 0) {
1236
+ return {
1237
+ content: [
1238
+ { type: "text", text: `No IOCs found for the specified criteria in ${params.format} format.` }
1239
+ ]
1240
+ };
1241
+ }
1242
+ return {
1243
+ content: [{ type: "text", text: output }]
1244
+ };
1245
+ } catch (err) {
1246
+ return {
1247
+ content: [
1248
+ { type: "text", text: `Error exporting IOCs: ${err instanceof Error ? err.message : String(err)}` }
1249
+ ],
1250
+ isError: true
1251
+ };
1252
+ }
1253
+ }
1254
+ );
1255
+ server2.tool(
1256
+ "misp_export_hashes",
1257
+ "Export file hashes from MISP for HIDS integration",
1258
+ {
1259
+ format: z5.enum(["md5", "sha1", "sha256"]).describe("Hash format to export"),
1260
+ last: z5.string().optional().describe("Relative time filter (e.g., 1d, 7d)"),
1261
+ tags: z5.array(z5.string()).optional().describe("Filter by tags")
1262
+ },
1263
+ async (params) => {
1264
+ try {
1265
+ const output = await client2.exportHashes({
1266
+ format: params.format,
1267
+ last: params.last,
1268
+ tags: params.tags
1269
+ });
1270
+ if (!output || output.trim().length === 0) {
1271
+ return {
1272
+ content: [
1273
+ { type: "text", text: `No ${params.format} hashes found for the specified criteria.` }
1274
+ ]
1275
+ };
1276
+ }
1277
+ return {
1278
+ content: [{ type: "text", text: output }]
1279
+ };
1280
+ } catch (err) {
1281
+ return {
1282
+ content: [
1283
+ { type: "text", text: `Error exporting hashes: ${err instanceof Error ? err.message : String(err)}` }
1284
+ ],
1285
+ isError: true
1286
+ };
1287
+ }
1288
+ }
1289
+ );
1290
+ }
1291
+
1292
+ // src/tools/sightings.ts
1293
+ import { z as z6 } from "zod";
1294
+ function registerSightingTools(server2, client2) {
1295
+ server2.tool(
1296
+ "misp_add_sighting",
1297
+ "Report a sighting of an IOC (confirms it was observed in the wild, marks as false positive, or sets expiration)",
1298
+ {
1299
+ attributeId: z6.string().optional().describe("Attribute ID to sight (use this or value)"),
1300
+ value: z6.string().optional().describe("Attribute value to sight (use this or attributeId)"),
1301
+ type: z6.union([z6.literal(0), z6.literal(1), z6.literal(2)]).describe("0=Sighting (seen in the wild), 1=False positive, 2=Expiration"),
1302
+ source: z6.string().optional().describe("Source of the sighting (e.g., organization name, sensor ID)"),
1303
+ timestamp: z6.string().optional().describe("Timestamp of the sighting (Unix timestamp)")
1304
+ },
1305
+ async (params) => {
1306
+ try {
1307
+ if (!params.attributeId && !params.value) {
1308
+ return {
1309
+ content: [
1310
+ { type: "text", text: "Either attributeId or value must be provided." }
1311
+ ],
1312
+ isError: true
1313
+ };
1314
+ }
1315
+ const sighting = await client2.addSighting({
1316
+ attributeId: params.attributeId,
1317
+ value: params.value,
1318
+ type: params.type,
1319
+ source: params.source,
1320
+ timestamp: params.timestamp
1321
+ });
1322
+ const typeLabels = ["Sighting", "False positive", "Expiration"];
1323
+ return {
1324
+ content: [
1325
+ {
1326
+ type: "text",
1327
+ text: JSON.stringify(
1328
+ {
1329
+ id: sighting.id,
1330
+ type: typeLabels[params.type],
1331
+ attribute_id: sighting.attribute_id,
1332
+ event_id: sighting.event_id,
1333
+ source: sighting.source,
1334
+ date_sighting: sighting.date_sighting
1335
+ },
1336
+ null,
1337
+ 2
1338
+ )
1339
+ }
1340
+ ]
1341
+ };
1342
+ } catch (err) {
1343
+ return {
1344
+ content: [
1345
+ { type: "text", text: `Error adding sighting: ${err instanceof Error ? err.message : String(err)}` }
1346
+ ],
1347
+ isError: true
1348
+ };
1349
+ }
1350
+ }
1351
+ );
1352
+ }
1353
+
1354
+ // src/tools/warninglists.ts
1355
+ import { z as z7 } from "zod";
1356
+ function registerWarninglistTools(server2, client2) {
1357
+ server2.tool(
1358
+ "misp_check_warninglists",
1359
+ "Check if an observable value appears on any MISP warninglists (known benign/false positive lists)",
1360
+ {
1361
+ value: z7.string().describe("Value to check against warninglists (IP, domain, hash, etc.)")
1362
+ },
1363
+ async ({ value }) => {
1364
+ try {
1365
+ const results = await client2.checkWarninglists(value);
1366
+ const matches = results[value] || [];
1367
+ if (matches.length === 0) {
1368
+ return {
1369
+ content: [
1370
+ {
1371
+ type: "text",
1372
+ text: `"${value}" does not appear on any warninglists. This does not confirm it is malicious, but it is not a known benign indicator.`
1373
+ }
1374
+ ]
1375
+ };
1376
+ }
1377
+ const summary = matches.map((w) => ({
1378
+ name: w.name,
1379
+ category: w.category,
1380
+ description: w.description,
1381
+ type: w.type
1382
+ }));
1383
+ return {
1384
+ content: [
1385
+ {
1386
+ type: "text",
1387
+ text: JSON.stringify(
1388
+ {
1389
+ value,
1390
+ on_warninglists: true,
1391
+ match_count: matches.length,
1392
+ warninglists: summary,
1393
+ note: "This value appears on known benign/false positive lists. Exercise caution before treating it as malicious."
1394
+ },
1395
+ null,
1396
+ 2
1397
+ )
1398
+ }
1399
+ ]
1400
+ };
1401
+ } catch (err) {
1402
+ return {
1403
+ content: [
1404
+ { type: "text", text: `Error checking warninglists: ${err instanceof Error ? err.message : String(err)}` }
1405
+ ],
1406
+ isError: true
1407
+ };
1408
+ }
1409
+ }
1410
+ );
1411
+ }
1412
+
1413
+ // src/tools/objects.ts
1414
+ import { z as z8 } from "zod";
1415
+ function registerObjectTools(server2, client2) {
1416
+ server2.tool(
1417
+ "misp_list_object_templates",
1418
+ "List available MISP object templates (file, domain-ip, email, network-connection, etc.)",
1419
+ {
1420
+ search: z8.string().optional().describe("Filter templates by name"),
1421
+ limit: z8.number().optional().describe("Max results (default 50)")
1422
+ },
1423
+ async ({ search, limit }) => {
1424
+ try {
1425
+ const templates = await client2.listObjectTemplates();
1426
+ let filtered = templates;
1427
+ if (search) {
1428
+ const q = search.toLowerCase();
1429
+ filtered = templates.filter(
1430
+ (t) => t.name.toLowerCase().includes(q) || t.description.toLowerCase().includes(q)
1431
+ );
1432
+ }
1433
+ if (limit && limit > 0) {
1434
+ filtered = filtered.slice(0, limit);
1435
+ }
1436
+ if (filtered.length === 0) {
1437
+ return {
1438
+ content: [{ type: "text", text: "No object templates found." }]
1439
+ };
1440
+ }
1441
+ const summary = filtered.map((t) => ({
1442
+ id: t.id,
1443
+ uuid: t.uuid,
1444
+ name: t.name,
1445
+ description: t.description,
1446
+ version: t.version,
1447
+ meta_category: t.meta_category
1448
+ }));
1449
+ return {
1450
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1451
+ };
1452
+ } catch (err) {
1453
+ return {
1454
+ content: [
1455
+ {
1456
+ type: "text",
1457
+ text: `Error listing object templates: ${err instanceof Error ? err.message : String(err)}`
1458
+ }
1459
+ ],
1460
+ isError: true
1461
+ };
1462
+ }
1463
+ }
1464
+ );
1465
+ server2.tool(
1466
+ "misp_get_object_template",
1467
+ "Get details of a specific MISP object template including required and optional attributes",
1468
+ {
1469
+ templateId: z8.string().describe("Object template ID or UUID")
1470
+ },
1471
+ async ({ templateId }) => {
1472
+ try {
1473
+ const template = await client2.getObjectTemplate(templateId);
1474
+ return {
1475
+ content: [{ type: "text", text: JSON.stringify(template, null, 2) }]
1476
+ };
1477
+ } catch (err) {
1478
+ return {
1479
+ content: [
1480
+ {
1481
+ type: "text",
1482
+ text: `Error getting object template: ${err instanceof Error ? err.message : String(err)}`
1483
+ }
1484
+ ],
1485
+ isError: true
1486
+ };
1487
+ }
1488
+ }
1489
+ );
1490
+ server2.tool(
1491
+ "misp_add_object",
1492
+ "Add a MISP object (structured group of attributes) to an event",
1493
+ {
1494
+ eventId: z8.string().describe("Event ID to add the object to"),
1495
+ templateName: z8.string().describe(
1496
+ "Object template name (e.g., file, domain-ip, email, network-connection, url)"
1497
+ ),
1498
+ attributes: z8.array(
1499
+ z8.object({
1500
+ object_relation: z8.string().describe(
1501
+ "Attribute relation within the object (e.g., filename, md5, ip, domain)"
1502
+ ),
1503
+ type: z8.string().describe("Attribute type (ip-dst, domain, md5, filename, etc.)"),
1504
+ value: z8.string().describe("Attribute value"),
1505
+ to_ids: z8.boolean().optional().describe("Flag for IDS export"),
1506
+ comment: z8.string().optional().describe("Comment")
1507
+ })
1508
+ ).describe("Attributes to include in the object"),
1509
+ comment: z8.string().optional().describe("Object-level comment"),
1510
+ distribution: z8.number().optional().describe("Distribution level (0-4)")
1511
+ },
1512
+ async ({ eventId, templateName, attributes, comment, distribution }) => {
1513
+ try {
1514
+ const result = await client2.addObject(eventId, {
1515
+ name: templateName,
1516
+ attributes,
1517
+ comment,
1518
+ distribution
1519
+ });
1520
+ return {
1521
+ content: [
1522
+ {
1523
+ type: "text",
1524
+ text: JSON.stringify(
1525
+ {
1526
+ id: result.id,
1527
+ name: result.name,
1528
+ event_id: result.event_id,
1529
+ meta_category: result.meta_category,
1530
+ description: result.description,
1531
+ attributes: (result.Attribute || []).map((a) => ({
1532
+ type: a.type,
1533
+ object_relation: a.object_relation,
1534
+ value: a.value
1535
+ }))
1536
+ },
1537
+ null,
1538
+ 2
1539
+ )
1540
+ }
1541
+ ]
1542
+ };
1543
+ } catch (err) {
1544
+ return {
1545
+ content: [
1546
+ {
1547
+ type: "text",
1548
+ text: `Error adding object: ${err instanceof Error ? err.message : String(err)}`
1549
+ }
1550
+ ],
1551
+ isError: true
1552
+ };
1553
+ }
1554
+ }
1555
+ );
1556
+ server2.tool(
1557
+ "misp_delete_object",
1558
+ "Delete a MISP object from an event",
1559
+ {
1560
+ objectId: z8.string().describe("Object ID to delete"),
1561
+ hard: z8.boolean().optional().describe("Hard delete (permanent) instead of soft delete")
1562
+ },
1563
+ async ({ objectId, hard }) => {
1564
+ try {
1565
+ const result = await client2.deleteObject(objectId, hard);
1566
+ return {
1567
+ content: [
1568
+ {
1569
+ type: "text",
1570
+ text: result.message || `Object ${objectId} deleted successfully.`
1571
+ }
1572
+ ]
1573
+ };
1574
+ } catch (err) {
1575
+ return {
1576
+ content: [
1577
+ {
1578
+ type: "text",
1579
+ text: `Error deleting object: ${err instanceof Error ? err.message : String(err)}`
1580
+ }
1581
+ ],
1582
+ isError: true
1583
+ };
1584
+ }
1585
+ }
1586
+ );
1587
+ }
1588
+
1589
+ // src/tools/galaxies.ts
1590
+ import { z as z9 } from "zod";
1591
+ function registerGalaxyTools(server2, client2) {
1592
+ server2.tool(
1593
+ "misp_list_galaxies",
1594
+ "List available MISP galaxies (MITRE ATT&CK, threat actors, malware families, tools, etc.)",
1595
+ {
1596
+ search: z9.string().optional().describe("Filter galaxies by name or type"),
1597
+ namespace: z9.string().optional().describe(
1598
+ "Filter by namespace (e.g., mitre-attack-pattern, mitre-intrusion-set, mitre-malware)"
1599
+ )
1600
+ },
1601
+ async ({ search, namespace }) => {
1602
+ try {
1603
+ const galaxies = await client2.listGalaxies();
1604
+ let filtered = galaxies;
1605
+ if (search) {
1606
+ const q = search.toLowerCase();
1607
+ filtered = filtered.filter(
1608
+ (g) => g.name.toLowerCase().includes(q) || g.type.toLowerCase().includes(q) || g.description.toLowerCase().includes(q)
1609
+ );
1610
+ }
1611
+ if (namespace) {
1612
+ const ns = namespace.toLowerCase();
1613
+ filtered = filtered.filter(
1614
+ (g) => g.type.toLowerCase().includes(ns)
1615
+ );
1616
+ }
1617
+ if (filtered.length === 0) {
1618
+ return {
1619
+ content: [{ type: "text", text: "No galaxies found matching the criteria." }]
1620
+ };
1621
+ }
1622
+ const summary = filtered.map((g) => ({
1623
+ id: g.id,
1624
+ name: g.name,
1625
+ type: g.type,
1626
+ description: g.description.length > 150 ? g.description.slice(0, 150) + "..." : g.description
1627
+ }));
1628
+ return {
1629
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1630
+ };
1631
+ } catch (err) {
1632
+ return {
1633
+ content: [
1634
+ {
1635
+ type: "text",
1636
+ text: `Error listing galaxies: ${err instanceof Error ? err.message : String(err)}`
1637
+ }
1638
+ ],
1639
+ isError: true
1640
+ };
1641
+ }
1642
+ }
1643
+ );
1644
+ server2.tool(
1645
+ "misp_get_galaxy",
1646
+ "Get a specific galaxy with its clusters (e.g., MITRE ATT&CK techniques, threat actor profiles)",
1647
+ {
1648
+ galaxyId: z9.string().describe("Galaxy ID to retrieve")
1649
+ },
1650
+ async ({ galaxyId }) => {
1651
+ try {
1652
+ const galaxy = await client2.getGalaxy(galaxyId);
1653
+ const result = {
1654
+ id: galaxy.id,
1655
+ uuid: galaxy.uuid,
1656
+ name: galaxy.name,
1657
+ type: galaxy.type,
1658
+ description: galaxy.description,
1659
+ clusters: (galaxy.GalaxyCluster || []).map((c) => ({
1660
+ id: c.id,
1661
+ value: c.value,
1662
+ description: c.description && c.description.length > 200 ? c.description.slice(0, 200) + "..." : c.description,
1663
+ tag_name: c.tag_name
1664
+ })),
1665
+ cluster_count: (galaxy.GalaxyCluster || []).length
1666
+ };
1667
+ return {
1668
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
1669
+ };
1670
+ } catch (err) {
1671
+ return {
1672
+ content: [
1673
+ {
1674
+ type: "text",
1675
+ text: `Error getting galaxy: ${err instanceof Error ? err.message : String(err)}`
1676
+ }
1677
+ ],
1678
+ isError: true
1679
+ };
1680
+ }
1681
+ }
1682
+ );
1683
+ server2.tool(
1684
+ "misp_search_galaxy_clusters",
1685
+ "Search galaxy clusters by keyword (find specific MITRE ATT&CK techniques, threat actors, malware, etc.)",
1686
+ {
1687
+ search: z9.string().describe(
1688
+ "Search term (e.g., 'phishing', 'APT28', 'ransomware', 'T1566')"
1689
+ ),
1690
+ galaxyType: z9.string().optional().describe(
1691
+ "Limit to a specific galaxy type (e.g., mitre-attack-pattern, mitre-intrusion-set)"
1692
+ )
1693
+ },
1694
+ async ({ search, galaxyType }) => {
1695
+ try {
1696
+ const results = await client2.searchGalaxyClusters(search, galaxyType);
1697
+ if (results.length === 0) {
1698
+ return {
1699
+ content: [
1700
+ {
1701
+ type: "text",
1702
+ text: `No galaxy clusters found matching "${search}".`
1703
+ }
1704
+ ]
1705
+ };
1706
+ }
1707
+ const summary = results.map((c) => ({
1708
+ id: c.id,
1709
+ galaxy_id: c.galaxy_id,
1710
+ value: c.value,
1711
+ description: c.description && c.description.length > 200 ? c.description.slice(0, 200) + "..." : c.description,
1712
+ tag_name: c.tag_name,
1713
+ type: c.type
1714
+ }));
1715
+ return {
1716
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1717
+ };
1718
+ } catch (err) {
1719
+ return {
1720
+ content: [
1721
+ {
1722
+ type: "text",
1723
+ text: `Error searching galaxy clusters: ${err instanceof Error ? err.message : String(err)}`
1724
+ }
1725
+ ],
1726
+ isError: true
1727
+ };
1728
+ }
1729
+ }
1730
+ );
1731
+ server2.tool(
1732
+ "misp_attach_galaxy_cluster",
1733
+ "Attach a galaxy cluster (MITRE ATT&CK technique, threat actor, etc.) to an event or attribute",
1734
+ {
1735
+ targetType: z9.enum(["event", "attribute"]).describe("Attach to an event or attribute"),
1736
+ targetId: z9.string().describe("Event ID or attribute ID"),
1737
+ galaxyClusterId: z9.string().describe("Galaxy cluster ID to attach")
1738
+ },
1739
+ async ({ targetType, targetId, galaxyClusterId }) => {
1740
+ try {
1741
+ await client2.attachGalaxyCluster(targetType, targetId, galaxyClusterId);
1742
+ return {
1743
+ content: [
1744
+ {
1745
+ type: "text",
1746
+ text: `Galaxy cluster ${galaxyClusterId} attached to ${targetType} ${targetId}.`
1747
+ }
1748
+ ]
1749
+ };
1750
+ } catch (err) {
1751
+ return {
1752
+ content: [
1753
+ {
1754
+ type: "text",
1755
+ text: `Error attaching galaxy cluster: ${err instanceof Error ? err.message : String(err)}`
1756
+ }
1757
+ ],
1758
+ isError: true
1759
+ };
1760
+ }
1761
+ }
1762
+ );
1763
+ }
1764
+
1765
+ // src/tools/feeds.ts
1766
+ import { z as z10 } from "zod";
1767
+ function registerFeedTools(server2, client2) {
1768
+ server2.tool(
1769
+ "misp_list_feeds",
1770
+ "List configured MISP feeds (threat intel sources, IOC feeds, etc.)",
1771
+ {
1772
+ enabled: z10.boolean().optional().describe("Filter by enabled/disabled status")
1773
+ },
1774
+ async ({ enabled }) => {
1775
+ try {
1776
+ let feeds = await client2.listFeeds();
1777
+ if (enabled !== void 0) {
1778
+ feeds = feeds.filter((f) => f.enabled === enabled);
1779
+ }
1780
+ if (feeds.length === 0) {
1781
+ return {
1782
+ content: [{ type: "text", text: "No feeds found." }]
1783
+ };
1784
+ }
1785
+ const summary = feeds.map((f) => ({
1786
+ id: f.id,
1787
+ name: f.name,
1788
+ provider: f.provider,
1789
+ url: f.url,
1790
+ enabled: f.enabled,
1791
+ source_format: f.source_format,
1792
+ distribution: f.distribution,
1793
+ event_id: f.event_id,
1794
+ caching_enabled: f.caching_enabled
1795
+ }));
1796
+ return {
1797
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1798
+ };
1799
+ } catch (err) {
1800
+ return {
1801
+ content: [
1802
+ {
1803
+ type: "text",
1804
+ text: `Error listing feeds: ${err instanceof Error ? err.message : String(err)}`
1805
+ }
1806
+ ],
1807
+ isError: true
1808
+ };
1809
+ }
1810
+ }
1811
+ );
1812
+ server2.tool(
1813
+ "misp_toggle_feed",
1814
+ "Enable or disable a MISP feed",
1815
+ {
1816
+ feedId: z10.string().describe("Feed ID"),
1817
+ enable: z10.boolean().describe("true to enable, false to disable")
1818
+ },
1819
+ async ({ feedId, enable }) => {
1820
+ try {
1821
+ await client2.toggleFeed(feedId, enable);
1822
+ return {
1823
+ content: [
1824
+ {
1825
+ type: "text",
1826
+ text: `Feed ${feedId} ${enable ? "enabled" : "disabled"} successfully.`
1827
+ }
1828
+ ]
1829
+ };
1830
+ } catch (err) {
1831
+ return {
1832
+ content: [
1833
+ {
1834
+ type: "text",
1835
+ text: `Error toggling feed: ${err instanceof Error ? err.message : String(err)}`
1836
+ }
1837
+ ],
1838
+ isError: true
1839
+ };
1840
+ }
1841
+ }
1842
+ );
1843
+ server2.tool(
1844
+ "misp_fetch_feed",
1845
+ "Trigger a fetch/pull of data from a specific MISP feed",
1846
+ {
1847
+ feedId: z10.string().describe("Feed ID to fetch")
1848
+ },
1849
+ async ({ feedId }) => {
1850
+ try {
1851
+ const result = await client2.fetchFeed(feedId);
1852
+ return {
1853
+ content: [
1854
+ {
1855
+ type: "text",
1856
+ text: result.message || `Feed ${feedId} fetch initiated.`
1857
+ }
1858
+ ]
1859
+ };
1860
+ } catch (err) {
1861
+ return {
1862
+ content: [
1863
+ {
1864
+ type: "text",
1865
+ text: `Error fetching feed: ${err instanceof Error ? err.message : String(err)}`
1866
+ }
1867
+ ],
1868
+ isError: true
1869
+ };
1870
+ }
1871
+ }
1872
+ );
1873
+ server2.tool(
1874
+ "misp_cache_feed",
1875
+ "Cache feed data locally for correlation without creating events",
1876
+ {
1877
+ feedId: z10.string().describe("Feed ID to cache")
1878
+ },
1879
+ async ({ feedId }) => {
1880
+ try {
1881
+ const result = await client2.cacheFeed(feedId);
1882
+ return {
1883
+ content: [
1884
+ {
1885
+ type: "text",
1886
+ text: result.message || `Feed ${feedId} cache initiated.`
1887
+ }
1888
+ ]
1889
+ };
1890
+ } catch (err) {
1891
+ return {
1892
+ content: [
1893
+ {
1894
+ type: "text",
1895
+ text: `Error caching feed: ${err instanceof Error ? err.message : String(err)}`
1896
+ }
1897
+ ],
1898
+ isError: true
1899
+ };
1900
+ }
1901
+ }
1902
+ );
1903
+ }
1904
+
1905
+ // src/tools/organisations.ts
1906
+ import { z as z11 } from "zod";
1907
+ function registerOrganisationTools(server2, client2) {
1908
+ server2.tool(
1909
+ "misp_list_organisations",
1910
+ "List MISP organisations (local and remote sharing partners)",
1911
+ {
1912
+ scope: z11.enum(["local", "external", "all"]).optional().describe("Filter by local, external, or all organisations")
1913
+ },
1914
+ async ({ scope }) => {
1915
+ try {
1916
+ const orgs = await client2.listOrganisations(scope || "all");
1917
+ if (orgs.length === 0) {
1918
+ return {
1919
+ content: [{ type: "text", text: "No organisations found." }]
1920
+ };
1921
+ }
1922
+ const summary = orgs.map((o) => ({
1923
+ id: o.id,
1924
+ name: o.name,
1925
+ uuid: o.uuid,
1926
+ description: o.description,
1927
+ nationality: o.nationality,
1928
+ sector: o.sector,
1929
+ type: o.type,
1930
+ local: o.local
1931
+ }));
1932
+ return {
1933
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
1934
+ };
1935
+ } catch (err) {
1936
+ return {
1937
+ content: [
1938
+ {
1939
+ type: "text",
1940
+ text: `Error listing organisations: ${err instanceof Error ? err.message : String(err)}`
1941
+ }
1942
+ ],
1943
+ isError: true
1944
+ };
1945
+ }
1946
+ }
1947
+ );
1948
+ server2.tool(
1949
+ "misp_get_organisation",
1950
+ "Get details of a specific MISP organisation",
1951
+ {
1952
+ orgId: z11.string().describe("Organisation ID")
1953
+ },
1954
+ async ({ orgId }) => {
1955
+ try {
1956
+ const org = await client2.getOrganisation(orgId);
1957
+ return {
1958
+ content: [{ type: "text", text: JSON.stringify(org, null, 2) }]
1959
+ };
1960
+ } catch (err) {
1961
+ return {
1962
+ content: [
1963
+ {
1964
+ type: "text",
1965
+ text: `Error getting organisation: ${err instanceof Error ? err.message : String(err)}`
1966
+ }
1967
+ ],
1968
+ isError: true
1969
+ };
1970
+ }
1971
+ }
1972
+ );
1973
+ }
1974
+
1975
+ // src/tools/servers.ts
1976
+ import { z as z12 } from "zod";
1977
+ function registerServerTools(server2, client2) {
1978
+ server2.tool(
1979
+ "misp_server_status",
1980
+ "Get MISP server version, status, and diagnostic information",
1981
+ {},
1982
+ async () => {
1983
+ try {
1984
+ const version = await client2.getVersion();
1985
+ const settings = await client2.getServerSettings();
1986
+ return {
1987
+ content: [
1988
+ {
1989
+ type: "text",
1990
+ text: JSON.stringify(
1991
+ {
1992
+ version: version.version,
1993
+ pymisp_recommended: version.pymisp_recommended_version,
1994
+ permissions: {
1995
+ sync: version.perm_sync,
1996
+ sighting: version.perm_sighting,
1997
+ galaxy_editor: version.perm_galaxy_editor,
1998
+ analyst_data: version.perm_analyst_data
1999
+ },
2000
+ diagnostics: settings.diagnostics
2001
+ },
2002
+ null,
2003
+ 2
2004
+ )
2005
+ }
2006
+ ]
2007
+ };
2008
+ } catch (err) {
2009
+ return {
2010
+ content: [
2011
+ {
2012
+ type: "text",
2013
+ text: `Error getting server status: ${err instanceof Error ? err.message : String(err)}`
2014
+ }
2015
+ ],
2016
+ isError: true
2017
+ };
2018
+ }
2019
+ }
2020
+ );
2021
+ server2.tool(
2022
+ "misp_list_sharing_groups",
2023
+ "List MISP sharing groups for controlled event distribution",
2024
+ {},
2025
+ async () => {
2026
+ try {
2027
+ const groups = await client2.listSharingGroups();
2028
+ if (groups.length === 0) {
2029
+ return {
2030
+ content: [
2031
+ {
2032
+ type: "text",
2033
+ text: "No sharing groups configured."
2034
+ }
2035
+ ]
2036
+ };
2037
+ }
2038
+ const summary = groups.map((g) => ({
2039
+ id: g.id,
2040
+ name: g.name,
2041
+ description: g.description,
2042
+ uuid: g.uuid,
2043
+ releasability: g.releasability,
2044
+ active: g.active,
2045
+ org_count: g.org_count
2046
+ }));
2047
+ return {
2048
+ content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
2049
+ };
2050
+ } catch (err) {
2051
+ return {
2052
+ content: [
2053
+ {
2054
+ type: "text",
2055
+ text: `Error listing sharing groups: ${err instanceof Error ? err.message : String(err)}`
2056
+ }
2057
+ ],
2058
+ isError: true
2059
+ };
2060
+ }
2061
+ }
2062
+ );
2063
+ server2.tool(
2064
+ "misp_delete_event",
2065
+ "Delete a MISP event (requires appropriate permissions)",
2066
+ {
2067
+ eventId: z12.string().describe("Event ID to delete")
2068
+ },
2069
+ async ({ eventId }) => {
2070
+ try {
2071
+ const result = await client2.deleteEvent(eventId);
2072
+ return {
2073
+ content: [
2074
+ {
2075
+ type: "text",
2076
+ text: result.message || `Event ${eventId} deleted.`
2077
+ }
2078
+ ]
2079
+ };
2080
+ } catch (err) {
2081
+ return {
2082
+ content: [
2083
+ {
2084
+ type: "text",
2085
+ text: `Error deleting event: ${err instanceof Error ? err.message : String(err)}`
2086
+ }
2087
+ ],
2088
+ isError: true
2089
+ };
2090
+ }
2091
+ }
2092
+ );
2093
+ }
2094
+
2095
+ // src/resources.ts
2096
+ function registerResources(server2, client2) {
2097
+ server2.resource(
2098
+ "types",
2099
+ "misp://types",
2100
+ {
2101
+ description: "All supported MISP attribute types and categories with their mappings",
2102
+ mimeType: "application/json"
2103
+ },
2104
+ async () => {
2105
+ const types = await client2.describeTypes();
2106
+ const summary = {
2107
+ types: types.types,
2108
+ categories: types.categories,
2109
+ category_type_mappings: types.category_type_mappings,
2110
+ type_defaults: Object.entries(types.sane_defaults).map(([type, info]) => ({
2111
+ type,
2112
+ default_category: info.default_category,
2113
+ to_ids: info.to_ids === 1
2114
+ }))
2115
+ };
2116
+ return {
2117
+ contents: [
2118
+ {
2119
+ uri: "misp://types",
2120
+ mimeType: "application/json",
2121
+ text: JSON.stringify(summary, null, 2)
2122
+ }
2123
+ ]
2124
+ };
2125
+ }
2126
+ );
2127
+ server2.resource(
2128
+ "statistics",
2129
+ "misp://statistics",
2130
+ {
2131
+ description: "MISP instance statistics (event count, attribute count, organization info)",
2132
+ mimeType: "application/json"
2133
+ },
2134
+ async () => {
2135
+ const events = await client2.searchEvents({ limit: 1 });
2136
+ const types = await client2.describeTypes();
2137
+ const stats = {
2138
+ available_types: types.types.length,
2139
+ available_categories: types.categories.length,
2140
+ sample_event_count: events.length,
2141
+ note: "For full statistics, use misp_search_events with various filters"
2142
+ };
2143
+ return {
2144
+ contents: [
2145
+ {
2146
+ uri: "misp://statistics",
2147
+ mimeType: "application/json",
2148
+ text: JSON.stringify(stats, null, 2)
2149
+ }
2150
+ ]
2151
+ };
2152
+ }
2153
+ );
2154
+ server2.resource(
2155
+ "taxonomies",
2156
+ "misp://taxonomies",
2157
+ {
2158
+ description: "Available MISP taxonomies (TLP, MITRE ATT&CK, etc.)",
2159
+ mimeType: "application/json"
2160
+ },
2161
+ async () => {
2162
+ const taxonomies = await client2.listTaxonomies();
2163
+ const summary = taxonomies.map((t) => ({
2164
+ namespace: t.namespace,
2165
+ description: t.description,
2166
+ version: t.version,
2167
+ enabled: t.enabled
2168
+ }));
2169
+ return {
2170
+ contents: [
2171
+ {
2172
+ uri: "misp://taxonomies",
2173
+ mimeType: "application/json",
2174
+ text: JSON.stringify(summary, null, 2)
2175
+ }
2176
+ ]
2177
+ };
2178
+ }
2179
+ );
2180
+ }
2181
+
2182
+ // src/prompts.ts
2183
+ import { z as z13 } from "zod";
2184
+ function registerPrompts(server2) {
2185
+ server2.prompt(
2186
+ "investigate-ioc",
2187
+ "Deep investigation of an IOC across MISP - searches for the indicator, finds correlations, checks warninglists, and summarizes threat context",
2188
+ {
2189
+ ioc: z13.string().describe("The IOC value to investigate (IP, domain, hash, URL, email, etc.)"),
2190
+ iocType: z13.string().optional().describe("IOC type hint (ip-src, domain, md5, sha256, url, etc.)")
2191
+ },
2192
+ ({ ioc, iocType }) => {
2193
+ const typeHint = iocType ? `The IOC type is "${iocType}".` : "Determine the IOC type from the value format.";
2194
+ return {
2195
+ messages: [
2196
+ {
2197
+ role: "user",
2198
+ content: {
2199
+ type: "text",
2200
+ text: `Investigate the following IOC in MISP: "${ioc}"
2201
+
2202
+ ${typeHint}
2203
+
2204
+ Follow these steps:
2205
+ 1. Use misp_search_attributes to search for this IOC value across all events. If you know the type, filter by it.
2206
+ 2. Use misp_correlate to find all correlations for this value across events.
2207
+ 3. Use misp_check_warninglists to check if this value appears on any known benign/false positive lists.
2208
+ 4. For each event found, note the threat level, tags (especially TLP and MITRE ATT&CK), and related IOCs.
2209
+ 5. If the IOC appears in multiple events, use misp_get_related_events on the most relevant event to discover additional related intelligence.
2210
+
2211
+ Provide a structured summary including:
2212
+ - Whether the IOC was found in MISP and in how many events
2213
+ - Threat level assessment based on event metadata
2214
+ - Related IOCs and correlations discovered
2215
+ - Whether it appears on any warninglists (potential false positive)
2216
+ - MITRE ATT&CK techniques associated with this IOC
2217
+ - Recommended next steps for the analyst`
2218
+ }
2219
+ }
2220
+ ]
2221
+ };
2222
+ }
2223
+ );
2224
+ server2.prompt(
2225
+ "create-incident-event",
2226
+ "Guided workflow for creating a MISP event from an incident, including adding attributes, tagging, and publishing",
2227
+ {
2228
+ description: z13.string().describe("Description of the incident"),
2229
+ iocs: z13.string().optional().describe("Comma-separated list of IOCs to add (e.g., '192.168.1.1,evil.com,abc123hash')")
2230
+ },
2231
+ ({ description, iocs }) => {
2232
+ const iocList = iocs ? `
2233
+ The following IOCs should be added: ${iocs}` : "\nAsk the analyst for any IOCs (IP addresses, domains, file hashes, URLs) associated with this incident.";
2234
+ return {
2235
+ messages: [
2236
+ {
2237
+ role: "user",
2238
+ content: {
2239
+ type: "text",
2240
+ text: `Create a MISP event for the following incident:
2241
+
2242
+ "${description}"
2243
+ ${iocList}
2244
+
2245
+ Follow these steps:
2246
+ 1. Use misp_create_event with:
2247
+ - An informative title based on the incident description
2248
+ - Appropriate threat level (1=High for active compromise, 2=Medium for suspicious activity, 3=Low for informational)
2249
+ - Analysis status: 0 (Initial)
2250
+ - Distribution: 0 (Organization only) to start - can be broadened later
2251
+
2252
+ 2. For each IOC:
2253
+ - Determine the correct attribute type (ip-src, ip-dst, domain, md5, sha256, url, etc.)
2254
+ - Use misp_add_attribute (or misp_add_attributes_bulk for multiple) to add them
2255
+ - Use misp_check_warninglists to verify none are known false positives
2256
+
2257
+ 3. Add appropriate tags using misp_tag_event:
2258
+ - TLP tag (tlp:white, tlp:green, tlp:amber, tlp:red)
2259
+ - Relevant MITRE ATT&CK technique tags if applicable
2260
+ - Any organization-specific tags
2261
+
2262
+ 4. Summarize what was created:
2263
+ - Event ID and title
2264
+ - Number of attributes added
2265
+ - Tags applied
2266
+ - Ask if the analyst wants to publish (misp_publish_event) or keep as draft`
2267
+ }
2268
+ }
2269
+ ]
2270
+ };
2271
+ }
2272
+ );
2273
+ server2.prompt(
2274
+ "threat-report",
2275
+ "Generate a threat intelligence report from MISP data by aggregating events, extracting IOC patterns, and summarizing the threat landscape",
2276
+ {
2277
+ eventId: z13.string().optional().describe("Specific event ID to report on"),
2278
+ tag: z13.string().optional().describe("Filter by tag (e.g., mitre-attack:T1059, tlp:amber)"),
2279
+ dateRange: z13.string().optional().describe("Date range or relative time (e.g., '7d', '30d', '2024-01-01 to 2024-01-31')")
2280
+ },
2281
+ ({ eventId, tag, dateRange }) => {
2282
+ let scopeInstructions;
2283
+ if (eventId) {
2284
+ scopeInstructions = `Focus on event ID ${eventId}. Use misp_get_event to get full details, then misp_get_related_events for context.`;
2285
+ } else if (tag) {
2286
+ scopeInstructions = `Focus on events tagged with "${tag}". Use misp_search_by_tag to find matching events.`;
2287
+ } else if (dateRange) {
2288
+ const isRelative = /^\d+[dmhwy]$/.test(dateRange);
2289
+ if (isRelative) {
2290
+ scopeInstructions = `Focus on events from the last ${dateRange}. Use misp_search_events with last="${dateRange}".`;
2291
+ } else {
2292
+ scopeInstructions = `Focus on events in the date range: ${dateRange}. Use misp_search_events with appropriate dateFrom/dateTo.`;
2293
+ }
2294
+ } else {
2295
+ scopeInstructions = `Generate a report on recent threat activity. Use misp_search_events with last="7d" to get the latest events.`;
2296
+ }
2297
+ return {
2298
+ messages: [
2299
+ {
2300
+ role: "user",
2301
+ content: {
2302
+ type: "text",
2303
+ text: `Generate a threat intelligence report from MISP data.
2304
+
2305
+ ${scopeInstructions}
2306
+
2307
+ Report structure:
2308
+ 1. **Executive Summary**: Brief overview of the threat landscape for the specified scope
2309
+ 2. **Key Events**: List the most significant events with threat levels and descriptions
2310
+ 3. **IOC Summary**:
2311
+ - Use misp_search_attributes to aggregate IOC types and counts
2312
+ - List the most significant indicators by type (IPs, domains, hashes, URLs)
2313
+ 4. **MITRE ATT&CK Coverage**: List any ATT&CK techniques observed across the events
2314
+ 5. **Correlations**: Use misp_correlate on high-value IOCs to discover cross-event links
2315
+ 6. **Recommendations**:
2316
+ - Immediate blocking actions (IPs, domains to block)
2317
+ - Detection rules needed
2318
+ - Areas requiring further investigation
2319
+
2320
+ Format the report in clear markdown with headers and tables where appropriate.`
2321
+ }
2322
+ }
2323
+ ]
2324
+ };
2325
+ }
2326
+ );
2327
+ }
2328
+
2329
+ // src/index.ts
2330
+ var config = getConfig();
2331
+ var client = new MispClient(config);
2332
+ var server = new McpServer({
2333
+ name: "misp-mcp",
2334
+ version: "1.1.0",
2335
+ description: "MCP server for MISP threat intelligence platform - IOC lookups, event management, correlation discovery, and intelligence enrichment"
2336
+ });
2337
+ if (!config.verifySsl) {
2338
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
2339
+ }
2340
+ registerEventTools(server, client);
2341
+ registerAttributeTools(server, client);
2342
+ registerCorrelationTools(server, client);
2343
+ registerTagTools(server, client);
2344
+ registerExportTools(server, client);
2345
+ registerSightingTools(server, client);
2346
+ registerWarninglistTools(server, client);
2347
+ registerObjectTools(server, client);
2348
+ registerGalaxyTools(server, client);
2349
+ registerFeedTools(server, client);
2350
+ registerOrganisationTools(server, client);
2351
+ registerServerTools(server, client);
2352
+ registerResources(server, client);
2353
+ registerPrompts(server);
2354
+ var transport = new StdioServerTransport();
2355
+ server.connect(transport).catch((err) => {
2356
+ console.error("Failed to start MISP MCP server:", err);
2357
+ process.exit(1);
2358
+ });
2359
+ //# sourceMappingURL=index.js.map