@maelitop/mention-mcp-server 1.4.0 → 1.5.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/CHANGELOG.md +124 -0
- package/README.md +21 -19
- package/dist/api-client.js +79 -33
- package/dist/config.js +17 -4
- package/dist/index.js +6 -58
- package/dist/logger.js +20 -55
- package/dist/prompts/build-boolean-query.js +16 -34
- package/dist/prompts/index.js +4 -3
- package/dist/server.js +17 -0
- package/dist/tools/create_advanced_alert.js +33 -62
- package/dist/tools/create_basic_alert.js +36 -53
- package/dist/tools/fetch_alert_stats.js +63 -90
- package/dist/tools/fetch_mentions.js +33 -53
- package/dist/tools/get_account_info.js +20 -44
- package/dist/tools/get_alert.js +15 -35
- package/dist/tools/get_app_data.js +20 -44
- package/dist/tools/index.js +24 -56
- package/dist/tools/list_alerts.js +20 -41
- package/dist/tools/pause_alert.js +21 -36
- package/dist/tools/unpause_alert.js +21 -36
- package/dist/tools/update_alert.js +44 -55
- package/dist/types.js +20 -21
- package/package.json +11 -16
- package/dist/__tests__/api-client.test.d.ts +0 -2
- package/dist/__tests__/api-client.test.d.ts.map +0 -1
- package/dist/__tests__/api-client.test.js +0 -132
- package/dist/__tests__/api-client.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -2
- package/dist/__tests__/config.test.d.ts.map +0 -1
- package/dist/__tests__/config.test.js +0 -48
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/tools.test.d.ts +0 -2
- package/dist/__tests__/tools.test.d.ts.map +0 -1
- package/dist/__tests__/tools.test.js +0 -316
- package/dist/__tests__/tools.test.js.map +0 -1
- package/dist/__tests__/types.test.d.ts +0 -2
- package/dist/__tests__/types.test.d.ts.map +0 -1
- package/dist/__tests__/types.test.js +0 -179
- package/dist/__tests__/types.test.js.map +0 -1
- package/dist/api-client.d.ts +0 -14
- package/dist/api-client.d.ts.map +0 -1
- package/dist/api-client.js.map +0 -1
- package/dist/config.d.ts +0 -10
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -6
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/prompts/base.d.ts +0 -25
- package/dist/prompts/base.d.ts.map +0 -1
- package/dist/prompts/base.js +0 -2
- package/dist/prompts/base.js.map +0 -1
- package/dist/prompts/build-boolean-query.d.ts +0 -3
- package/dist/prompts/build-boolean-query.d.ts.map +0 -1
- package/dist/prompts/build-boolean-query.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -2
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js.map +0 -1
- package/dist/tools/base.d.ts +0 -19
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -2
- package/dist/tools/base.js.map +0 -1
- package/dist/tools/create_advanced_alert.d.ts +0 -3
- package/dist/tools/create_advanced_alert.d.ts.map +0 -1
- package/dist/tools/create_advanced_alert.js.map +0 -1
- package/dist/tools/create_basic_alert.d.ts +0 -3
- package/dist/tools/create_basic_alert.d.ts.map +0 -1
- package/dist/tools/create_basic_alert.js.map +0 -1
- package/dist/tools/fetch_alert_stats.d.ts +0 -3
- package/dist/tools/fetch_alert_stats.d.ts.map +0 -1
- package/dist/tools/fetch_alert_stats.js.map +0 -1
- package/dist/tools/fetch_mentions.d.ts +0 -3
- package/dist/tools/fetch_mentions.d.ts.map +0 -1
- package/dist/tools/fetch_mentions.js.map +0 -1
- package/dist/tools/get_account_info.d.ts +0 -3
- package/dist/tools/get_account_info.d.ts.map +0 -1
- package/dist/tools/get_account_info.js.map +0 -1
- package/dist/tools/get_alert.d.ts +0 -3
- package/dist/tools/get_alert.d.ts.map +0 -1
- package/dist/tools/get_alert.js.map +0 -1
- package/dist/tools/get_app_data.d.ts +0 -3
- package/dist/tools/get_app_data.d.ts.map +0 -1
- package/dist/tools/get_app_data.js.map +0 -1
- package/dist/tools/index.d.ts +0 -14
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/list_alerts.d.ts +0 -3
- package/dist/tools/list_alerts.d.ts.map +0 -1
- package/dist/tools/list_alerts.js.map +0 -1
- package/dist/tools/pause_alert.d.ts +0 -3
- package/dist/tools/pause_alert.d.ts.map +0 -1
- package/dist/tools/pause_alert.js.map +0 -1
- package/dist/tools/unpause_alert.d.ts +0 -3
- package/dist/tools/unpause_alert.d.ts.map +0 -1
- package/dist/tools/unpause_alert.js.map +0 -1
- package/dist/tools/update_alert.d.ts +0 -3
- package/dist/tools/update_alert.d.ts.map +0 -1
- package/dist/tools/update_alert.js.map +0 -1
- package/dist/types.d.ts +0 -448
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/server.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { registerPrompts } from "./prompts/index.js";
|
|
3
|
+
import { registerTools } from "./tools/index.js";
|
|
4
|
+
const alertAuthoringInstructions = [
|
|
5
|
+
"Call get_account_info first. Its groups give the group_id that create_basic_alert and create_advanced_alert require, and canCreateAdvancedAlert says whether the account can use create_advanced_alert; when it is false, use create_basic_alert.",
|
|
6
|
+
"get_app_data lists the language and source codes that alerts accept, and the country codes that update_alert accepts.",
|
|
7
|
+
];
|
|
8
|
+
const listAlertsInstruction = "list_alerts returns the alert IDs that the other alert, mention and stats tools take.";
|
|
9
|
+
export function createServer(apiClient, version, { readOnly }) {
|
|
10
|
+
const instructions = readOnly
|
|
11
|
+
? listAlertsInstruction
|
|
12
|
+
: [...alertAuthoringInstructions, listAlertsInstruction].join("\n");
|
|
13
|
+
const server = new McpServer({ name: "mention-mcp-server", version }, { instructions });
|
|
14
|
+
registerTools(server, apiClient, readOnly);
|
|
15
|
+
registerPrompts(server);
|
|
16
|
+
return server;
|
|
17
|
+
}
|
|
@@ -1,66 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logError, logInfo } from "../logger.js";
|
|
1
|
+
import { logInfo } from "../logger.js";
|
|
3
2
|
import { CreateAdvancedAlertArgsSchema, CreateAlertResponseSchema } from "../types.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type: "advanced",
|
|
15
|
-
query_string,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const rawData = await apiClient.makeRequest(`/accounts/${accountId}/alerts`, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: JSON.stringify(requestBody),
|
|
21
|
-
});
|
|
22
|
-
const data = CreateAlertResponseSchema.parse(rawData);
|
|
23
|
-
logInfo("Advanced alert created", {
|
|
24
|
-
accountId,
|
|
25
|
-
alertName: validated.name,
|
|
26
|
-
alertId: data.alert.id,
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
content: [
|
|
30
|
-
{
|
|
31
|
-
type: "text",
|
|
32
|
-
text: data.alert.id,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
// Check if this is a boolean query validation error
|
|
39
|
-
if (error instanceof Error && error.message.includes("boolean_errors")) {
|
|
40
|
-
logError("Boolean query validation failed", error);
|
|
41
|
-
throw new Error(`Boolean query validation failed. Common issues:
|
|
42
|
-
- Use url:domain.com instead of domain.com for websites
|
|
43
|
-
- Ensure proper boolean operators (AND, OR, NOT)
|
|
44
|
-
- Use quotes for phrases: "cold email"
|
|
45
|
-
- Max 1700 characters
|
|
46
|
-
- Example: (Lemlist OR url:lemlist.com OR "cold email") AND -spam
|
|
47
|
-
|
|
48
|
-
Original error: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
logError("Failed to create advanced alert", error);
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
3
|
+
export function registerCreateAdvancedAlertTool(server, apiClient) {
|
|
4
|
+
server.registerTool("create_advanced_alert", {
|
|
5
|
+
title: "Create Advanced Alert",
|
|
6
|
+
description: "Create a new advanced monitoring alert with boolean query syntax. Advanced alerts use complex query strings with boolean operators like AND, OR, NOT.",
|
|
7
|
+
inputSchema: CreateAdvancedAlertArgsSchema.shape,
|
|
8
|
+
annotations: {
|
|
9
|
+
readOnlyHint: false,
|
|
10
|
+
destructiveHint: false,
|
|
11
|
+
idempotentHint: false,
|
|
12
|
+
openWorldHint: true,
|
|
53
13
|
},
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
14
|
+
}, async ({ query_string, ...requestData }) => {
|
|
15
|
+
const accountId = await apiClient.getAccountId();
|
|
16
|
+
const requestBody = {
|
|
17
|
+
...requestData,
|
|
18
|
+
query: {
|
|
19
|
+
type: "advanced",
|
|
20
|
+
query_string,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const rawData = await apiClient.makeRequest(`/accounts/${accountId}/alerts`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
body: JSON.stringify(requestBody),
|
|
26
|
+
});
|
|
27
|
+
const data = CreateAlertResponseSchema.parse(rawData);
|
|
28
|
+
logInfo("Advanced alert created", {
|
|
29
|
+
accountId,
|
|
30
|
+
alertName: requestData.name,
|
|
31
|
+
alertId: data.alert.id,
|
|
32
|
+
});
|
|
58
33
|
return {
|
|
59
|
-
|
|
60
|
-
description: "Create a new advanced monitoring alert with boolean query syntax. Advanced alerts use complex query strings with boolean operators like AND, OR, NOT.",
|
|
61
|
-
inputSchema: zodToJsonSchema(CreateAdvancedAlertArgsSchema),
|
|
34
|
+
content: [{ type: "text", text: data.alert.id }],
|
|
62
35
|
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
//# sourceMappingURL=create_advanced_alert.js.map
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -1,57 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logError, logInfo } from "../logger.js";
|
|
1
|
+
import { logInfo } from "../logger.js";
|
|
3
2
|
import { CreateAlertResponseSchema, CreateBasicAlertArgsSchema } from "../types.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type: "basic",
|
|
15
|
-
included_keywords,
|
|
16
|
-
required_keywords,
|
|
17
|
-
excluded_keywords,
|
|
18
|
-
monitored_website,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
const rawData = await apiClient.makeRequest(`/accounts/${accountId}/alerts`, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
body: JSON.stringify(requestBody),
|
|
24
|
-
});
|
|
25
|
-
const data = CreateAlertResponseSchema.parse(rawData);
|
|
26
|
-
logInfo("Basic alert created", {
|
|
27
|
-
accountId,
|
|
28
|
-
alertName: validated.name,
|
|
29
|
-
alertId: data.alert.id,
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
content: [
|
|
33
|
-
{
|
|
34
|
-
type: "text",
|
|
35
|
-
text: data.alert.id,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
logError("Failed to create basic alert", error);
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
3
|
+
export function registerCreateBasicAlertTool(server, apiClient) {
|
|
4
|
+
server.registerTool("create_basic_alert", {
|
|
5
|
+
title: "Create Basic Alert",
|
|
6
|
+
description: "Create a new basic monitoring alert. Basic alerts use simple keyword matching with included_keywords, required_keywords, and excluded_keywords arrays.",
|
|
7
|
+
inputSchema: CreateBasicAlertArgsSchema.shape,
|
|
8
|
+
annotations: {
|
|
9
|
+
readOnlyHint: false,
|
|
10
|
+
destructiveHint: false,
|
|
11
|
+
idempotentHint: false,
|
|
12
|
+
openWorldHint: true,
|
|
44
13
|
},
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
14
|
+
}, async ({ included_keywords, required_keywords, excluded_keywords, monitored_website, ...requestData }) => {
|
|
15
|
+
const accountId = await apiClient.getAccountId();
|
|
16
|
+
const requestBody = {
|
|
17
|
+
...requestData,
|
|
18
|
+
query: {
|
|
19
|
+
type: "basic",
|
|
20
|
+
included_keywords,
|
|
21
|
+
required_keywords,
|
|
22
|
+
excluded_keywords,
|
|
23
|
+
monitored_website,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const rawData = await apiClient.makeRequest(`/accounts/${accountId}/alerts`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: JSON.stringify(requestBody),
|
|
29
|
+
});
|
|
30
|
+
const data = CreateAlertResponseSchema.parse(rawData);
|
|
31
|
+
logInfo("Basic alert created", {
|
|
32
|
+
accountId,
|
|
33
|
+
alertName: requestData.name,
|
|
34
|
+
alertId: data.alert.id,
|
|
35
|
+
});
|
|
49
36
|
return {
|
|
50
|
-
|
|
51
|
-
description: "Create a new basic monitoring alert. Basic alerts use simple keyword matching with included_keywords, required_keywords, and excluded_keywords arrays.",
|
|
52
|
-
inputSchema: zodToJsonSchema(CreateBasicAlertArgsSchema),
|
|
37
|
+
content: [{ type: "text", text: data.alert.id }],
|
|
53
38
|
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=create_basic_alert.js.map
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -1,96 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { logError, logInfo } from "../logger.js";
|
|
1
|
+
import { logInfo } from "../logger.js";
|
|
3
2
|
import { FetchAlertStatsArgsSchema } from "../types.js";
|
|
4
|
-
function
|
|
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
|
-
if (values && Array.isArray(values)) {
|
|
45
|
-
for (const value of values) {
|
|
46
|
-
searchParams.append(key, String(value));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Handle special country_stats parameter
|
|
51
|
-
if (validated.country_stats !== undefined) {
|
|
52
|
-
if (typeof validated.country_stats === "boolean") {
|
|
53
|
-
searchParams.append("country_stats", validated.country_stats ? "10" : "0");
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
searchParams.append("country_stats", String(validated.country_stats));
|
|
57
|
-
}
|
|
3
|
+
export function registerFetchAlertStatsTool(server, apiClient) {
|
|
4
|
+
server.registerTool("fetch_alert_stats", {
|
|
5
|
+
title: "Fetch Alert Stats",
|
|
6
|
+
description: "Retrieve comprehensive statistics for one or more alerts including mentions per interval, tones, influencers, geographical data, and reach metrics. Supports flexible date ranges, filtering, and aggregation options.",
|
|
7
|
+
inputSchema: FetchAlertStatsArgsSchema.shape,
|
|
8
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
9
|
+
}, async (args) => {
|
|
10
|
+
const accountId = await apiClient.getAccountId();
|
|
11
|
+
const searchParams = new URLSearchParams();
|
|
12
|
+
for (const alertId of args.alerts) {
|
|
13
|
+
searchParams.append("alerts[]", alertId);
|
|
14
|
+
}
|
|
15
|
+
searchParams.append("from", args.from);
|
|
16
|
+
searchParams.append("to", args.to);
|
|
17
|
+
searchParams.append("interval", args.interval);
|
|
18
|
+
const optionalParams = {
|
|
19
|
+
timezone: args.timezone,
|
|
20
|
+
favorite: args.favorite,
|
|
21
|
+
week_day_stats: args.week_day_stats,
|
|
22
|
+
week_day_by_hour_stats: args.week_day_by_hour_stats,
|
|
23
|
+
influencers: args.influencers,
|
|
24
|
+
reach_per_interval_stats: args.reach_per_interval_stats,
|
|
25
|
+
"author_influence.score": args["author_influence.score"],
|
|
26
|
+
};
|
|
27
|
+
for (const [key, value] of Object.entries(optionalParams)) {
|
|
28
|
+
if (value !== undefined && value !== null) {
|
|
29
|
+
searchParams.append(key, String(value));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const arrayParams = {
|
|
33
|
+
"tones[]": args.tones,
|
|
34
|
+
"languages[]": args.languages,
|
|
35
|
+
"sources[]": args.sources,
|
|
36
|
+
"countries[]": args.countries,
|
|
37
|
+
"tags[]": args.tags,
|
|
38
|
+
};
|
|
39
|
+
for (const [key, values] of Object.entries(arrayParams)) {
|
|
40
|
+
if (values && Array.isArray(values)) {
|
|
41
|
+
for (const value of values) {
|
|
42
|
+
searchParams.append(key, String(value));
|
|
58
43
|
}
|
|
59
|
-
const queryString = searchParams.toString();
|
|
60
|
-
const endpoint = `/accounts/${accountId}/stats${queryString ? `?${queryString}` : ""}`;
|
|
61
|
-
const data = await apiClient.makeRequest(endpoint);
|
|
62
|
-
logInfo("Alert statistics fetched successfully", {
|
|
63
|
-
accountId,
|
|
64
|
-
alertIds: validated.alerts,
|
|
65
|
-
endpoint,
|
|
66
|
-
from: validated.from,
|
|
67
|
-
to: validated.to,
|
|
68
|
-
partial: data?.partial || false,
|
|
69
|
-
});
|
|
70
|
-
return {
|
|
71
|
-
content: [
|
|
72
|
-
{
|
|
73
|
-
type: "text",
|
|
74
|
-
text: JSON.stringify(data, null, 2),
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
};
|
|
78
44
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
45
|
+
}
|
|
46
|
+
if (args.country_stats !== undefined) {
|
|
47
|
+
if (typeof args.country_stats === "boolean") {
|
|
48
|
+
searchParams.append("country_stats", args.country_stats ? "10" : "0");
|
|
82
49
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
50
|
+
else {
|
|
51
|
+
searchParams.append("country_stats", String(args.country_stats));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const queryString = searchParams.toString();
|
|
55
|
+
const endpoint = `/accounts/${accountId}/stats${queryString ? `?${queryString}` : ""}`;
|
|
56
|
+
const data = await apiClient.makeRequest(endpoint);
|
|
57
|
+
logInfo("Alert statistics fetched successfully", {
|
|
58
|
+
accountId,
|
|
59
|
+
alertIds: args.alerts,
|
|
60
|
+
endpoint,
|
|
61
|
+
from: args.from,
|
|
62
|
+
to: args.to,
|
|
63
|
+
partial: data?.partial || false,
|
|
64
|
+
});
|
|
88
65
|
return {
|
|
89
|
-
|
|
90
|
-
description: "Retrieve comprehensive statistics for one or more alerts including mentions per interval, tones, influencers, geographical data, and reach metrics. Supports flexible date ranges, filtering, and aggregation options.",
|
|
91
|
-
inputSchema: zodToJsonSchema(FetchAlertStatsArgsSchema),
|
|
66
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
92
67
|
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=fetch_alert_stats.js.map
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -1,59 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { apiPath } from "../api-client.js";
|
|
2
|
+
import { logInfo } from "../logger.js";
|
|
3
3
|
import { FetchMentionsArgsSchema } from "../types.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
searchParams.append(key, String(value));
|
|
21
|
-
}
|
|
4
|
+
export function registerFetchMentionsTool(server, apiClient) {
|
|
5
|
+
server.registerTool("fetch_mentions", {
|
|
6
|
+
title: "Fetch Mentions",
|
|
7
|
+
description: "Retrieve mentions associated with a specific alert. Supports various filters like source, folder, tone, countries, and advanced search queries.",
|
|
8
|
+
inputSchema: FetchMentionsArgsSchema.shape,
|
|
9
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
10
|
+
}, async ({ alert_id, ...queryParams }) => {
|
|
11
|
+
const accountId = await apiClient.getAccountId();
|
|
12
|
+
const searchParams = new URLSearchParams();
|
|
13
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
14
|
+
if (value !== undefined && value !== null) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
for (const item of value) {
|
|
17
|
+
searchParams.append(`${key}[]`, String(item));
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
logInfo("Mentions fetched successfully", {
|
|
28
|
-
accountId,
|
|
29
|
-
alertId: alert_id,
|
|
30
|
-
endpoint,
|
|
31
|
-
mentionCount: data?.mentions?.length || 0,
|
|
32
|
-
});
|
|
33
|
-
return {
|
|
34
|
-
content: [
|
|
35
|
-
{
|
|
36
|
-
type: "text",
|
|
37
|
-
text: JSON.stringify(data, null, 2),
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
logError("Failed to fetch mentions", error);
|
|
44
|
-
throw error;
|
|
20
|
+
else {
|
|
21
|
+
searchParams.append(key, String(value));
|
|
22
|
+
}
|
|
45
23
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
}
|
|
25
|
+
const queryString = searchParams.toString();
|
|
26
|
+
const path = apiPath `/accounts/${accountId}/alerts/${alert_id}/mentions`;
|
|
27
|
+
const endpoint = queryString ? `${path}?${queryString}` : path;
|
|
28
|
+
const data = await apiClient.makeRequest(endpoint);
|
|
29
|
+
logInfo("Mentions fetched successfully", {
|
|
30
|
+
accountId,
|
|
31
|
+
alertId: alert_id,
|
|
32
|
+
endpoint,
|
|
33
|
+
mentionCount: data?.mentions?.length || 0,
|
|
34
|
+
});
|
|
51
35
|
return {
|
|
52
|
-
|
|
53
|
-
description: "Retrieve mentions associated with a specific alert. Supports various filters like source, folder, tone, countries, languages, and advanced search queries.",
|
|
54
|
-
inputSchema: zodToJsonSchema(FetchMentionsArgsSchema),
|
|
36
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
55
37
|
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=fetch_mentions.js.map
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -1,46 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
type: "text",
|
|
20
|
-
text: JSON.stringify(filteredResponse, null, 2),
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
logError("Failed to get account info", error);
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export const getAccountInfoTool = {
|
|
33
|
-
getDefinition() {
|
|
1
|
+
import { logInfo } from "../logger.js";
|
|
2
|
+
export function registerGetAccountInfoTool(server, apiClient) {
|
|
3
|
+
server.registerTool("get_account_info", {
|
|
4
|
+
title: "Get Account Info",
|
|
5
|
+
description: "Get the current account's ID, its groups, and whether it can create advanced alerts (canCreateAdvancedAlert).",
|
|
6
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
7
|
+
}, async () => {
|
|
8
|
+
const data = await apiClient.getAccountInfo();
|
|
9
|
+
const filteredResponse = {
|
|
10
|
+
accountId: data.account.id,
|
|
11
|
+
canCreateAdvancedAlert: data.account.subscription.advanced_query_access,
|
|
12
|
+
groups: data.account.groups?.map((group) => ({
|
|
13
|
+
id: group.id,
|
|
14
|
+
name: group.name,
|
|
15
|
+
})) || [],
|
|
16
|
+
};
|
|
17
|
+
logInfo("Account info retrieved", { accountId: data.account.id });
|
|
34
18
|
return {
|
|
35
|
-
|
|
36
|
-
description: "Get current account information including subscription plan, account ID, and capabilities. This tool should be called first to understand account limitations and determine which alert creation tools are available.",
|
|
37
|
-
inputSchema: {
|
|
38
|
-
type: "object",
|
|
39
|
-
properties: {},
|
|
40
|
-
required: [],
|
|
41
|
-
},
|
|
19
|
+
content: [{ type: "text", text: JSON.stringify(filteredResponse, null, 2) }],
|
|
42
20
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=get_account_info.js.map
|
|
21
|
+
});
|
|
22
|
+
}
|
package/dist/tools/get_alert.js
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { apiPath } from "../api-client.js";
|
|
2
|
+
import { logInfo } from "../logger.js";
|
|
3
3
|
import { GetAlertArgsSchema } from "../types.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
type: "text",
|
|
16
|
-
text: JSON.stringify(data, null, 2),
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
logError("Failed to get alert", error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export const getAlertTool = {
|
|
29
|
-
getDefinition() {
|
|
4
|
+
export function registerGetAlertTool(server, apiClient) {
|
|
5
|
+
server.registerTool("get_alert", {
|
|
6
|
+
title: "Get Alert",
|
|
7
|
+
description: "Get detailed information about a specific alert by its ID.",
|
|
8
|
+
inputSchema: GetAlertArgsSchema.shape,
|
|
9
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
10
|
+
}, async ({ alert_id }) => {
|
|
11
|
+
const accountId = await apiClient.getAccountId();
|
|
12
|
+
const data = await apiClient.makeRequest(apiPath `/accounts/${accountId}/alerts/${alert_id}`);
|
|
13
|
+
logInfo("Alert retrieved", { accountId, alertId: alert_id });
|
|
30
14
|
return {
|
|
31
|
-
|
|
32
|
-
description: "Get detailed information about a specific alert by its ID.",
|
|
33
|
-
inputSchema: zodToJsonSchema(GetAlertArgsSchema),
|
|
15
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
34
16
|
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=get_alert.js.map
|
|
17
|
+
});
|
|
18
|
+
}
|