@maelitop/mention-mcp-server 1.4.1 → 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.
@@ -1,94 +1,69 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
- import { logError, logInfo } from "../logger.js";
1
+ import { logInfo } from "../logger.js";
3
2
  import { FetchAlertStatsArgsSchema } from "../types.js";
4
- function createFetchAlertStatsHandler(apiClient) {
5
- return {
6
- async handle(args) {
7
- try {
8
- const validated = FetchAlertStatsArgsSchema.parse(args);
9
- const accountId = await apiClient.getAccountId();
10
- // Build query parameters
11
- const searchParams = new URLSearchParams();
12
- // Handle the required alerts array
13
- for (const alertId of validated.alerts) {
14
- searchParams.append("alerts[]", alertId);
15
- }
16
- searchParams.append("from", validated.from);
17
- searchParams.append("to", validated.to);
18
- searchParams.append("interval", validated.interval);
19
- // Handle optional parameters
20
- const optionalParams = {
21
- timezone: validated.timezone,
22
- favorite: validated.favorite,
23
- week_day_stats: validated.week_day_stats,
24
- week_day_by_hour_stats: validated.week_day_by_hour_stats,
25
- influencers: validated.influencers,
26
- reach_per_interval_stats: validated.reach_per_interval_stats,
27
- "author_influence.score": validated["author_influence.score"],
28
- };
29
- for (const [key, value] of Object.entries(optionalParams)) {
30
- if (value !== undefined && value !== null) {
31
- searchParams.append(key, String(value));
32
- }
33
- }
34
- // Handle array parameters
35
- const arrayParams = {
36
- "tones[]": validated.tones,
37
- "languages[]": validated.languages,
38
- "sources[]": validated.sources,
39
- "countries[]": validated.countries,
40
- "tags[]": validated.tags,
41
- };
42
- for (const [key, values] of Object.entries(arrayParams)) {
43
- if (values && Array.isArray(values)) {
44
- for (const value of values) {
45
- searchParams.append(key, String(value));
46
- }
47
- }
48
- }
49
- // Handle special country_stats parameter
50
- if (validated.country_stats !== undefined) {
51
- if (typeof validated.country_stats === "boolean") {
52
- searchParams.append("country_stats", validated.country_stats ? "10" : "0");
53
- }
54
- else {
55
- searchParams.append("country_stats", String(validated.country_stats));
56
- }
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));
57
43
  }
58
- const queryString = searchParams.toString();
59
- const endpoint = `/accounts/${accountId}/stats${queryString ? `?${queryString}` : ""}`;
60
- const data = await apiClient.makeRequest(endpoint);
61
- logInfo("Alert statistics fetched successfully", {
62
- accountId,
63
- alertIds: validated.alerts,
64
- endpoint,
65
- from: validated.from,
66
- to: validated.to,
67
- partial: data?.partial || false,
68
- });
69
- return {
70
- content: [
71
- {
72
- type: "text",
73
- text: JSON.stringify(data, null, 2),
74
- },
75
- ],
76
- };
77
44
  }
78
- catch (error) {
79
- logError("Failed to fetch alert statistics", error);
80
- throw error;
45
+ }
46
+ if (args.country_stats !== undefined) {
47
+ if (typeof args.country_stats === "boolean") {
48
+ searchParams.append("country_stats", args.country_stats ? "10" : "0");
81
49
  }
82
- },
83
- };
84
- }
85
- export const fetchAlertStatsTool = {
86
- getDefinition() {
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
+ });
87
65
  return {
88
- name: "fetch_alert_stats",
89
- 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.",
90
- inputSchema: zodToJsonSchema(FetchAlertStatsArgsSchema),
66
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
91
67
  };
92
- },
93
- createHandler: createFetchAlertStatsHandler,
94
- };
68
+ });
69
+ }
@@ -1,60 +1,39 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { apiPath } from "../api-client.js";
3
- import { logError, logInfo } from "../logger.js";
2
+ import { logInfo } from "../logger.js";
4
3
  import { FetchMentionsArgsSchema } from "../types.js";
