UNPKG

deepsource-mcp-server

Version:
362 lines 12.2 kB
/** * Type adapters for converting MCP tool parameters to domain handler parameters * * These adapters handle the conversion between primitive types from tool schemas * and branded types expected by domain handlers. */ import { asProjectKey, asGraphQLNodeId, asRunId, asCommitOid, asAnalyzerShortcode, } from '../types/branded.js'; /** * Adapts quality metrics parameters from tool schema to handler interface */ export function adaptQualityMetricsParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string }; const shortcodeIn = typedParams.shortcodeIn; if (shortcodeIn !== undefined) { result.shortcodeIn = shortcodeIn; } return result; } /** * Adapts update metric threshold parameters from tool schema to handler interface */ export function adaptUpdateMetricThresholdParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string repositoryId: typedParams.repositoryId, // Handler still expects string metricShortcode: typedParams.metricShortcode, metricKey: typedParams.metricKey, }; const thresholdValue = typedParams.thresholdValue; if (thresholdValue !== undefined) { result.thresholdValue = thresholdValue; } return result; } /** * Adapts update metric setting parameters from tool schema to handler interface */ export function adaptUpdateMetricSettingParams(params) { const typedParams = params; return { projectKey: typedParams.projectKey, // Handler still expects string repositoryId: typedParams.repositoryId, // Handler still expects string metricShortcode: typedParams.metricShortcode, isReported: typedParams.isReported, isThresholdEnforced: typedParams.isThresholdEnforced, }; } /** * Adapts compliance report parameters from tool schema to handler interface */ export function adaptComplianceReportParams(params) { const typedParams = params; return { projectKey: typedParams.projectKey, // Handler still expects string reportType: typedParams.reportType, }; } /** * Adapts project issues parameters from tool schema to handler interface */ export function adaptProjectIssuesParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string }; const path = typedParams.path; if (path !== undefined) result.path = path; const analyzerIn = typedParams.analyzerIn; if (analyzerIn !== undefined) result.analyzerIn = analyzerIn; const tags = typedParams.tags; if (tags !== undefined) result.tags = tags; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts dependency vulnerabilities parameters from tool schema to handler interface */ export function adaptDependencyVulnerabilitiesParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string }; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts project runs parameters from tool schema to handler interface */ export function adaptProjectRunsParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string }; const analyzerIn = typedParams.analyzerIn; if (analyzerIn !== undefined) result.analyzerIn = analyzerIn; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts run parameters from tool schema to handler interface */ export function adaptRunParams(params) { const typedParams = params; return { projectKey: typedParams.projectKey, // Handler still expects string runIdentifier: typedParams.runIdentifier, // Handler still expects string isCommitOid: typedParams.isCommitOid || false, }; } /** * Adapts recent run issues parameters from tool schema to handler interface */ export function adaptRecentRunIssuesParams(params) { const typedParams = params; const result = { projectKey: typedParams.projectKey, // Handler still expects string branchName: typedParams.branchName, }; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts parameters for domain-based handlers */ export function adaptToDomainQualityMetricsParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), }; const shortcodeIn = typedParams.shortcodeIn; if (shortcodeIn !== undefined) { result.shortcodeIn = shortcodeIn; } return result; } /** * Adapts raw parameters to domain update metric threshold parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for updating metric thresholds */ export function adaptToDomainUpdateMetricThresholdParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), repositoryId: asGraphQLNodeId(typedParams.repositoryId), metricShortcode: typedParams.metricShortcode, metricKey: typedParams.metricKey, }; const thresholdValue = typedParams.thresholdValue; if (thresholdValue !== undefined) { result.thresholdValue = thresholdValue; } return result; } /** * Adapts raw parameters to domain update metric setting parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for updating metric settings */ export function adaptToDomainUpdateMetricSettingParams(params) { const typedParams = params; return { projectKey: asProjectKey(typedParams.projectKey), repositoryId: asGraphQLNodeId(typedParams.repositoryId), metricShortcode: typedParams.metricShortcode, isReported: typedParams.isReported, isThresholdEnforced: typedParams.isThresholdEnforced, }; } /** * Adapts raw parameters to domain compliance report parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for compliance reports */ export function adaptToDomainComplianceReportParams(params) { const typedParams = params; return { projectKey: asProjectKey(typedParams.projectKey), reportType: typedParams.reportType, }; } /** * Adapts raw parameters to domain project issues parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for project issues */ export function adaptToDomainProjectIssuesParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), }; const path = typedParams.path; if (path !== undefined) result.path = path; const analyzerIn = typedParams.analyzerIn?.map((a) => asAnalyzerShortcode(a)); if (analyzerIn !== undefined) result.analyzerIn = analyzerIn; const tags = typedParams.tags; if (tags !== undefined) result.tags = tags; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts raw parameters to domain dependency vulnerabilities parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for dependency vulnerabilities */ export function adaptToDomainDependencyVulnerabilitiesParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), }; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts raw parameters to domain project runs parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for project runs */ export function adaptToDomainProjectRunsParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), }; const analyzerIn = typedParams.analyzerIn?.map((a) => asAnalyzerShortcode(a)); if (analyzerIn !== undefined) result.analyzerIn = analyzerIn; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } /** * Adapts raw parameters to domain run parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for a specific run */ export function adaptToDomainRunParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), runIdentifier: typedParams.isCommitOid ? asCommitOid(typedParams.runIdentifier) : asRunId(typedParams.runIdentifier), }; const isCommitOid = typedParams.isCommitOid; if (isCommitOid !== undefined) { result.isCommitOid = isCommitOid; } return result; } /** * Adapts raw parameters to domain recent run issues parameters * @param params - Raw parameters from the MCP request * @returns Typed domain parameters for recent run issues */ export function adaptToDomainRecentRunIssuesParams(params) { const typedParams = params; const result = { projectKey: asProjectKey(typedParams.projectKey), branchName: typedParams.branchName, }; const first = typedParams.first; if (first !== undefined) result.first = first; const last = typedParams.last; if (last !== undefined) result.last = last; const after = typedParams.after; if (after !== undefined) result.after = after; const before = typedParams.before; if (before !== undefined) result.before = before; return result; } //# sourceMappingURL=handler-adapters.js.map