{"record":{"id":"4c2451ebdee7b5b5","repo":"abhigyanpatwari/GitNexus","slug":"configured-mcp-repository-policy-must-be-validated","errorCode":null,"errorMessage":"Configured MCP repository policy must be validated before server creation.","messagePattern":"Configured MCP repository policy must be validated before server creation\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/mcp/server.ts","lineNumber":105,"sourceCode":"    case 'overview':\n      return `\\n\\n---\\n**Next:** To drill into an area, READ gitnexus://repo/${repoPath}/cluster/{name}. To see execution flows, READ gitnexus://repo/${repoPath}/processes.`;\n\n    default:\n      return '';\n  }\n}\n\n/**\n * Create a configured MCP Server with all handlers registered.\n * Transport-agnostic — caller connects the desired transport.\n */\nexport function createMCPServer(\n  backend: LocalBackend,\n  options: { repositoryPolicy?: McpRepositoryPolicy } = {},\n): Server {\n  const readOnly = resolveMcpReadOnlyMode();\n  if (!options.repositoryPolicy && mcpRepositoryPolicyConfigured()) {\n    throw new Error('Configured MCP repository policy must be validated before server creation.');\n  }\n  const repositoryPolicy = options.repositoryPolicy ?? McpRepositoryPolicy.unrestricted();\n  const scopedBackend = repositoryPolicy.scopeBackend(backend);\n  const server = new Server(\n    {\n      name: 'gitnexus',\n      version: packageVersion(),\n    },\n    {\n      capabilities: {\n        tools: {},\n        resources: {},\n        prompts: {},\n      },\n    },\n  );\n\n  // Handle list resources request","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/mcp/server.ts#L87-L123","documentation":"createMCPServer throws this when no validated McpRepositoryPolicy was passed in options while an unvalidated repository policy is present in configuration (mcpRepositoryPolicyConfigured() returns true). The library refuses to create an MCP server against a backend whose repository access policy was never parsed and validated by McpRepositoryPolicy, because an unvalidated policy could grant unintended repo access. It is a fail-closed safety check.","triggerScenarios":"Calling createMCPServer(backend) with no options.repositoryPolicy while config that defines an MCP repository policy exists (e.g. repositoryPolicy set in config file/env). Also passing an explicitly empty options object instead of a validated policy object.","commonSituations":"Server boot after adding a repository policy to config without wiring it through McpRepositoryPolicy.parse/validate before calling createMCPServer; upgrading versions where policy validation became mandatory; test harnesses constructing the server directly with only a backend.","solutions":["Parse the configured policy with McpRepositoryPolicy (e.g. McpRepositoryPolicy.fromConfig/parse) and pass the validated instance as options.repositoryPolicy.","If unrestricted access is truly intended, explicitly pass McpRepositoryPolicy.unrestricted() so intent is explicit.","Remove or disable the configured repository policy if the server should not be policy-scoped.","Check mcpRepositoryPolicyConfigured() before calling createMCPServer and branch to the validating code path."],"exampleFix":"// before\nconst server = createMCPServer(backend);\n// after\nconst policy = McpRepositoryPolicy.parse(config.mcpRepositoryPolicy);\nconst server = createMCPServer(backend, { repositoryPolicy: policy });","handlingStrategy":"validation","validationCode":"import { mcpRepositoryPolicyConfigured, McpRepositoryPolicy } from './mcp/policy.js';\nif (!options.repositoryPolicy && mcpRepositoryPolicyConfigured()) {\n  options.repositoryPolicy = McpRepositoryPolicy.parse(loadConfiguredPolicy());\n}\nconst server = createMCPServer(backend, options);","typeGuard":"function hasValidatedPolicy(o: { repositoryPolicy?: McpRepositoryPolicy }): o is { repositoryPolicy: McpRepositoryPolicy } {\n  return o.repositoryPolicy instanceof McpRepositoryPolicy;\n}","tryCatchPattern":"try {\n  const server = createMCPServer(backend, { repositoryPolicy: validatedPolicy });\n} catch (err) {\n  if ((err as Error).message.includes('repository policy must be validated')) {\n    throw new Error('App bug: pass McpRepositoryPolicy.parse(config) into createMCPServer', { cause: err });\n  }\n  throw err;\n}","preventionTips":["Always construct the policy via McpRepositoryPolicy before server creation — never call createMCPServer bare when a policy may be configured.","Centralize server creation in one factory that owns policy parsing.","Add a startup assertion that mcpRepositoryPolicyConfigured() === false unless a validated policy is in hand."],"tags":["mcp","security","configuration"],"backgroundTag":"missing-required-config","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-09-08T00:40:44.970Z","contentChangedAt":"2026-09-08T00:40:44.970Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}