5
- function createFetchMentionsHandler(apiClient) {
6
- return {
7
- async handle(args) {
8
- try {
9
- const validated = FetchMentionsArgsSchema.parse(args);
10
- const accountId = await apiClient.getAccountId();
11
- const { alert_id, ...queryParams } = validated;
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));
18
- }
19
- }
20
- else {
21
- searchParams.append(key, String(value));
22
- }
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));
23
18
  }
24
19
  }
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
- });
35
- return {
36
- content: [
37
- {
38
- type: "text",
39
- text: JSON.stringify(data, null, 2),
40
- },
41
- ],
42
- };
43
- }
44
- catch (error) {
45
- logError("Failed to fetch mentions", error);
46
- throw error;
20
+ else {
21
+ searchParams.append(key, String(value));
22
+ }
47
23
  }
48
- },
49
- };
50
- }
51
- export const fetchMentionsTool = {
52
- getDefinition() {
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
+ });
53
35
  return {
54
- name: "fetch_mentions",
55
- description: "Retrieve mentions associated with a specific alert. Supports various filters like source, folder, tone, countries, and advanced search queries.",
56
- inputSchema: zodToJsonSchema(FetchMentionsArgsSchema),
36
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
57
37
  };
58
- },
59
- createHandler: createFetchMentionsHandler,
60
- };
38
+ });
39
+ }
@@ -1,45 +1,22 @@
1
- import { logError, logInfo } from "../logger.js";
2
- function createGetAccountInfoHandler(apiClient) {
3
- return {
4
- async handle() {
5
- try {
6
- const data = await apiClient.getAccountInfo();
7
- const filteredResponse = {
8
- accountId: data.account.id,
9
- canCreateAdvancedAlert: data.account.subscription.advanced_query_access,
10
- groups: data.account.groups?.map((group) => ({
11
- id: group.id,
12
- name: group.name,
13
- })) || [],
14
- };
15
- logInfo("Account info retrieved", { accountId: data.account.id });
16
- return {
17
- content: [
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
- name: "get_account_info",
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
- createHandler: createGetAccountInfoHandler,
45
- };
21
+ });
22
+ }
@@ -1,38 +1,18 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  import { apiPath } from "../api-client.js";
3
- import { logError, logInfo } from "../logger.js";
2
+ import { logInfo } from "../logger.js";
4
3
  import { GetAlertArgsSchema } from "../types.js";
5
- function createGetAlertHandler(apiClient) {
6
- return {
7
- async handle(args) {
8
- try {
9
- const { alert_id } = GetAlertArgsSchema.parse(args);
10
- const accountId = await apiClient.getAccountId();
11
- const data = await apiClient.makeRequest(apiPath `/accounts/${accountId}/alerts/${alert_id}`);
12
- logInfo("Alert retrieved", { accountId, alertId: alert_id });
13
- return {
14
- content: [
15
- {
16
- type: "text",
17
- text: JSON.stringify(data, null, 2),
18
- },
19
- ],
20
- };
21
- }
22
- catch (error) {
23
- logError("Failed to get alert", error);
24
- throw error;
25
- }
26
- },
27
- };
28
- }
29
- export const getAlertTool = {
30
- 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 });
31
14
  return {
32
- name: "get_alert",
33
- description: "Get detailed information about a specific alert by its ID.",
34
- inputSchema: zodToJsonSchema(GetAlertArgsSchema),
15
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
35
16
  };
36
- },
37
- createHandler: createGetAlertHandler,
38
- };
17
+ });
18
+ }
@@ -1,46 +1,23 @@
1
- import { logError, logInfo } from "../logger.js";
1
+ import { logInfo } from "../logger.js";
2
2
  import { AppDataResponseSchema } from "../types.js";
