{"record":{"id":"17d7038e08cc76a5","repo":"Tencent/WeKnora","slug":"mcp-service-not-found-17d703","errorCode":null,"errorMessage":"mcp service not found","messagePattern":"mcp service not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/mcp_tool_approval_service.go","lineNumber":30,"sourceCode":"\trepo    interfaces.MCPToolApprovalRepository\n\tmcpRepo interfaces.MCPServiceRepository\n}\n\n// NewMCPToolApprovalService constructs the MCP tool approval service.\nfunc NewMCPToolApprovalService(\n\trepo interfaces.MCPToolApprovalRepository,\n\tmcpRepo interfaces.MCPServiceRepository,\n) interfaces.MCPToolApprovalService {\n\treturn &mcpToolApprovalService{repo: repo, mcpRepo: mcpRepo}\n}\n\nfunc (s *mcpToolApprovalService) ListByService(ctx context.Context, tenantID uint64, serviceID string) ([]*types.MCPToolApproval, error) {\n\tsvc, err := s.mcpRepo.GetByID(ctx, tenantID, serviceID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif svc == nil {\n\t\treturn nil, fmt.Errorf(\"mcp service not found\")\n\t}\n\treturn s.repo.ListByService(ctx, tenantID, serviceID)\n}\n\nfunc (s *mcpToolApprovalService) SetRequireApproval(\n\tctx context.Context, tenantID uint64, serviceID, toolName string, require bool,\n) error {\n\tif toolName == \"\" {\n\t\treturn fmt.Errorf(\"tool_name is required\")\n\t}\n\tsvc, err := s.mcpRepo.GetByID(ctx, tenantID, serviceID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif svc == nil {\n\t\treturn fmt.Errorf(\"mcp service not found\")\n\t}\n\trow := &types.MCPToolApproval{","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/mcp_tool_approval_service.go#L12-L48","documentation":"ListByService looks up the parent MCP service by tenantID+serviceID before listing approvals; a nil row (not an error) from mcpRepo.GetByID yields this plain error. It signals the referenced MCP service record does not exist for the tenant.","triggerScenarios":"Calling ListByService with a serviceID that does not exist in the tenant's MCP services, or one belonging to another tenant.","commonSituations":"Stale client cache holding a deleted service ID; wrong tenant header in a multi-tenant deployment; UUID/ID typo in the request; service was soft-deleted but references remain.","solutions":["Verify the serviceID exists via the MCP service list/get API for the tenant","Confirm the request targets the correct tenant","Create the MCP service first if it was never provisioned","Return a typed not-found error at the HTTP layer (404) rather than surfacing this raw"],"exampleFix":"// before\napprovals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)\n// after\nif _, err := mcpSvc.Get(ctx, tenantID, serviceID); err != nil {\n\treturn nil, err // surface not-found before listing approvals\n}\napprovals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)","handlingStrategy":"validation","validationCode":"svc, err := mcpRepo.GetByID(ctx, tenantID, serviceID)\nif err != nil { return err }\nif svc == nil {\n\treturn fmt.Errorf(\"mcp service %q not found for tenant %d\", serviceID, tenantID)\n}\n// now safe\napprovals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)","typeGuard":null,"tryCatchPattern":"approvals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)\nif err != nil {\n\tif strings.Contains(err.Error(), \"mcp service not found\") {\n\t\treturn ErrServiceNotFound // map to 404 at the transport layer\n\t}\n\treturn err\n}","preventionTips":["Resolve serviceIDs from the tenant's own MCP service list, never from user input verbatim","Include tenant filters in every lookup to avoid cross-tenant ID reuse","Clean up approval references when deleting an MCP service","Return typed not-found sentinel errors for easy errors.Is matching"],"tags":["mcp","not-found","validation"],"backgroundTag":"resource-not-found","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}