UNPKG

@channel.io/be-user-chat-mcp

Version:

Backend UserChat Model Context Protocol server for Channel.io

64 lines 3.93 kB
import { z } from "zod"; import { getChangeLogsByEntity } from "../repositories/change-log.repository.js"; import { getWorkflow, getWorkflowRevisions, getWorkflowSectionPaths, } from "../repositories/workflow.repository.js"; import { searchSentryEvents, searchSentryLogs, } from "../services/sentry.service.js"; import { registerMcpTool, formatResult } from "../utils/helper.util.js"; const GetWorkflowAndRevisionsDataInputSchema = z.object({ workflow_id: z.string().min(1, "workflow_id is required"), }); const GetUserChatWorkflowSectionPathsDataInputSchema = z.object({ user_chat_id: z.string().min(1, "user_chat_id is required"), }); const GetWorkflowChangeLogsDataInputSchema = z.object({ workflow_id: z.string().min(1, "workflow_id is required"), since: z.number().optional(), }); const GetWorkflowSentryIssuesInputSchema = z.object({ workflow_id: z.string().min(1, "workflow_id is required"), period: z.enum(["24h", "14d", "30d", "90d"]).optional(), }); export function registerWorkflowTool(server, getContext) { registerMcpTool(server, "get_workflow_and_revisions_data", GetWorkflowAndRevisionsDataInputSchema, async (input, context) => { const { workflow_id } = input; const [workflowResult, revisionsResult] = await Promise.allSettled([ getWorkflow(workflow_id, context), getWorkflowRevisions(workflow_id, context), ]); return { workflow: formatResult(workflowResult, `Workflow not found for ID: ${workflow_id}`, `Error fetching Workflow for ID: ${workflow_id}`), revisions: formatResult(revisionsResult, `No revisions found for workflow ID: ${workflow_id}`, `Error fetching revisions for workflow ID: ${workflow_id}`), }; }, getContext); registerMcpTool(server, "get_workflow_section_path_data", GetUserChatWorkflowSectionPathsDataInputSchema, async (input, context) => { const { user_chat_id } = input; const [sectionPathsResult] = await Promise.allSettled([ getWorkflowSectionPaths(user_chat_id, context), ]); return { sectionPaths: formatResult(sectionPathsResult, `No section paths found for user_chat_id: ${user_chat_id}`, `Error fetching section paths for user_chat_id: ${user_chat_id}`), }; }, getContext); registerMcpTool(server, "get_workflow_change_logs_data", GetWorkflowChangeLogsDataInputSchema, async (input, context) => { const { workflow_id, since } = input; const [changeLogsResult] = await Promise.allSettled([ getChangeLogsByEntity("workflow", workflow_id, since, context), ]); return { changeLogs: formatResult(changeLogsResult, `No change logs found for workflow ID: ${workflow_id}`, `Error fetching change logs for workflow ID: ${workflow_id}`), }; }, getContext); registerMcpTool(server, "get_workflow_sentry_issues", GetWorkflowSentryIssuesInputSchema, async (input, context) => { const { workflow_id, period } = input; const projectSlug = "ch-dropwizard"; const query = `${workflow_id}`; const [sentryIssuesResult, sentryEventsResult] = await Promise.allSettled([ searchSentryLogs(projectSlug, query, period, 50, undefined, context), searchSentryEvents(projectSlug, query, 50, undefined, context), ]); return { sentryIssues: formatResult(sentryIssuesResult, `Sentry issues not found for workflow_id: ${workflow_id} in project ${projectSlug}`, `Error fetching Sentry issues for workflow_id: ${workflow_id} in project ${projectSlug}`), sentryEvents: formatResult(sentryEventsResult, `Sentry events not found for workflow_id: ${workflow_id} in project ${projectSlug}`, `Error fetching Sentry events for workflow_id: ${workflow_id} in project ${projectSlug}`), }; }, getContext); } //# sourceMappingURL=workflow.tool.js.map