3
- function createGetAppDataHandler(apiClient) {
4
- return {
5
- async handle() {
6
- try {
7
- const rawData = await apiClient.makeRequest("/app/data");
8
- const data = AppDataResponseSchema.parse(rawData);
9
- const filteredResponse = {
10
- languages: Object.keys(data.alert_languages || {}),
11
- countries: Object.keys(data.alert_countries || {}),
12
- sources: Object.entries(data.alert_sources || {})
13
- .filter(([_, source]) => !source.hidden)
14
- .map(([code]) => code),
15
- };
16
- logInfo("App data retrieved");
17
- return {
18
- content: [
19
- {
20
- type: "text",
21
- text: JSON.stringify(filteredResponse, null, 2),
22
- },
23
- ],
24
- };
25
- }
26
- catch (error) {
27
- logError("Failed to get app data", error);
28
- throw error;
29
- }
30
- },
31
- };
32
- }
33
- export const getAppDataTool = {
34
- getDefinition() {
3
+ export function registerGetAppDataTool(server, apiClient) {
4
+ server.registerTool("get_app_data", {
5
+ title: "Get Languages, Countries and Sources",
6
+ description: "Get application configuration data including available languages, countries, sources, colors, and other metadata needed for creating alerts.",
7
+ annotations: { readOnlyHint: true, openWorldHint: true },
8
+ }, async () => {
9
+ const rawData = await apiClient.makeRequest("/app/data");
10
+ const data = AppDataResponseSchema.parse(rawData);
11
+ const filteredResponse = {
12
+ languages: Object.keys(data.alert_languages || {}),
13
+ countries: Object.keys(data.alert_countries || {}),
14
+ sources: Object.entries(data.alert_sources || {})
15
+ .filter(([_, source]) => !source.hidden)
16
+ .map(([code]) => code),
17
+ };
18
+ logInfo("App data retrieved");
35
19
  return {
36
- name: "get_app_data",
37
- description: "Get application configuration data including available languages, countries, sources, colors, and other metadata needed for creating alerts.",
38
- inputSchema: {
39
- type: "object",
40
- properties: {},
41
- required: [],
42
- },
20
+ content: [{ type: "text", text: JSON.stringify(filteredResponse, null, 2) }],
43
21
  };
44
- },
45
- createHandler: createGetAppDataHandler,
46
- };
22
+ });
23
+ }
@@ -1,57 +1,26 @@
1
- import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
2
- import { logError, logInfo } from "../logger.js";
3
- import { createAdvancedAlertTool } from "./create_advanced_alert.js";
4
- import { createBasicAlertTool } from "./create_basic_alert.js";
5
- import { fetchAlertStatsTool } from "./fetch_alert_stats.js";
6
- import { fetchMentionsTool } from "./fetch_mentions.js";
7
- import { getAccountInfoTool } from "./get_account_info.js";
8
- import { getAlertTool } from "./get_alert.js";
9
- import { getAppDataTool } from "./get_app_data.js";
10
- import { listAlertsTool } from "./list_alerts.js";
11
- import { pauseAlertTool } from "./pause_alert.js";
12
- import { unpauseAlertTool } from "./unpause_alert.js";
13
- import { updateAlertTool } from "./update_alert.js";
14
- const tools = [
15
- getAccountInfoTool,
16
- getAppDataTool,
17
- listAlertsTool,
18
- getAlertTool,
19
- createBasicAlertTool,
20
- createAdvancedAlertTool,
21
- updateAlertTool,
22
- pauseAlertTool,
23
- unpauseAlertTool,
24
- fetchMentionsTool,
25
- fetchAlertStatsTool,
26
- ];
27
- export function getToolDefinitions() {
28
- return tools.map((tool) => tool.getDefinition());
29
- }
30
- export class ToolHandlers {
31
- apiClient;
32
- handlers;
33
- constructor(apiClient) {
34
- this.apiClient = apiClient;
35
- this.handlers = new Map();
36
- for (const tool of tools) {
37
- const handler = tool.createHandler(apiClient);
38
- this.handlers.set(tool.getDefinition().name, handler);
39
- }
40
- }
41
- async handleTool(name, args) {
42
- const handler = this.handlers.get(name);
43
- if (!handler) {
44
- throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
45
- }
46
- logInfo("Tool call started", { tool: name });
47
- try {
48
- const result = await handler.handle(args);
49
- logInfo("Tool call completed", { tool: name });
50
- return result;
51
- }
52
- catch (error) {
53
- logError("Tool call failed", error, { tool: name, args });
54
- throw error;
55
- }
1
+ import { registerCreateAdvancedAlertTool } from "./create_advanced_alert.js";
2
+ import { registerCreateBasicAlertTool } from "./create_basic_alert.js";
3
+ import { registerFetchAlertStatsTool } from "./fetch_alert_stats.js";
4
+ import { registerFetchMentionsTool } from "./fetch_mentions.js";
5
+ import { registerGetAccountInfoTool } from "./get_account_info.js";
6
+ import { registerGetAlertTool } from "./get_alert.js";
7
+ import { registerGetAppDataTool } from "./get_app_data.js";
8
+ import { registerListAlertsTool } from "./list_alerts.js";
9
+ import { registerPauseAlertTool } from "./pause_alert.js";
10
+ import { registerUnpauseAlertTool } from "./unpause_alert.js";
11
+ import { registerUpdateAlertTool } from "./update_alert.js";
12
+ export function registerTools(server, apiClient, readOnly) {
13
+ registerGetAccountInfoTool(server, apiClient);
14
+ registerGetAppDataTool(server, apiClient);
15
+ registerListAlertsTool(server, apiClient);
16
+ registerGetAlertTool(server, apiClient);
17
+ if (!readOnly) {
18
+ registerCreateBasicAlertTool(server, apiClient);
19
+ registerCreateAdvancedAlertTool(server, apiClient);
20
+ registerUpdateAlertTool(server, apiClient);
21
+ registerPauseAlertTool(server, apiClient);
22
+ registerUnpauseAlertTool(server, apiClient);
56
23
  }
24
+ registerFetchMentionsTool(server, apiClient);
25
+ registerFetchAlertStatsTool(server, apiClient);
57
26
  }
@@ -1,43 +1,23 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
- import { logError, logInfo } from "../logger.js";
1
+ import { logInfo } from "../logger.js";
3
2
  import { ListAlertsArgsSchema } from "../types.js";
4
- function createListAlertsHandler(apiClient) {
5
- return {
6
- async handle(args) {
7
- try {
8
- const { limit, cursor } = ListAlertsArgsSchema.parse(args);
9
- const accountId = await apiClient.getAccountId();
10
- const queryParams = new URLSearchParams();
11
- if (limit)
12
- queryParams.append("limit", limit.toString());
13
- if (cursor)
14
- queryParams.append("cursor", cursor);
15
- const endpoint = `/accounts/${accountId}/alerts${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
16
- const data = await apiClient.makeRequest(endpoint);
17
- logInfo("Alerts listed", { accountId, limit, cursor });
18
- return {
19
- content: [
20
- {
21
- type: "text",
22
- text: JSON.stringify(data, null, 2),
23
- },
24
- ],
25
- };
26
- }
27
- catch (error) {
28
- logError("Failed to list alerts", error);
29
- throw error;
30
- }
31
- },
32
- };
33
- }
34
- export const listAlertsTool = {
35
- getDefinition() {
3
+ export function registerListAlertsTool(server, apiClient) {
4
+ server.registerTool("list_alerts", {
5
+ title: "List Alerts",
6
+ description: "List all monitoring alerts for the current account with pagination support.",
7
+ inputSchema: ListAlertsArgsSchema.shape,
8
+ annotations: { readOnlyHint: true, openWorldHint: true },
9
+ }, async ({ limit, cursor }) => {
10
+ const accountId = await apiClient.getAccountId();
11
+ const queryParams = new URLSearchParams();
12
+ if (limit)
13
+ queryParams.append("limit", limit.toString());
14
+ if (cursor)
15
+ queryParams.append("cursor", cursor);
16
+ const endpoint = `/accounts/${accountId}/alerts${queryParams.toString() ? `?${queryParams.toString()}` : ""}`;
17
+ const data = await apiClient.makeRequest(endpoint);
18
+ logInfo("Alerts listed", { accountId, limit, cursor });
36
19
  return {
37
- name: "list_alerts",
38
- description: "List all monitoring alerts for the current account with pagination support.",
39
- inputSchema: zodToJsonSchema(ListAlertsArgsSchema),
20
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
40
21
  };
41
- },
42
- createHandler: createListAlertsHandler,
43
- };
22
+ });
23
+ }