UNPKG

mcp-casual-interview

Version:

MCP server for casual interview preparation workflow management

83 lines 3.91 kB
import { toStructuredCallToolResult } from '../util.js'; import { formatProgressMessage, errorMessages } from './prompts.js'; // Domain layer imports import { ProgressCheckAggregate } from '../../../domain/command/progress-check/index.js'; import { ProgressViewQueries } from '../../../domain/read/progress-view/index.js'; import { WorkflowStateEffects, ErrorMapping } from '../../../effect/workflow-state/index.js'; /** * Maps domain WorkflowState to schema WorkflowStateType */ const mapWorkflowStateToSchemaType = (domainState) => { const mapping = { 'not_started': 'not_started', 'information_initially_registered': 'initial_info_registered', 'career_summary_created': 'career_summary_created', 'match_position_determined': 'match_position_determined', 'match_degree_prediagnosed': 'match_degree_diagnosed', 'attract_plan_determined': 'attract_plan_determined', 'completed': 'completed' }; return mapping[domainState]; }; /** * Maps domain progress response to MCP output schema */ const mapProgressResponseToOutput = (domainResponse, notionPageUrl) => { return { currentState: mapWorkflowStateToSchemaType(domainResponse.currentState), nextAction: domainResponse.nextAction.message, notion_page_url: notionPageUrl }; }; /** * Progress check handler using domain layer orchestration */ export const progressCheckHandler = async (args) => { // 1. Get current workflow state from effect layer const currentStateResult = await WorkflowStateEffects.getWorkflowState(); if (currentStateResult.isErr()) { const workflowError = ErrorMapping.mapStorageErrorToWorkflowError(currentStateResult.error); return toStructuredCallToolResult([errorMessages.storageError(workflowError.message)], { error: workflowError.message }, true); } const currentState = currentStateResult.value; // 2. Get notion page URL from effect layer const notionPageUrlResult = await WorkflowStateEffects.getNotionPageUrl(); if (notionPageUrlResult.isErr()) { const workflowError = ErrorMapping.mapStorageErrorToWorkflowError(notionPageUrlResult.error); return toStructuredCallToolResult([errorMessages.storageError(workflowError.message)], { error: workflowError.message }, true); } const notionPageUrl = notionPageUrlResult.value; // 3. Execute progress check command const progressCheckResult = ProgressCheckAggregate.checkProgress(currentState); if (progressCheckResult.isErr()) { return toStructuredCallToolResult([errorMessages.progressCheckError(progressCheckResult.error.message)], { error: progressCheckResult.error.message }, true); } // 4. Build read model view from progress check event const progressView = ProgressViewQueries.fromState(currentState); // 5. Map domain data to MCP output schema const outputData = mapProgressResponseToOutput(progressView, notionPageUrl); // 6. Format for human consumption const message = formatProgressMessage({ nextAction: outputData.nextAction, currentState: outputData.currentState }); return toStructuredCallToolResult([message], outputData, false); }; /** * Utility function to update workflow state via domain layer * Used by other MCP tools that need to advance workflow state */ export const updateWorkflowState = async (newState) => { const updateResult = await WorkflowStateEffects.setWorkflowState(newState); if (updateResult.isErr()) { console.error('Failed to update workflow state:', updateResult.error); } }; /** * Utility function to get current state via domain layer */ export const getCurrentWorkflowState = async () => { const stateResult = await WorkflowStateEffects.getWorkflowState(); return stateResult.isOk() ? stateResult.value : 'not_started'; }; //# sourceMappingURL=handler.js.map